[pypy-commit] pypy exc-later: Reinstate the parts of specialize_exceptions() that add code branches.

rlamy noreply at buildbot.pypy.org
Fri Nov 13 21:11:41 EST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: exc-later
Changeset: r80672:5cdd77f61327
Date: 2015-11-13 20:04 +0000
http://bitbucket.org/pypy/pypy/changeset/5cdd77f61327/

Log:	Reinstate the parts of specialize_exceptions() that add code
	branches.

diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -311,6 +311,36 @@
                 stack.extend(link.target.exits)
                 seen[link.target] = True
 
+def propagate_uncaught_exceptions(graph):
+    """Add the equivalent of:
+        except OverflowError:
+            raise
+        except Exception:
+            raise
+    to any try: except: suite that misses them."""
+    for block in list(graph.iterblocks()):
+        if block.canraise:
+            op = block.raising_op
+            exits = list(block.exits)
+            if OverflowError in op.canraise:
+                if not any(issubclass(OverflowError, exit.exitcase)
+                           for exit in block.exits[1:]):
+                    v_etype = const(OverflowError)
+                    v_exc = Variable('last_exc_value')
+                    exit = Link([v_etype, v_exc], graph.exceptblock, OverflowError)
+                    exit.extravars(v_etype, v_exc)
+                    exits.append(exit)
+            if Exception in op.canraise:
+                if block.exits[-1].exitcase is not Exception:
+                    v_etype = Variable('last_exception')
+                    v_exc = Variable('last_exc_value')
+                    exit = Link([v_etype, v_exc], graph.exceptblock, Exception)
+                    exit.extravars(v_etype, v_exc)
+                    exits.append(exit)
+            block.recloseblock(*exits)
+            if len(exits) == 1:
+                block.exitswitch = None
+
 
 def remove_assertion_errors(graph):
     """Remove branches that go directly to raising an AssertionError,
@@ -1053,6 +1083,7 @@
     transform_ovfcheck,
     simplify_exceptions,
     remove_assertion_errors,
+    propagate_uncaught_exceptions,
     remove_dead_exceptions,
     join_blocks,
     ]


More information about the pypy-commit mailing list