[pypy-svn] r25644 - in pypy/dist/pypy/translator: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Apr 10 01:55:29 CEST 2006


Author: cfbolz
Date: Mon Apr 10 01:55:27 2006
New Revision: 25644

Modified:
   pypy/dist/pypy/translator/simplify.py
   pypy/dist/pypy/translator/test/test_simplify.py
Log:
make has_no_side_effects more precise: follow all graphs instead of giving up
when seeing an indirect_call


Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py	(original)
+++ pypy/dist/pypy/translator/simplify.py	Mon Apr 10 01:55:27 2006
@@ -383,9 +383,11 @@
         if graph.startblock not in translator.rtyper.already_seen:
             return False
     if seen is None:
-        seen = []
+        seen = {}
     elif graph in seen:
         return True
+    newseen = seen.copy()
+    newseen[graph] = True
     try:
         def visit(block):
             if not isinstance(block, Block):
@@ -395,12 +397,15 @@
                     g = get_graph(op.args[0], translator)
                     if g is None:
                         raise HasSideEffects
-                    if not has_no_side_effects(translator, g, seen + [graph]):
+                    if not has_no_side_effects(translator, g, newseen):
                         raise HasSideEffects
                 elif op.opname == "indirect_call":
-                    # XXX can be improved: look at all graphs,
-                    # if they are there
-                    raise HasSideEffects
+                    graphs = op.args[-1].value
+                    if graphs is None:
+                        raise HasSideEffects
+                    for g in graphs:
+                        if not has_no_side_effects(translator, g, newseen):
+                            raise HasSideEffects
                 elif lloperation.LL_OPERATIONS[op.opname].sideeffects:
                     raise HasSideEffects
         traverse(visit, graph)

Modified: pypy/dist/pypy/translator/test/test_simplify.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_simplify.py	(original)
+++ pypy/dist/pypy/translator/test/test_simplify.py	Mon Apr 10 01:55:27 2006
@@ -37,7 +37,24 @@
         a = rec(x)
         return x + 12
     graph, _ = translate(f, [int])
-    assert len(graph.startblock.operations)
+    assert len(graph.startblock.operations) == 1
+
+def test_remove_call_with_indirect_call():
+    def f1(x):
+        return x + 1
+    def f2(x):
+        return x + 2
+    def g(x):
+        if x == 32:
+            f = f1
+        else:
+            f = f2
+        return f(x)
+    def h(x):
+        a = g(x)
+        return x + 42
+    graph, t = translate(h, [int])
+    assert len(graph.startblock.operations) == 1
 
 def test_dont_remove_if_exception_guarded():
     def f(x):



More information about the Pypy-commit mailing list