[pypy-svn] r15474 - in pypy/dist/pypy: rpython/test translator

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Jul 31 16:29:13 CEST 2005


Author: cfbolz
Date: Sun Jul 31 16:29:10 2005
New Revision: 15474

Modified:
   pypy/dist/pypy/rpython/test/test_rspecialcase.py
   pypy/dist/pypy/translator/backendoptimization.py
   pypy/dist/pypy/translator/simplify.py
Log:
(pedronis, cfbolz):
fixed eliminate_empty_blocks so that it removes now empty try
blocks.


Modified: pypy/dist/pypy/rpython/test/test_rspecialcase.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rspecialcase.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rspecialcase.py	Sun Jul 31 16:29:10 2005
@@ -1,5 +1,5 @@
 from pypy.rpython.lltype import *
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.test_llinterp import interpret, gengraph
 
 from pypy.translator.ann_override import PyPyAnnotatorPolicy
 
@@ -13,13 +13,32 @@
             return "ab"
         else:
             return f()
-
     res = interpret(g, [0])
     assert not res
     res = interpret(g, [1])
     assert ''.join(res.chars) == "ab"
+
+def test_ignore_breaking_transformations():
+    def f():
+        pass
+    f._annspecialcase_ = "override:ignore"
+    def g(i):
+        if i == 1:
+            return "ab"
+        else:
+            try:
+                return f()
+            except:
+                return "hello!"
+    t, typer = gengraph(g, [int])
+    from pypy.translator import backendoptimization, simplify
+    from pypy.objspace.flow.model import checkgraph
+    graph = t.getflowgraph(g)
+    backendoptimization.remove_same_as(graph)
+    simplify.eliminate_empty_blocks(graph)
+    #should not crash:
+    checkgraph(graph)
     
-        
 def test_meth_override_ignore():
     class X:
         def f(self):

Modified: pypy/dist/pypy/translator/backendoptimization.py
==============================================================================
--- pypy/dist/pypy/translator/backendoptimization.py	(original)
+++ pypy/dist/pypy/translator/backendoptimization.py	Sun Jul 31 16:29:10 2005
@@ -1,5 +1,6 @@
 import autopath
 from pypy.translator.translator import Translator
+from pypy.translator.simplify import eliminate_empty_blocks
 from pypy.objspace.flow.model import Variable, Constant, Block, Link
 from pypy.objspace.flow.model import SpaceOperation
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
@@ -148,6 +149,8 @@
 
 def backend_optimizations(graph):
     remove_same_as(graph)
+    eliminate_empty_blocks(graph)
+    checkgraph(graph)
     SSI_to_SSA(graph)
     checkgraph(graph)
 

Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py	(original)
+++ pypy/dist/pypy/translator/simplify.py	Sun Jul 31 16:29:10 2005
@@ -18,7 +18,13 @@
     following link.  Arguments of the links should be updated."""
     def visit(link):
         if isinstance(link, Link):
-            while not link.target.operations and len(link.target.exits) == 1:
+            while not link.target.operations:
+                if len(link.target.exits) != 1:
+                    print link.target.exits
+                    print link.target.exitswitch
+                    print "###########################################"
+                    if link.target.exitswitch != Constant(last_exception):
+                        break
                 assert link.target is not link.prevblock, (
                     "the graph contains an empty infinite loop")
                 block1 = link.target



More information about the Pypy-commit mailing list