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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 16 19:39:26 CET 2006


Author: cfbolz
Date: Mon Jan 16 19:39:25 2006
New Revision: 22235

Modified:
   pypy/dist/pypy/translator/backendopt/escape.py
   pypy/dist/pypy/translator/backendopt/test/test_escape.py
Log:
fix indirect_call when the set of graphs that can be called is unknown


Modified: pypy/dist/pypy/translator/backendopt/escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/escape.py	Mon Jan 16 19:39:25 2006
@@ -310,14 +310,23 @@
     def indirect_call(self, op, function, *args):
         graphs = op.args[-1].value
         args = args[:-1]
-        for graph in graphs:
-            result, funcargs = self.schedule_function(graph)
-            assert len(args) == len(funcargs)
-            for localarg, funcarg in zip(args, funcargs):
+        if graphs is None:
+            for localarg in args:
                 if localarg is None:
-                    assert funcarg is None
                     continue
-                self.register_state_dependency(localarg, funcarg)
+                changed = localarg.setescapes()
+                self.handle_changed(changed)
+                changed = localarg.setchanges()
+                self.handle_changed(changed)
+        else:
+            for graph in graphs:
+                result, funcargs = self.schedule_function(graph)
+                assert len(args) == len(funcargs)
+                for localarg, funcarg in zip(args, funcargs):
+                    if localarg is None:
+                        assert funcarg is None
+                        continue
+                    self.register_state_dependency(localarg, funcarg)
         if isonheap(op.result):
             # assume that a call creates a new value
             return VarState(self.get_creationpoint(op.result, "indirect_call"))

Modified: pypy/dist/pypy/translator/backendopt/test/test_escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_escape.py	Mon Jan 16 19:39:25 2006
@@ -2,6 +2,7 @@
 from pypy.translator.backendopt.escape import AbstractDataFlowInterpreter, malloc_to_stack
 from pypy.translator.backendopt.escape import find_backedges, find_loop_blocks
 from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython.objectmodel import instantiate
 
 def build_adi(function, types):
     t = TranslationContext()
@@ -293,6 +294,20 @@
     assert a1crep.changes and a2crep.changes
     assert not a1crep.escapes and a2crep.escapes
 
+def test_indirect_call_unknown_graphs():
+    class A:
+        pass
+    class B:
+        pass
+    def f(i):
+        if i:
+            klass = A
+        else:
+            klass = B
+        a = instantiate(klass)
+    # does not crash
+    t, adi, graph = build_adi(f, [int])
+
 def test_getarray():
     class A(object):
         pass



More information about the Pypy-commit mailing list