[pypy-svn] r35965 - in pypy/dist/pypy/translator/backendopt: . test
antocuni at codespeak.net
antocuni at codespeak.net
Sat Dec 23 11:34:21 CET 2006
Author: antocuni
Date: Sat Dec 23 11:34:19 2006
New Revision: 35965
Modified:
pypy/dist/pypy/translator/backendopt/inline.py
pypy/dist/pypy/translator/backendopt/test/test_inline.py
Log:
- generate keepalive only for lltypesystem
- do not longer skip a test that passes
- two new failing tests
Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/inline.py Sat Dec 23 11:34:19 2006
@@ -13,7 +13,7 @@
from pypy.rpython import rmodel
from pypy.tool.algo import sparsemat
from pypy.translator.backendopt.support import log, split_block_with_keepalive
-from pypy.translator.backendopt.support import generate_keepalive, find_backedges, find_loop_blocks
+from pypy.translator.backendopt.support import find_backedges, find_loop_blocks
from pypy.translator.backendopt.canraise import RaiseAnalyzer
BASE_INLINE_THRESHOLD = 32.4 # just enough to inline add__Int_Int()
@@ -223,7 +223,14 @@
if var not in self.varmap:
self.varmap[var] = copyvar(None, var)
return self.varmap[var]
-
+
+ def generate_keepalive(self, *args):
+ from pypy.translator.backendopt.support import generate_keepalive
+ if self.translator.rtyper.type_system.name == 'lltypesystem':
+ return generate_keepalive(*args)
+ else:
+ return []
+
def passon_vars(self, cache_key):
if cache_key in self._passon_vars:
return self._passon_vars[cache_key]
@@ -331,7 +338,7 @@
for exceptionlink in afterblock.exits[1:]:
if exc_match(vtable, exceptionlink.llexitcase):
passon_vars = self.passon_vars(link.prevblock)
- copiedblock.operations += generate_keepalive(passon_vars)
+ copiedblock.operations += self.generate_keepalive(passon_vars)
copiedlink.target = exceptionlink.target
linkargs = self.find_args_in_exceptional_case(
exceptionlink, link.prevblock, var_etype, var_evalue, afterblock, passon_vars)
@@ -379,7 +386,7 @@
del blocks[-1].exits[0].llexitcase
linkargs = copiedexceptblock.inputargs
copiedexceptblock.recloseblock(Link(linkargs, blocks[0]))
- copiedexceptblock.operations += generate_keepalive(linkargs)
+ copiedexceptblock.operations += self.generate_keepalive(linkargs)
def do_inline(self, block, index_operation):
Modified: pypy/dist/pypy/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_inline.py Sat Dec 23 11:34:19 2006
@@ -486,13 +486,12 @@
assert round(res, 5) == round(32.333333333, 5)
def test_indirect_call_with_exception(self):
- self._skip_oo('exception rewiring')
class Dummy:
pass
def x1():
return Dummy() # can raise MemoryError
def x2():
- return 2
+ return None
def x3(x):
if x:
f = x1
@@ -509,6 +508,25 @@
assert x4() == 1
py.test.raises(CannotInline, self.check_inline, x3, x4, [])
+
+class TestInlineLLType(LLRtypeMixin, BaseTestInline):
+
+ def test_correct_keepalive_placement(self):
+ def h(x):
+ if not x:
+ raise ValueError
+ return 1
+ def f(x):
+ s = "a %s" % (x, )
+ try:
+ h(len(s))
+ except ValueError:
+ pass
+ return -42
+ eval_func, t = self.check_auto_inlining(f, [int])
+ res = eval_func([42])
+ assert res == -42
+
def test_keepalive_hard_case(self):
from pypy.rpython.lltypesystem import lltype
Y = lltype.Struct('y', ('n', lltype.Signed))
@@ -529,25 +547,40 @@
res = eval_func([])
assert res == 5
- def test_correct_keepalive_placement(self):
- def h(x):
- if not x:
- raise ValueError
- return 1
- def f(x):
- s = "a %s" % (x, )
- try:
- h(len(s))
- except ValueError:
- pass
- return -42
- eval_func, t = self.check_auto_inlining(f, [int])
- res = eval_func([42])
- assert res == -42
+class TestInlineOOType(OORtypeMixin, BaseTestInline):
+ def test_invalid_iterator(self):
+ py.test.skip('Fixme!')
+ def f():
+ try:
+ d = {'a': 1, 'b': 2}
+ for key in d:
+ d[key] = 0
+ return True
+ except RuntimeError:
+ return False
+ eval_func, t = self.check_auto_inlining(f, [])
+ res = eval_func([])
+ assert res == False
-class TestInlineLLType(LLRtypeMixin, BaseTestInline):
- pass
+ def test_rtype_r_dict_exceptions(self):
+ py.test.skip('Fixme!')
+ from pypy.rlib.objectmodel import r_dict
+ def raising_hash(obj):
+ if obj.startswith("bla"):
+ raise TypeError
+ return 1
+ def eq(obj1, obj2):
+ return obj1 is obj2
+ def f():
+ d1 = r_dict(eq, raising_hash)
+ d1['xxx'] = 1
+ try:
+ x = d1["blabla"]
+ except Exception:
+ return 42
+ return x
-class TestInlineOOType(OORtypeMixin, BaseTestInline):
- pass
+ eval_func, t = self.check_auto_inlining(f, [])
+ res = eval_func([])
+ assert res == 42
More information about the pypy-svn
mailing list