[pypy-svn] r69968 - in pypy/trunk/pypy/rlib: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 8 10:09:09 CET 2009
Author: arigo
Date: Tue Dec 8 10:09:08 2009
New Revision: 69968
Modified:
pypy/trunk/pypy/rlib/jit.py
pypy/trunk/pypy/rlib/test/test_jit.py
Log:
Detect type errors in the arguments passed to
various jit_merge_point/can_enter_jit.
Modified: pypy/trunk/pypy/rlib/jit.py
==============================================================================
--- pypy/trunk/pypy/rlib/jit.py (original)
+++ pypy/trunk/pypy/rlib/jit.py Tue Dec 8 10:09:08 2009
@@ -237,6 +237,23 @@
"arguments: %s" % (self.instance,
expected))
+ try:
+ cache = self.bookkeeper._jit_annotation_cache[driver]
+ except AttributeError:
+ cache = {}
+ self.bookkeeper._jit_annotation_cache = {driver: cache}
+ except KeyError:
+ cache = {}
+ self.bookkeeper._jit_annotation_cache[driver] = cache
+ for key, s_value in kwds_s.items():
+ s_previous = cache.get(key, annmodel.s_ImpossibleValue)
+ s_value = annmodel.unionof(s_previous, s_value)
+ if annmodel.isdegenerated(s_value):
+ raise JitHintError("mixing incompatible types in argument %s"
+ " of jit_merge_point/can_enter_jit" %
+ key[2:])
+ cache[key] = s_value
+
if self.instance.__name__ == 'jit_merge_point':
self.annotate_hooks(**kwds_s)
Modified: pypy/trunk/pypy/rlib/test/test_jit.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_jit.py (original)
+++ pypy/trunk/pypy/rlib/test/test_jit.py Tue Dec 8 10:09:08 2009
@@ -1,5 +1,6 @@
import py
from pypy.rlib.jit import hint, we_are_jitted, JitDriver, purefunction_promote
+from pypy.rlib.jit import JitHintError
from pypy.translator.translator import TranslationContext, graphof
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rpython.lltypesystem import lltype
@@ -65,6 +66,28 @@
get_printable_location_args = getargs(get_printable_location)
assert can_inline_args == get_printable_location_args == [lltype.Float]
+ def test_annotate_argumenterror(self):
+ myjitdriver = JitDriver(greens=['m'], reds=['n'])
+ def fn(n):
+ while n > 0:
+ myjitdriver.can_enter_jit(m=42.5, n=n)
+ myjitdriver.jit_merge_point(n=n)
+ n -= 1
+ return n
+ py.test.raises(JitHintError, self.gengraph, fn, [int])
+
+ def test_annotate_typeerror(self):
+ myjitdriver = JitDriver(greens=['m'], reds=['n'])
+ class A(object): pass
+ class B(object): pass
+ def fn(n):
+ while n > 0:
+ myjitdriver.can_enter_jit(m=A(), n=n)
+ myjitdriver.jit_merge_point(m=B(), n=n)
+ n -= 1
+ return n
+ py.test.raises(JitHintError, self.gengraph, fn, [int])
+
class TestJITLLtype(BaseTestJIT, LLRtypeMixin):
pass
More information about the Pypy-commit
mailing list