Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5
Changeset: r88644:a016f52580ec
Date: 2016-11-24 17:58 +0100
http://bitbucket.org/pypy/pypy/changeset/a016f52580ec/

Log:    hg merge default

diff --git a/rpython/jit/metainterp/blackhole.py 
b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -6,7 +6,7 @@
 from rpython.jit.metainterp.history import MissingValue
 from rpython.rlib import longlong2float
 from rpython.rlib.debug import ll_assert, make_sure_not_resized
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, specialize
 from rpython.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
@@ -132,20 +132,8 @@
                 elif argtype == 'I' or argtype == 'R' or argtype == 'F':
                     assert argcodes[next_argcode] == argtype
                     next_argcode = next_argcode + 1
-                    length = ord(code[position])
-                    position += 1
-                    value = []
-                    for i in range(length):
-                        index = ord(code[position+i])
-                        if   argtype == 'I': reg = self.registers_i[index]
-                        elif argtype == 'R': reg = self.registers_r[index]
-                        elif argtype == 'F': reg = self.registers_f[index]
-                        if not we_are_translated():
-                            assert not isinstance(reg, MissingValue), (
-                                name, self.jitcode, position)
-                        value.append(reg)
-                    make_sure_not_resized(value)
-                    position += length
+                    value = self._get_list_of_values(code, position, argtype)
+                    position += 1 + len(value)
                 elif argtype == 'self':
                     value = self
                 elif argtype == 'cpu':
@@ -1657,6 +1645,24 @@
             if box is not None:
                 self.setarg_f(i, box.getfloatstorage())
 
+    @specialize.arg(3)
+    def _get_list_of_values(self, code, position, argtype):
+        length = ord(code[position])
+        position += 1
+        value = []
+        for i in range(length):
+            index = ord(code[position+i])
+            if   argtype == 'I': reg = self.registers_i[index]
+            elif argtype == 'R': reg = self.registers_r[index]
+            elif argtype == 'F': reg = self.registers_f[index]
+            else: assert 0
+            if not we_are_translated():
+                assert not isinstance(reg, MissingValue), (
+                    name, self.jitcode, position)
+            value.append(reg)
+        make_sure_not_resized(value)
+        return value
+
 # ____________________________________________________________
 
 def _run_forever(blackholeinterp, current_exc):
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1243,7 +1243,13 @@
                                                  args_s[1], args_s[2:])
         if self.instance == _jit_conditional_call_value:
             from rpython.annotator import model as annmodel
-            return annmodel.unionof(s_res, args_s[0])
+            # the result is either s_res, i.e. the function result, or
+            # it is args_s[0]-but-not-none.  The "not-none" part is
+            # only useful for pointer-like types, but it means that
+            # args_s[0] could be NULL without the result of the whole
+            # conditional_call_elidable() necessarily returning a result
+            # that can be NULL.
+            return annmodel.unionof(s_res, args_s[0].nonnoneify())
 
     def specialize_call(self, hop):
         from rpython.rtyper.lltypesystem import lltype
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -314,6 +314,24 @@
         res = self.interpret(f, [-42, 1000, 100])
         assert res == -42
 
+    def test_conditional_call_elidable_annotates_nonnull(self):
+        class X:
+            pass
+        def g(n):
+            return X()   # non-null
+        def f(x, n):
+            y = conditional_call_elidable(x, g, n)
+            return y     # now, y is known to be non-null, even if x can be
+        def main(n):
+            if n > 100:
+                x = X()
+            else:
+                x = None
+            return f(x, n)
+        t = TranslationContext()
+        s = t.buildannotator().build_types(main, [int])
+        assert s.can_be_None is False
+
     def test_enter_leave_portal_frame(self):
         from rpython.translator.interactive import Translation
         def g():
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to