[pypy-commit] pypy default: some sanity checks about using nonsensical combinations of hints

cfbolz noreply at buildbot.pypy.org
Wed Mar 4 14:55:58 CET 2015


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r76239:ff7c259bbcc6
Date: 2015-03-04 14:55 +0100
http://bitbucket.org/pypy/pypy/changeset/ff7c259bbcc6/

Log:	some sanity checks about using nonsensical combinations of hints

diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -45,6 +45,8 @@
             else:
                 assert oldresult == result
             return result
+    if getattr(func, '_jit_unroll_safe_', False):
+        raise TypeError("it does not make sense for %s to be both elidable and unroll_safe" % func)
     func._elidable_function_ = True
     return func
 
@@ -83,6 +85,8 @@
     """ Make sure the JIT does not trace inside decorated function
     (it becomes a call instead)
     """
+    if getattr(func, '_jit_unroll_safe_', False):
+        raise TypeError("it does not make sense for %s to be both dont_look_inside and unroll_safe" % func)
     func._jit_look_inside_ = False
     return func
 
@@ -97,6 +101,10 @@
     """ JIT can safely unroll loops in this function and this will
     not lead to code explosion
     """
+    if getattr(func, '_elidable_function_', False):
+        raise TypeError("it does not make sense for %s to be both elidable and unroll_safe" % func)
+    if not getattr(func, '_jit_look_inside_', True):
+        raise TypeError("it does not make sense for %s to be both elidable and dont_look_inside" % func)
     func._jit_unroll_safe_ = True
     return func
 
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -1,9 +1,10 @@
-import py
+import py, pytest
 
 from rpython.conftest import option
 from rpython.annotator.model import UnionError
 from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote,
-    JitHintError, oopspec, isconstant, conditional_call)
+    JitHintError, oopspec, isconstant, conditional_call,
+    elidable, unroll_safe, dont_look_inside)
 from rpython.rlib.rarithmetic import r_uint
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.lltypesystem import lltype
@@ -91,6 +92,28 @@
     myjitdriver = JitDriver(greens=['n'], reds=[])
     py.test.raises(JitHintError, fn, 100)
 
+def test_invalid_hint_combinations_error():
+    with pytest.raises(TypeError):
+        @unroll_safe
+        @elidable
+        def f():
+            pass
+    with pytest.raises(TypeError):
+        @unroll_safe
+        @elidable
+        def f():
+            pass
+    with pytest.raises(TypeError):
+        @unroll_safe
+        @dont_look_inside
+        def f():
+            pass
+    with pytest.raises(TypeError):
+        @unroll_safe
+        @dont_look_inside
+        def f():
+            pass
+
 class TestJIT(BaseRtypingTest):
     def test_hint(self):
         def f():


More information about the pypy-commit mailing list