[pypy-svn] r49998 - in pypy/dist/pypy/translator: backendopt backendopt/test c/test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 22 10:17:13 CET 2007


Author: arigo
Date: Sat Dec 22 10:17:12 2007
New Revision: 49998

Modified:
   pypy/dist/pypy/translator/backendopt/inline.py
   pypy/dist/pypy/translator/backendopt/test/test_all.py
   pypy/dist/pypy/translator/backendopt/test/test_constfold.py
   pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
When doing secondary backendopts, don't inline a graph
that is not in the 'graphs' list.  The issue, shown by
test_boehm, is that the graphs outside the list may
already be exception-transformed.  The inliner cannot
do something sane with them.


Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py	(original)
+++ pypy/dist/pypy/translator/backendopt/inline.py	Sat Dec 22 10:17:12 2007
@@ -625,6 +625,7 @@
 
 
 def inlinable_static_callers(graphs):
+    ok_to_call = dict.fromkeys(graphs)
     result = []
     for parentgraph in graphs:
         for block in parentgraph.iterblocks():
@@ -632,7 +633,7 @@
                 if op.opname == "direct_call":
                     funcobj = get_funcobj(op.args[0].value)
                     graph = getattr(funcobj, 'graph', None)
-                    if graph is not None:
+                    if graph is not None and graph in ok_to_call:
                         if getattr(getattr(funcobj, '_callable', None),
                                    '_dont_inline_', False):
                             continue
@@ -640,7 +641,7 @@
                 if op.opname == "oosend":
                     meth = get_meth_from_oosend(op)
                     graph = getattr(meth, 'graph', None)
-                    if graph is not None:
+                    if graph is not None and graph in ok_to_call:
                         result.append((parentgraph, graph))
     return result
     

Modified: pypy/dist/pypy/translator/backendopt/test/test_all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_all.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_all.py	Sat Dec 22 10:17:12 2007
@@ -230,6 +230,53 @@
         res = interp.eval_graph(f_graph, [11, 22])
         assert res == 33
 
+    def test_secondary_backendopt(self):
+        # checks an issue with a newly added graph that calls an
+        # already-exception-transformed graph.  This can occur e.g.
+        # from a late-seen destructor added by the GC transformer
+        # which ends up calling existing code.
+        def common(n):
+            if n > 5:
+                raise ValueError
+        def main(n):
+            common(n)
+        def later(n):
+            try:
+                common(n)
+                return 0
+            except ValueError:
+                return 1
+
+        t = TranslationContext()
+        t.buildannotator().build_types(main, [int])
+        t.buildrtyper(type_system='lltype').specialize()
+        exctransformer = t.getexceptiontransformer()
+        exctransformer.create_exception_handling(graphof(t, common))
+        from pypy.annotation import model as annmodel
+        from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
+        annhelper = MixLevelHelperAnnotator(t.rtyper)
+        later_graph = annhelper.getgraph(later, [annmodel.SomeInteger()],
+                                         annmodel.SomeInteger())
+        annhelper.finish()
+        annhelper.backend_optimize()
+        # ^^^ as the inliner can't handle exception-transformed graphs,
+        # this should *not* inline common() into later().
+        if conftest.option.view:
+            later_graph.show()
+        common_graph = graphof(t, common)
+        found = False
+        for block in later_graph.iterblocks():
+            for op in block.operations:
+                if (op.opname == 'direct_call' and
+                    op.args[0].value._obj.graph is common_graph):
+                    found = True
+        assert found, "cannot find the call (buggily inlined?)"
+        from pypy.rpython.llinterp import LLInterpreter
+        llinterp = LLInterpreter(t.rtyper)
+        res = llinterp.eval_graph(later_graph, [10])
+        assert res == 1
+
+
 class TestOOType(BaseTester):
     type_system = 'ootype'
     check_malloc_removed = OOTypeMallocRemovalTest.check_malloc_removed

Modified: pypy/dist/pypy/translator/backendopt/test/test_constfold.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_constfold.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_constfold.py	Sat Dec 22 10:17:12 2007
@@ -261,7 +261,7 @@
 
     graph, t = get_graph(fn, [int])
     from pypy.translator.backendopt import removenoops, inline
-    inline.auto_inline_graphs(t, [graph], threshold=999)
+    inline.auto_inline_graphs(t, t.graphs, threshold=999)
     constant_fold_graph(graph)
     removenoops.remove_same_as(graph)
     if conftest.option.view:
@@ -303,7 +303,7 @@
 
     graph, t = get_graph(fn, [int])
     from pypy.translator.backendopt import removenoops, inline
-    inline.auto_inline_graphs(t, [graph], threshold=999)
+    inline.auto_inline_graphs(t, t.graphs, threshold=999)
     removenoops.remove_same_as(graph)
     constant_fold_graph(graph)
     if conftest.option.view:

Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Sat Dec 22 10:17:12 2007
@@ -150,7 +150,6 @@
 
     def test_del_raises(self):
         from pypy.rpython.lltypesystem.lloperation import llop
-        import os
         class A(object):
             def __del__(self):
                 s.dels += 1



More information about the Pypy-commit mailing list