Alex Gaynor committed 524483d

a) Renamed @unroll_if to @look_inside_iff at carl's request
b) Unroll Argument.unpack if one should.
c) Leave a comment about a small level mess with keyword argumengs and the decorator

  • Participants
  • Parent commits 4fd7b83
  • Branches unroll-if-alt

Comments (0)

Files changed (8)

File pypy/interpreter/

     ###  Manipulation  ###
+    @jit.look_inside_iff(lambda self: not self._dont_jit)
     def unpack(self): # slowish
         "Return a ([w1,w2...], {'kw':w3...}) pair."
         kwds_w = {}
     ###  Parsing for function calls  ###
+    # XXX: this should be @jit.look_inside_iff, but we need key word arguments,
+    # and it doesn't support them for now.
     def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=None,
         """Parse args and kwargs according to the signature of a code object,

File pypy/jit/metainterp/test/

 from pypy.jit.metainterp.warmstate import set_future_value
 from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
     loop_invariant, elidable, promote, jit_debug, assert_green,
-    AssertGreenFailed, unroll_safe, current_trace_length, unroll_if, isconstant)
+    AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff, isconstant)
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
         self.meta_interp(f, [10], repeat=3)
-    def test_unroll_if_const(self):
-        @unroll_if(lambda arg: isconstant(arg))
+    def test_look_inside_iff_const(self):
+        @look_inside_iff(lambda arg: isconstant(arg))
         def f(arg):
             s = 0
             while arg > 0:
             'int_gt': 1, 'int_sub': 1, 'strlen': 1, 'jump': 1,
-    def test_unroll_if_const_getarrayitem_gc_pure(self):
+    def test_look_inside_iff_const_getarrayitem_gc_pure(self):
         driver = JitDriver(greens=['unroll'], reds=['s', 'n'])
         class A(object):
             def __init__(self, x):
                 self.x = [x]
-        @unroll_if(lambda x: isconstant(x))
+        @look_inside_iff(lambda x: isconstant(x))
         def f(x):
             i = 0
             for c in x:

File pypy/objspace/std/

                 c = self.peekchr()
             return result
-        @jit.unroll_if(lambda self: jit.isconstant(self.fmt))
+        @jit.look_inside_iff(lambda self: jit.isconstant(self.fmt))
         def format(self):
             lgt = len(self.fmt) + 4 * len(self.values_w) + 10
             if do_unicode:

File pypy/objspace/std/

             cache[selector] = attr
         return attr
-    @jit.unroll_if(lambda self, obj, selector, w_value:
+    @jit.look_inside_iff(lambda self, obj, selector, w_value:
             jit.isconstant(self) and
             jit.isconstant(selector[0]) and

File pypy/rlib/

     warnings.warn("purefunction_promote is deprecated, use elidable_promote instead", DeprecationWarning)
     return elidable_promote(*args, **kwargs)
-def unroll_if(predicate):
+def look_inside_iff(predicate):
+    """
+    look inside (including unrolling loops) the target function, if and only if
+    predicate(*args) returns True
+    """
     def inner(func):
         func_unroll = unroll_safe(func_with_new_name(func, func.__name__ + "_unroll"))
-        for thing in func, func_unroll, predicate:
+        func = dont_look_inside(func)
+        for thing in [func, func_unroll, predicate]:
             thing._annspecialcase_ = "specialize:call_location"
         def f(*args):
                 return func(*args)
-        f.func_name = func.func_name + "_unroll_if"
+        f.func_name = func.func_name + "_look_inside_iff"
         return f
     return inner
     While tracing, returns whether or not the value is currently known to be
     constant. This is not perfect, values can become constant later. Mostly for
-    use with @unroll_if.
+    use with @look_inside_iff.
     # I hate the annotator so much.
     if NonConstant(False):

File pypy/rlib/rstruct/

     _mixin_ = True
     _operate_is_specialized_ = False
-    @jit.unroll_if(lambda self, fmt: jit.isconstant(fmt))
+    @jit.look_inside_iff(lambda self, fmt: jit.isconstant(fmt))
     def interpret(self, fmt):
         # decode the byte order, size and alignment based on the 1st char
         table = unroll_native_fmtdescs

File pypy/rpython/lltypesystem/

         ll_builder.used = needed + used
-    @jit.unroll_if(lambda ll_builder, char, times: jit.isconstant(times) and times <= 4)
+    @jit.look_inside_iff(lambda ll_builder, char, times: jit.isconstant(times) and times <= 4)
     def ll_append_multiple_char(ll_builder, char, times):
         used = ll_builder.used
         if times + used > ll_builder.allocated:

File pypy/rpython/lltypesystem/

             return -1
         return count
-    @jit.unroll_if(lambda length, items: jit.isconstant(length) and length <= 2)
+    @jit.look_inside_iff(lambda length, items: jit.isconstant(length) and length <= 2)
     @enforceargs(int, None)
     def ll_join_strs(length, items):
         # Special case for length 1 items, helps both the JIT and other code