[pypy-commit] pypy guard-compatible: add elidable_compatible version of isinstance checks

cfbolz pypy.commits at gmail.com
Wed Mar 30 03:38:01 EDT 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: guard-compatible
Changeset: r83431:743ac8d23501
Date: 2016-03-30 09:29 +0200
http://bitbucket.org/pypy/pypy/changeset/743ac8d23501/

Log:	add elidable_compatible version of isinstance checks

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -521,10 +521,12 @@
         return space.get_and_call_function(w_check, w_type, w_sub)
 
     def isinstance_allow_override(space, w_inst, w_type):
-        if space.type(w_inst) is w_type:
+        if not jit.we_are_jitted() and space.type(w_inst) is w_type:
             return space.w_True # fast path copied from cpython
         w_check = space.lookup(w_type, "__instancecheck__")
         if w_check is not None:
+            if space.type(w_inst) is w_type:
+                return space.w_True # fast path copied from cpython
             return space.get_and_call_function(w_check, w_type, w_inst)
         else:
             return space.isinstance(w_inst, w_type)
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
@@ -345,6 +345,11 @@
             name, w_type.version_tag())[1]
         return w_res
 
+    @jit.elidable_compatible(quasi_immut_field_name_for_second_arg="version")
+    def _type_issubtype(self, version, w_type):
+        from pypy.objspace.std.typeobject import _issubtype
+        return _issubtype(self.terminator.w_cls, w_type)
+
 
 class Terminator(AbstractAttribute):
     _immutable_fields_ = ['w_cls']
@@ -1150,3 +1155,12 @@
             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()
+        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)
+    return space.type(w_obj).issubtype(w_type)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -651,6 +651,9 @@
                 assert w_inst is not None
                 if isinstance(w_inst, cls):
                     return True
+        if self.config.objspace.std.withmapdict:
+            from pypy.objspace.std.mapdict import mapdict_type_isinstance
+            return mapdict_type_isinstance(self, w_inst, w_type)
         return self.type(w_inst).issubtype(w_type)
 
     @specialize.memo()


More information about the pypy-commit mailing list