[pypy-svn] r10027 - in pypy/dist/pypy: objspace/flow translator translator/test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 21 22:36:53 CET 2005
Author: arigo
Date: Mon Mar 21 22:36:53 2005
New Revision: 10027
Modified:
pypy/dist/pypy/objspace/flow/model.py
pypy/dist/pypy/translator/simplify.py
pypy/dist/pypy/translator/test/test_translator.py
Log:
An invalid simplification fixed in simplify.py. Added a test for it and a way
to look at the broken graphs when they occur.
Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py (original)
+++ pypy/dist/pypy/objspace/flow/model.py Mon Mar 21 22:36:53 2005
@@ -379,6 +379,7 @@
except AssertionError, e:
# hack for debug tools only
+ #graph.show() <== ENABLE THIS TO SEE THE BROKEN GRAPH
if this_block[0] and not hasattr(e, '__annotator_block'):
setattr(e, '__annotator_block', this_block[0])
raise
Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py (original)
+++ pypy/dist/pypy/translator/simplify.py Mon Mar 21 22:36:53 2005
@@ -146,12 +146,20 @@
but not used in the target block. Input is a set of blocks"""
read_vars = {} # set of variables really used
variable_flow = {} # map {Var: list-of-Vars-it-depends-on}
-
+
+ def canremove(op, block):
+ if op.opname not in CanRemove:
+ return False
+ if block.exitswitch != Constant(last_exception):
+ return True
+ # cannot remove the exc-raising operation
+ return op is not block.operations[-1]
+
# compute variable_flow and an initial read_vars
for block in blocks:
# figure out which variables are ever read
for op in block.operations:
- if op.opname not in CanRemove: # mark the inputs as really needed
+ if not canremove(op, block): # mark the inputs as really needed
for arg in op.args:
read_vars[arg] = True
else:
@@ -198,7 +206,7 @@
for i in range(len(block.operations)-1, -1, -1):
op = block.operations[i]
if op.result not in read_vars:
- if op.opname in CanRemove:
+ if canremove(op, block):
del block.operations[i]
elif op.opname == 'simple_call':
# XXX we want to have a more effective and safe
Modified: pypy/dist/pypy/translator/test/test_translator.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_translator.py (original)
+++ pypy/dist/pypy/translator/test/test_translator.py Mon Mar 21 22:36:53 2005
@@ -1,4 +1,14 @@
import autopath
from pypy.translator.translator import Translator
-from pypy.translator.test import snippet
+
+def example(d):
+ try:
+ d['key']
+ except KeyError:
+ d['key'] = 'value'
+
+def test_example():
+ t = Translator(example)
+ t.simplify() # this specific example triggered a bug in simplify.py
+ #t.view()
More information about the Pypy-commit
mailing list