Author: Armin Rigo <[email protected]>
Branch: record-known-result
Changeset: r97844:7e2f7fad5601
Date: 2019-10-24 13:53 +0200
http://bitbucket.org/pypy/pypy/changeset/7e2f7fad5601/

Log:    Test and fix annotation for record_exact_value()

diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1213,7 +1213,7 @@
         func(*args)
     return _jit_record_known_result(result, func, *args)
 
-class ConditionalCallEntry(ExtRegistryEntry):
+class Entry(ExtRegistryEntry):
     _about_ = _jit_record_known_result
 
     def compute_result_annotation(self, *args_s):
@@ -1237,6 +1237,7 @@
     Assure the JIT that value is the same as const_value
     """
     assert value == const_value
+    return const_value
 
 def ll_record_exact_value(ll_value, ll_const_value):
     from rpython.rlib.debug import ll_assert
@@ -1244,27 +1245,33 @@
     from rpython.rtyper.lltypesystem import lltype
     ll_assert(ll_value == ll_const_value, "record_exact_value called with two 
different arguments")
     llop.jit_record_exact_value(lltype.Void, ll_value, ll_const_value)
+    return ll_const_value
 
 class Entry(ExtRegistryEntry):
     _about_ = record_exact_value
 
     def compute_result_annotation(self, s_val, s_const_val):
         from rpython.annotator import model as annmodel
-        annmodel.unionof(s_val, s_const_val) # produce error if types are 
incompatible
+        # produce error if types are incompatible
+        s_common = annmodel.unionof(s_val, s_const_val)
+        # we need to keep this annotation around for specialize_call().
+        # The easiest is to use this union as the return value.
+        return s_common
 
     def specialize_call(self, hop):
         from rpython.rtyper.lltypesystem import lltype
         from rpython.rtyper import rclass
 
-        v_inst = hop.inputarg(hop.args_r[0], arg=0)
-        v_const_inst = hop.inputarg(hop.args_r[1], arg=1)
+        r_common = hop.r_result    # from the union of the two annotations
+        v_inst = hop.inputarg(r_common, arg=0)
+        v_const_inst = hop.inputarg(r_common, arg=1)
         hop.exception_is_here()
         return hop.gendirectcall(ll_record_exact_value, v_inst, v_const_inst)
 
+
 def _jit_conditional_call(condition, function, *args):
     pass           # special-cased below
 
-
 @specialize.call_location()
 def conditional_call(condition, function, *args):
     """Does the same as:
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
@@ -370,6 +370,17 @@
             record_exact_value(a, a) # assume not crash
         self.interpret(g, [])
 
+    def test_record_exact_value_2(self):
+        class A(object):
+            pass
+        def make(j):
+            if j < 5: return None
+            return A()
+        def g(j):
+            a = make(j)
+            record_exact_value(a, None)
+        self.interpret(g, [3])
+
     def test_record_exact_value_int(self):
         @dont_look_inside
         def f():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to