[pypy-commit] pypy guard-compatible: test and fix

cfbolz pypy.commits at gmail.com
Mon May 23 05:29:54 EDT 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: guard-compatible
Changeset: r84618:69f037c8ed73
Date: 2016-05-23 11:29 +0200
http://bitbucket.org/pypy/pypy/changeset/69f037c8ed73/

Log:	test and fix

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -187,7 +187,7 @@
     def _get_mapdict_map(self):
         return None
     def _get_mapdict_map_no_promote(self):
-        return None
+        raise TypeError
     def _set_mapdict_map(self, map):
         raise NotImplementedError
     def _mapdict_read_storage(self, index):
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -17,6 +17,8 @@
 erase_map,  unerase_map = rerased.new_erasing_pair("map")
 erase_list, unerase_list = rerased.new_erasing_pair("mapdict storage list")
 
+def check_not_none(s_arg, bk):
+    assert not s_arg.can_be_none()
 
 # ____________________________________________________________
 # attribute shapes
@@ -698,13 +700,15 @@
     def _get_mapdict_map(self):
         return jit.promote(self.map)
     def _get_mapdict_map_no_promote(self):
+        debug.check_annotation(self.map, check_not_none)
         return self.map
     def _set_mapdict_map(self, map):
+        assert map is not None
         self.map = map
 
     def _mapdict_init_empty(self, map):
         from rpython.rlib.debug import make_sure_not_resized
-        self.map = map
+        self._set_mapdict_map(map)
         self.storage = make_sure_not_resized([None] * map.size_estimate())
 
     def _mapdict_read_storage(self, storageindex):
@@ -719,7 +723,7 @@
 
     def _set_mapdict_storage_and_map(self, storage, map):
         self.storage = storage
-        self.map = map
+        self._set_mapdict_map(map)
 
 class ObjectWithoutDict(W_Root):
     # mainly for tests
@@ -750,14 +754,16 @@
         def _get_mapdict_map(self):
             return jit.promote(self.map)
         def _get_mapdict_map_no_promote(self):
+            debug.check_annotation(self.map, check_not_none)
             return self.map
         def _set_mapdict_map(self, map):
+            assert map is not None
             self.map = map
         def _mapdict_init_empty(self, map):
             for i in rangenmin1:
                 setattr(self, "_value%s" % i, None)
             setattr(self, valnmin1, erase_item(None))
-            self.map = map
+            self._set_mapdict_map(map)
 
         def _has_storage_list(self):
             return self.map._length_larger_than(n)
@@ -793,7 +799,7 @@
             return n
 
         def _set_mapdict_storage_and_map(self, storage, map):
-            self.map = map
+            self._set_mapdict_map(map)
             len_storage = len(storage)
             for i in rangenmin1:
                 if i < len_storage:
@@ -1151,17 +1157,18 @@
 @objectmodel.specialize.arg_or_var(2)
 def mapdict_lookup(space, w_obj, name):
     if we_are_jitted():
-        map = w_obj._get_mapdict_map_no_promote()
-        if map is not None:
+        if w_obj.user_overridden_class:
+            map = w_obj._get_mapdict_map_no_promote()
             return map._type_lookup(name)
     return space._lookup(w_obj, name)
 
 
 def mapdict_type_isinstance(space, w_obj, w_type):
     if we_are_jitted():
-        map = w_obj._get_mapdict_map_no_promote()
-        if map is not None and map.version is not None:
-            version_tag = w_type.version_tag()
-            if version_tag is not None:
-                return map._type_issubtype(w_type)
+        if w_obj.user_overridden_class:
+            map = w_obj._get_mapdict_map_no_promote()
+            if map.version is not None:
+                version_tag = w_type.version_tag()
+                if version_tag is not None:
+                    return map._type_issubtype(w_type)
     return space.type(w_obj).issubtype(w_type)
diff --git a/rpython/jit/metainterp/compile.py b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -1104,7 +1104,7 @@
         for _compatibility_conditions in self.other_compat_conditions:
             if _compatibility_conditions.check_compat_and_activate(
                     cpu, ref, self.rd_loop_token):
-                return self._compatibility_conditions.jump_target
+                return _compatibility_conditions.jump_target
         return 0
 
     def compile_and_attach(self, metainterp, new_loop, orig_inputargs):
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_compatible.py b/rpython/jit/metainterp/optimizeopt/test/test_compatible.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_compatible.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_compatible.py
@@ -32,6 +32,22 @@
         """
         self.optimize_loop(ops, expected)
 
+    def test_guard_compatible_and_guard_nonnull(self):
+        ops = """
+        [p1]
+        guard_nonnull(p1, ConstClass(node_vtable)) []
+        guard_compatible(p1, ConstPtr(myptr)) []
+        guard_nonnull(p1, ConstClass(node_vtable)) []
+        jump(ConstPtr(myptr))
+        """
+        expected = """
+        [p1]
+        guard_nonnull(p1, ConstClass(node_vtable)) []
+        guard_compatible(p1, ConstPtr(myptr)) []
+        jump(ConstPtr(myptr))
+        """
+        self.optimize_loop(ops, expected)
+
     def test_guard_compatible_and_guard_class(self):
         ops = """
         [p1]
diff --git a/rpython/jit/metainterp/test/test_compatible.py b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -45,6 +45,51 @@
         # trace, two bridges, a finish bridge
         self.check_trace_count(4)
 
+    def test_simple_check_values(self):
+        S = lltype.GcStruct('S', ('x', lltype.Signed))
+        p1 = lltype.malloc(S)
+        p1.x = 5
+
+        p2 = lltype.malloc(S)
+        p2.x = 5
+
+        p3 = lltype.malloc(S)
+        p3.x = 6
+        driver = jit.JitDriver(greens = [], reds = ['n', 's', 'x'])
+
+        class A(object):
+            pass
+
+        c = A()
+        c.count = 0
+        @jit.elidable_compatible()
+        def g(s, ignored):
+            c.count += 1
+            return s.x
+
+        def f(n, x):
+            s = 0
+            while n > 0:
+                driver.can_enter_jit(n=n, x=x, s=s)
+                driver.jit_merge_point(n=n, x=x, s=s)
+                diff = g(x, "abc")
+                n -= 1
+                s += diff
+            return s
+
+        def main():
+            g(p1, "def") # make annotator not make argument constant
+            n = f(100, p1)
+            n += f(100, p2)
+            n += f(100, p3)
+            return n
+
+        x = self.meta_interp(main, [])
+
+        assert x == main()
+        # trace, two bridges, a finish bridge
+        self.check_trace_count(4)
+
     def test_exception(self):
         S = lltype.GcStruct('S', ('x', lltype.Signed))
         p1 = lltype.malloc(S)


More information about the pypy-commit mailing list