[pypy-commit] pypy exc-later: Fix handling of implicit exceptions
rlamy
noreply at buildbot.pypy.org
Tue Mar 17 20:29:34 CET 2015
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: exc-later
Changeset: r76443:55b6905f0451
Date: 2015-03-14 05:25 +0000
http://bitbucket.org/pypy/pypy/changeset/55b6905f0451/
Log: Fix handling of implicit exceptions
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -335,13 +335,6 @@
self.stack = state.stack[:]
self.last_exception = state.last_exception
self.blockstack = state.blocklist[:]
- self._normalize_raise_signals()
-
- def _normalize_raise_signals(self):
- st = self.stack
- for i in range(len(st)):
- if isinstance(st[i], RaiseImplicit):
- st[i] = Raise(st[i].w_exc)
def guessbool(self, w_condition):
if isinstance(w_condition, Constant):
@@ -677,7 +670,7 @@
return
elif isinstance(w_top, FlowSignal):
# case of a finally: block
- raise w_top
+ raise w_top.as_explicit()
else:
# case of an except: block. We popped the exception type
self.popvalue() # Now we pop the exception value
@@ -1162,6 +1155,9 @@
def __eq__(self, other):
return type(other) is type(self) and other.args == self.args
+ def as_explicit(self):
+ return self
+
class Return(FlowSignal):
"""Signals a 'return' statement.
@@ -1223,6 +1219,9 @@
ctx.recorder.crnt_block.closeblock(link)
raise StopFlowing
+ def as_explicit(self):
+ return Raise(self.w_exc)
+
class Break(FlowSignal):
"""Signals a 'break' statement."""
diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -335,11 +335,8 @@
x = self.codetest(self.implicitException_os_stat)
simplify_graph(x)
self.show(x)
- assert len(x.startblock.exits) == 3
- d = {}
- for link in x.startblock.exits:
- d[link.exitcase] = True
- assert d == {None: True, OSError: True, Exception: True}
+ exc_cases = [exit.exitcase for exit in x.startblock.exits]
+ assert exc_cases == [None, OSError]
#__________________________________________________________
def reraiseAnythingDicCase(dic):
@@ -503,14 +500,8 @@
graph = self.codetest(self.multiple_catch_simple_call)
simplify_graph(graph)
assert self.all_operations(graph) == {'simple_call': 1}
- entrymap = mkentrymap(graph)
- links = entrymap[graph.returnblock]
- assert len(links) == 3
- assert (dict.fromkeys([link.exitcase for link in links]) ==
- dict.fromkeys([None, IndexError, OSError]))
- links = entrymap[graph.exceptblock]
- assert len(links) == 1
- assert links[0].exitcase is Exception
+ exc_cases = [exit.exitcase for exit in graph.startblock.exits]
+ assert exc_cases == [None, IndexError, OSError]
#__________________________________________________________
def dellocal():
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -353,10 +353,11 @@
else:
# ignore the uncaught implicit exception
continue
- exits = [block.exits[0]] + exits
if has_generic_case:
exits += exc_exits
- block.recloseblock(*exits)
+ if not exits:
+ block.exitswitch = None
+ block.recloseblock(block.exits[0], *exits)
@@ -1104,6 +1105,7 @@
specialize_exceptions,
remove_dead_exceptions,
transform_xxxitem,
+ join_blocks,
]
def simplify_graph(graph, passes=True): # can take a list of passes to apply, True meaning all
More information about the pypy-commit
mailing list