[pypy-commit] pypy default: flow space: only emit ll_assert_not_none() in some forms of raise,

arigo pypy.commits at gmail.com
Sat Dec 17 11:59:42 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r89118:e58b69ffe5aa
Date: 2016-12-17 17:59 +0100
http://bitbucket.org/pypy/pypy/changeset/e58b69ffe5aa/

Log:	flow space: only emit ll_assert_not_none() in some forms of raise,
	not if we built the exception instance just now

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -599,6 +599,7 @@
         """
         from rpython.rlib.debug import ll_assert_not_none
 
+        check_not_none = False
         w_is_type = op.isinstance(w_arg1, const(type)).eval(self)
         if self.guessbool(w_is_type):
             # this is for all cases of the form (Class, something)
@@ -610,6 +611,7 @@
                 if self.guessbool(op.issubtype(w_valuetype, w_arg1).eval(self)):
                     # raise Type, Instance: let etype be the exact type of value
                     w_value = w_arg2
+                    check_not_none = True
                 else:
                     # raise Type, X: assume X is the constructor argument
                     w_value = op.simple_call(w_arg1, w_arg2).eval(self)
@@ -620,7 +622,10 @@
                                 "separate value")
                 raise Raise(const(exc))
             w_value = w_arg1
-        w_value = op.simple_call(const(ll_assert_not_none), w_value).eval(self)
+            check_not_none = True
+        if check_not_none:
+            w_value = op.simple_call(const(ll_assert_not_none),
+                                     w_value).eval(self)
         w_type = op.type(w_value).eval(self)
         return FSException(w_type, w_value)
 
diff --git a/rpython/jit/codewriter/test/test_flatten.py b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -466,6 +466,14 @@
             int_return $True
         """, transform=True)
 
+    def test_assert_disappears(self):
+        def f(i):
+            assert i > 5
+            return i
+        self.encoding_test(f, [7], """
+            int_return %i0
+        """)
+
     def test_int_floordiv_ovf_zer(self):
         def f(i, j):
             assert i >= 0


More information about the pypy-commit mailing list