[pypy-commit] pypy translation-cleanup: Do not wrap unrollers.

rlamy noreply at buildbot.pypy.org
Sat Oct 13 20:26:53 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r58109:f1d90d0488b3
Date: 2012-10-13 19:26 +0100
http://bitbucket.org/pypy/pypy/changeset/f1d90d0488b3/

Log:	Do not wrap unrollers.

	Since they aren't Python objects, it doesn't make much sense to wrap
	them inside Constant(). Not doing it simplifies the code a bit.

	+ Remove costly isinstance() check.

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -574,18 +574,14 @@
         if w_top == self.space.w_None:
             # finally: block with no unroller active
             return
-        try:
-            unroller = self.space.unwrap(w_top)
-        except UnwrapException:
-            pass
+        elif isinstance(w_top, SuspendedUnroller):
+            # case of a finally: block
+            return self.unroll_finally(w_top)
         else:
-            if isinstance(unroller, SuspendedUnroller):
-                # case of a finally: block
-                return self.unroll_finally(unroller)
-        # case of an except: block.  We popped the exception type
-        self.popvalue()        #     Now we pop the exception value
-        unroller = self.space.unwrap(self.popvalue())
-        return self.unroll_finally(unroller)
+            # case of an except: block.  We popped the exception type
+            self.popvalue()        #     Now we pop the exception value
+            unroller = self.popvalue()
+            return self.unroll_finally(unroller)
 
     def unroll_finally(self, unroller):
         # go on unrolling the stack
@@ -667,14 +663,13 @@
         # and cannot suppress the exception.
         # This opcode changed a lot between CPython versions
         if sys.version_info >= (2, 6):
-            w_unroller = self.popvalue()
+            unroller = self.popvalue()
             w_exitfunc = self.popvalue()
-            self.pushvalue(w_unroller)
+            self.pushvalue(unroller)
         else:
             w_exitfunc = self.popvalue()
-            w_unroller = self.peekvalue(0)
+            unroller = self.peekvalue(0)
 
-        unroller = self.space.unwrap(w_unroller)
         w_None = self.space.w_None
         if isinstance(unroller, SApplicationException):
             operr = unroller.operr
@@ -890,7 +885,7 @@
         # the stack setup is slightly different than in CPython:
         # instead of the traceback, we store the unroller object,
         # wrapped.
-        frame.pushvalue(frame.space.wrap(unroller))
+        frame.pushvalue(unroller)
         frame.pushvalue(operationerr.get_w_value(frame.space))
         frame.pushvalue(operationerr.w_type)
         frame.last_exception = operationerr
@@ -906,7 +901,7 @@
         # any abnormal reason for unrolling a finally: triggers the end of
         # the block unrolling and the entering the finally: handler.
         self.cleanupstack(frame)
-        frame.pushvalue(frame.space.wrap(unroller))
+        frame.pushvalue(unroller)
         return self.handlerposition   # jump to the handler
 
 
diff --git a/pypy/objspace/flow/framestate.py b/pypy/objspace/flow/framestate.py
--- a/pypy/objspace/flow/framestate.py
+++ b/pypy/objspace/flow/framestate.py
@@ -6,9 +6,6 @@
         self.mergeable = mergeable
         self.blocklist = blocklist
         self.next_instr = next_instr
-        for w1 in self.mergeable:
-            assert isinstance(w1, (Variable, Constant)) or w1 is None, (
-                '%r found in frame state' % w1)
 
     def copy(self):
         "Make a copy of this state in which all Variables are fresh."
@@ -109,12 +106,10 @@
     from pypy.objspace.flow.flowcontext import SuspendedUnroller
     i = 0
     while i < len(lst):
-        item = lst[i]
-        if not (isinstance(item, Constant) and
-                isinstance(item.value, SuspendedUnroller)):
+        unroller = lst[i]
+        if not isinstance(unroller, SuspendedUnroller):
             i += 1
         else:
-            unroller = item.value
             vars = unroller.state_unpack_variables(space)
             key = unroller.__class__, len(vars)
             try:
@@ -132,4 +127,4 @@
             arguments = lst[i+1: i+1+argcount]
             del lst[i+1: i+1+argcount]
             unroller = unrollerclass.state_pack_variables(space, *arguments)
-            lst[i] = space.wrap(unroller)
+            lst[i] = unroller


More information about the pypy-commit mailing list