Commits

Carl Friedrich Bolz  committed f12ceee

(mikael, cfbolz, pedronis, arigo): move removing of asserts to the beginning of
doing optimizations

  • Participants
  • Parent commits 901edb4

Comments (0)

Files changed (3)

File pypy/config/translationoption.py

                    "Remove operations that look like 'raise AssertionError', "
                    "which lets the C optimizer remove the asserts",
                    default=False),
+        BoolOption("really_remove_asserts",
+                   "Really remove operations that look like 'raise AssertionError', "
+                   "without relying on the C compiler",
+                   default=False),
 
         BoolOption("stack_optimization",
                    "Tranform graphs in SSI form into graphs tailored for "

File pypy/translator/backendopt/all.py

     if translator.rtyper.type_system.name == 'ootypesystem':
         check_virtual_methods()
 
+    if config.remove_asserts:
+        constfold(config, graphs)
+        remove_asserts(translator, graphs)
+
+    if config.really_remove_asserts:
+        for graph in graphs:
+            removenoops.remove_debug_assert(graph)
+        # the dead operations will be killed by the remove_obvious_noops below
+
     # remove obvious no-ops
     def remove_obvious_noops():
         for graph in graphs:
                                     call_count_pred=call_count_pred)
     constfold(config, graphs)
 
-    if config.remove_asserts:
-        remove_asserts(translator, graphs)
-
     if config.heap2stack:
         assert graphs is translator.graphs  # XXX for now
         malloc_to_stack(translator)

File pypy/translator/backendopt/test/test_all.py

 from pypy.translator.backendopt.test.test_malloc import TestLLTypeMallocRemoval as LLTypeMallocRemovalTest
 from pypy.translator.backendopt.test.test_malloc import TestOOTypeMallocRemoval as OOTypeMallocRemovalTest
 from pypy.translator.translator import TranslationContext, graphof
-from pypy.objspace.flow.model import Constant
+from pypy.objspace.flow.model import Constant, summary
 from pypy.annotation import model as annmodel
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rlib.rarithmetic import intmask
             assert Constant(7) not in link.args
             assert Constant(11) not in link.args
 
+    def test_isinstance(self):
+        class A:
+            pass
+        class B(A):
+            pass
+        def g(n):
+            if n > 10:
+                return A()
+            else:
+                b = B()
+                b.value = 321
+                return b
+        def fn(n):
+            x = g(n)
+            assert isinstance(x, B)
+            return x.value
+        t = self.translateopt(fn, [int], really_remove_asserts=True,
+                              remove_asserts=True)
+        graph = graphof(t, fn)
+        assert "direct_call" not in summary(graph)
+
 class TestLLType(BaseTester):
     type_system = 'lltype'
     check_malloc_removed = LLTypeMallocRemovalTest.check_malloc_removed