[pypy-commit] pypy kill-ootype: Remove ootype support from the annotator

rlamy noreply at buildbot.pypy.org
Sat Jul 6 16:49:31 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: kill-ootype
Changeset: r65231:eee1c17aebdf
Date: 2013-07-06 16:34 +0200
http://bitbucket.org/pypy/pypy/changeset/eee1c17aebdf/

Log:	Remove ootype support from the annotator

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -866,12 +866,8 @@
 
 # ____________________________________________________________
 # annotation of low-level types
-from rpython.annotator.model import SomePtr, SomeOOInstance, SomeOOClass
-from rpython.annotator.model import SomeOOObject
+from rpython.annotator.model import SomePtr
 from rpython.annotator.model import ll_to_annotation, annotation_to_lltype
-from rpython.rtyper.ootypesystem import ootype
-
-_make_none_union('SomeOOInstance', 'ootype=obj.ootype, can_be_None=True')
 
 class __extend__(pairtype(SomePtr, SomePtr)):
     def union((p1, p2)):
@@ -912,41 +908,6 @@
         return pair(p2, obj).union()
 
 
-class __extend__(pairtype(SomeOOInstance, SomeOOInstance)):
-    def union((r1, r2)):
-        common = ootype.commonBaseclass(r1.ootype, r2.ootype)
-        assert common is not None, 'Mixing of incompatible instances %r, %r' %(r1.ootype, r2.ootype)
-        return SomeOOInstance(common, can_be_None=r1.can_be_None or r2.can_be_None)
-
-class __extend__(pairtype(SomeOOClass, SomeOOClass)):
-    def union((r1, r2)):
-        if r1.ootype is None:
-            common = r2.ootype
-        elif r2.ootype is None:
-            common = r1.ootype
-        elif r1.ootype == r2.ootype:
-            common = r1.ootype
-        elif isinstance(r1.ootype, ootype.Instance) and isinstance(r2.ootype, ootype.Instance):
-            common = ootype.commonBaseclass(r1.ootype, r2.ootype)
-            assert common is not None, ('Mixing of incompatible classes %r, %r'
-                                        % (r1.ootype, r2.ootype))
-        else:
-            common = ootype.Object
-        return SomeOOClass(common)
-
-class __extend__(pairtype(SomeOOInstance, SomeObject)):
-    def union((r, obj)):
-        assert False, ("mixing reference type %r with something else %r" % (r.ootype, obj))
-
-class __extend__(pairtype(SomeObject, SomeOOInstance)):
-    def union((obj, r2)):
-        return pair(r2, obj).union()
-
-class __extend__(pairtype(SomeOOObject, SomeOOObject)):
-    def union((r1, r2)):
-        assert r1.ootype is ootype.Object and r2.ootype is ootype.Object
-        return SomeOOObject()
-
 #_________________________________________
 # weakrefs
 
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -7,13 +7,12 @@
 import sys, types, inspect, weakref
 
 from rpython.flowspace.model import Constant
-from rpython.annotator.model import SomeString, SomeChar, SomeFloat, \
-     SomePtr, unionof, SomeInstance, SomeDict, SomeBuiltin, SomePBC, \
-     SomeInteger, SomeOOInstance, SomeOOObject, TLS, SomeAddress, \
-     SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \
-     SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \
-     SomeUnicodeString, SomeList, HarmlesslyBlocked, \
-     SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray
+from rpython.annotator.model import (
+    SomeString, SomeChar, SomeFloat, SomePtr, unionof, SomeInstance, SomeDict,
+    SomeBuiltin, SomePBC, SomeInteger, TLS, SomeAddress, SomeUnicodeCodePoint,
+    s_None, s_ImpossibleValue, SomeLLADTMeth, SomeBool, SomeTuple,
+    SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked,
+    SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray)
 from rpython.annotator.classdef import InstanceSource, ClassDef
 from rpython.annotator.listdef import ListDef, ListItem
 from rpython.annotator.dictdef import DictDef
@@ -23,7 +22,6 @@
 from rpython.rlib.objectmodel import r_dict, Symbolic
 from rpython.tool.algo.unionfind import UnionFind
 from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.rtyper.ootypesystem import ootype
 from rpython.rtyper import extregistry
 
 
@@ -433,16 +431,6 @@
             result = SomePtr(lltype.typeOf(x))
         elif isinstance(x, llmemory.fakeaddress):
             result = SomeAddress()
-        elif isinstance(x, ootype._static_meth):
-            result = SomeOOStaticMeth(ootype.typeOf(x))
-        elif isinstance(x, ootype._class):
-            result = SomeOOClass(x._INSTANCE)   # NB. can be None
-        elif isinstance(x, ootype.instance_impl): # XXX
-            result = SomeOOInstance(ootype.typeOf(x))
-        elif isinstance(x, (ootype._record, ootype._string)):
-            result = SomeOOInstance(ootype.typeOf(x))
-        elif isinstance(x, (ootype._object)):
-            result = SomeOOObject()
         elif tp is type:
             if (x is type(None) or      # add cases here if needed
                 x.__module__ == 'rpython.rtyper.lltypesystem.lltype'):
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -3,20 +3,15 @@
 """
 import sys
 
-from rpython.annotator.model import SomeInteger, SomeObject, SomeChar, SomeBool
-from rpython.annotator.model import SomeString, SomeTuple, s_Bool
-from rpython.annotator.model import SomeUnicodeCodePoint, SomeAddress
-from rpython.annotator.model import SomeFloat, unionof, SomeUnicodeString
-from rpython.annotator.model import SomePBC, SomeInstance, SomeDict, SomeList
-from rpython.annotator.model import SomeWeakRef, SomeIterator
-from rpython.annotator.model import SomeOOObject, SomeByteArray
-from rpython.annotator.model import annotation_to_lltype, lltype_to_annotation, ll_to_annotation
-from rpython.annotator.model import add_knowntypedata
-from rpython.annotator.model import s_ImpossibleValue
+from rpython.annotator.model import (
+    SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple, s_Bool,
+    SomeUnicodeCodePoint, SomeAddress, SomeFloat, unionof, SomeUnicodeString,
+    SomePBC, SomeInstance, SomeDict, SomeList, SomeWeakRef, SomeIterator,
+    SomeByteArray, annotation_to_lltype, lltype_to_annotation,
+    ll_to_annotation, add_knowntypedata, s_ImpossibleValue,)
 from rpython.annotator.bookkeeper import getbookkeeper
 from rpython.annotator import description
 from rpython.flowspace.model import Constant
-from rpython.tool.error import AnnotatorError
 import rpython.rlib.rarithmetic
 import rpython.rlib.objectmodel
 
@@ -177,8 +172,8 @@
                 r.const = isinstance(s_obj.const, typ)
             elif our_issubclass(s_obj.knowntype, typ):
                 if not s_obj.can_be_none():
-                    r.const = True 
-            elif not our_issubclass(typ, s_obj.knowntype): 
+                    r.const = True
+            elif not our_issubclass(typ, s_obj.knowntype):
                 r.const = False
             elif s_obj.knowntype == int and typ == bool: # xxx this will explode in case of generalisation
                                                    # from bool to int, notice that isinstance( , bool|int)
@@ -207,7 +202,7 @@
         r.const = hasattr(s_obj.const, s_attr.const)
     elif (isinstance(s_obj, SomePBC)
           and s_obj.getKind() is description.FrozenDesc):
-       answers = {}    
+       answers = {}
        for d in s_obj.descriptions:
            answer = (d.s_read_attribute(s_attr.const) != s_ImpossibleValue)
            answers[answer] = True
@@ -344,7 +339,7 @@
     return SomeAddress()
 
 def unicodedata_decimal(s_uchr):
-    raise TypeError, "unicodedate.decimal() calls should not happen at interp-level"    
+    raise TypeError, "unicodedate.decimal() calls should not happen at interp-level"
 
 def test(*args):
     return s_Bool
@@ -395,7 +390,7 @@
 if hasattr(object.__init__, 'im_func'):
     BUILTIN_ANALYZERS[object.__init__.im_func] = object_init
 else:
-    BUILTIN_ANALYZERS[object.__init__] = object_init    
+    BUILTIN_ANALYZERS[object.__init__] = object_init
 
 # import
 BUILTIN_ANALYZERS[__import__] = import_func
@@ -490,7 +485,7 @@
     return SomePtr(ll_ptrtype=PtrT.const)
 
 def identityhash(s_obj):
-    assert isinstance(s_obj, (SomePtr, SomeOOObject, SomeOOInstance))
+    assert isinstance(s_obj, SomePtr)
     return SomeInteger()
 
 def getRuntimeTypeInfo(T):
@@ -523,92 +518,6 @@
 BUILTIN_ANALYZERS[lltype.runtime_type_info] = runtime_type_info
 BUILTIN_ANALYZERS[lltype.Ptr] = constPtr
 
-# ootype
-from rpython.annotator.model import SomeOOInstance, SomeOOClass, SomeOOStaticMeth
-from rpython.rtyper.ootypesystem import ootype
-
-def new(I):
-    assert I.is_constant()
-    i = ootype.new(I.const)
-    r = SomeOOInstance(ootype.typeOf(i))
-    return r
-
-def oonewarray(s_type, length):
-    assert s_type.is_constant()
-    return SomeOOInstance(s_type.const)
-
-def null(I_OR_SM):
-    assert I_OR_SM.is_constant()
-    null = ootype.null(I_OR_SM.const)
-    r = lltype_to_annotation(ootype.typeOf(null))
-    return r
-
-def instanceof(i, I):
-    assert I.is_constant()
-    assert isinstance(I.const, ootype.Instance)
-    return s_Bool
-
-def classof(i):
-    assert isinstance(i, SomeOOInstance) 
-    return SomeOOClass(i.ootype)
-
-def subclassof(class1, class2):
-    assert isinstance(class1, SomeOOClass) 
-    assert isinstance(class2, SomeOOClass) 
-    return s_Bool
-
-def runtimenew(c):
-    assert isinstance(c, SomeOOClass)
-    if c.ootype is None:
-        return s_ImpossibleValue   # can't call runtimenew(NULL)
-    else:
-        return SomeOOInstance(c.ootype)
-
-def ooupcast(I, i):
-    assert isinstance(I.const, ootype.Instance)
-    if ootype.isSubclass(i.ootype, I.const):
-        return SomeOOInstance(I.const)
-    else:
-        raise AnnotatorError, 'Cannot cast %s to %s' % (i.ootype, I.const)
-
-def oodowncast(I, i):
-    assert isinstance(I.const, ootype.Instance)
-    if ootype.isSubclass(I.const, i.ootype):
-        return SomeOOInstance(I.const)
-    else:
-        raise AnnotatorError, 'Cannot cast %s to %s' % (i.ootype, I.const)
-
-def cast_to_object(obj):
-    assert isinstance(obj, SomeOOStaticMeth) or \
-           (isinstance(obj, SomeOOClass) and obj.ootype is None) or \
-           isinstance(obj.ootype, ootype.OOType)
-    return SomeOOObject()
-
-def cast_from_object(T, obj):
-    TYPE = T.const
-    if TYPE is ootype.Object:
-        return SomeOOObject()
-    elif TYPE is ootype.Class:
-        return SomeOOClass(ootype.ROOT) # ???
-    elif isinstance(TYPE, ootype.StaticMethod):
-        return SomeOOStaticMeth(TYPE)
-    elif isinstance(TYPE, ootype.OOType):
-        return SomeOOInstance(TYPE)
-    else:
-        raise AnnotatorError, 'Cannot cast Object to %s' % TYPE
-
-BUILTIN_ANALYZERS[ootype.instanceof] = instanceof
-BUILTIN_ANALYZERS[ootype.new] = new
-BUILTIN_ANALYZERS[ootype.oonewarray] = oonewarray
-BUILTIN_ANALYZERS[ootype.null] = null
-BUILTIN_ANALYZERS[ootype.runtimenew] = runtimenew
-BUILTIN_ANALYZERS[ootype.classof] = classof
-BUILTIN_ANALYZERS[ootype.subclassof] = subclassof
-BUILTIN_ANALYZERS[ootype.ooupcast] = ooupcast
-BUILTIN_ANALYZERS[ootype.oodowncast] = oodowncast
-BUILTIN_ANALYZERS[ootype.cast_to_object] = cast_to_object
-BUILTIN_ANALYZERS[ootype.cast_from_object] = cast_from_object
-
 #________________________________
 # weakrefs
 
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -603,36 +603,6 @@
         return False
 
 
-class SomeOOObject(SomeObject):
-    def __init__(self):
-        from rpython.rtyper.ootypesystem import ootype
-        self.ootype = ootype.Object
-
-
-class SomeOOClass(SomeObject):
-    def __init__(self, ootype):
-        self.ootype = ootype
-
-
-class SomeOOInstance(SomeObject):
-    def __init__(self, ootype, can_be_None=False):
-        self.ootype = ootype
-        self.can_be_None = can_be_None
-
-
-class SomeOOBoundMeth(SomeObject):
-    immutable = True
-
-    def __init__(self, ootype, name):
-        self.ootype = ootype
-        self.name = name
-
-
-class SomeOOStaticMeth(SomeObject):
-    immutable = True
-
-    def __init__(self, method):
-        self.method = method
 
 annotation_to_ll_map = [
     (SomeSingleFloat(), lltype.SingleFloat),
@@ -647,16 +617,6 @@
 
 
 def annotation_to_lltype(s_val, info=None):
-    from rpython.rtyper.ootypesystem import ootype
-
-    if isinstance(s_val, SomeOOInstance):
-        return s_val.ootype
-    if isinstance(s_val, SomeOOStaticMeth):
-        return s_val.method
-    if isinstance(s_val, SomeOOClass):
-        return ootype.Class
-    if isinstance(s_val, SomeOOObject):
-        return s_val.ootype
     if isinstance(s_val, SomeInteriorPtr):
         p = s_val.ll_ptrtype
         if 0 in p.offsets:
@@ -683,8 +643,6 @@
 
 
 def lltype_to_annotation(T):
-    from rpython.rtyper.ootypesystem import ootype
-
     try:
         s = ll_to_annotation_map.get(T)
     except TypeError:
@@ -694,14 +652,6 @@
             return lltype_to_annotation(T.OF)
         if isinstance(T, lltype.Number):
             return SomeInteger(knowntype=T._type)
-        if isinstance(T, (ootype.Instance, ootype.BuiltinType)):
-            return SomeOOInstance(T)
-        elif isinstance(T, ootype.StaticMethod):
-            return SomeOOStaticMeth(T)
-        elif T == ootype.Class:
-            return SomeOOClass(ootype.ROOT)
-        elif T == ootype.Object:
-            return SomeOOObject()
         elif isinstance(T, lltype.InteriorPtr):
             return SomeInteriorPtr(T)
         else:
diff --git a/rpython/annotator/test/test_model.py b/rpython/annotator/test/test_model.py
--- a/rpython/annotator/test/test_model.py
+++ b/rpython/annotator/test/test_model.py
@@ -2,7 +2,6 @@
 
 from rpython.annotator.model import *
 from rpython.annotator.listdef import ListDef
-from rpython.rtyper.ootypesystem import ootype
 
 
 listdef1 = ListDef(None, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
@@ -57,11 +56,11 @@
                                                      (s6, s6)])
 
 def test_commonbase_simple():
-    class A0: 
+    class A0:
         pass
-    class A1(A0): 
+    class A1(A0):
         pass
-    class A2(A0): 
+    class A2(A0):
         pass
     class B1(object):
         pass
@@ -73,10 +72,10 @@
     except TypeError:    # if A0 is also a new-style class, e.g. in PyPy
         class B3(A0, object):
             pass
-    assert commonbase(A1,A2) is A0 
+    assert commonbase(A1,A2) is A0
     assert commonbase(A1,A0) is A0
     assert commonbase(A1,A1) is A1
-    assert commonbase(A2,B2) is object 
+    assert commonbase(A2,B2) is object
     assert commonbase(A2,B3) is A0
 
 def test_list_union():
@@ -115,9 +114,6 @@
     assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(S)
     s_p = ll_to_annotation(lltype.malloc(A, 0))
     assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(A)
-    C = ootype.Instance('C', ootype.ROOT, {})
-    s_p = ll_to_annotation(ootype.new(C))
-    assert isinstance(s_p, SomeOOInstance) and s_p.ootype == C
 
 def test_annotation_to_lltype():
     from rpython.rlib.rarithmetic import r_uint, r_singlefloat
@@ -125,8 +121,8 @@
     s_pos = SomeInteger(nonneg=True)
     s_1 = SomeInteger(nonneg=True); s_1.const = 1
     s_m1 = SomeInteger(nonneg=False); s_m1.const = -1
-    s_u = SomeInteger(nonneg=True, unsigned=True); 
-    s_u1 = SomeInteger(nonneg=True, unsigned=True); 
+    s_u = SomeInteger(nonneg=True, unsigned=True);
+    s_u1 = SomeInteger(nonneg=True, unsigned=True);
     s_u1.const = r_uint(1)
     assert annotation_to_lltype(s_i) == lltype.Signed
     assert annotation_to_lltype(s_pos) == lltype.Signed
@@ -140,13 +136,10 @@
     s_p = SomePtr(ll_ptrtype=PS)
     assert annotation_to_lltype(s_p) == PS
     py.test.raises(ValueError, "annotation_to_lltype(si0)")
-    C = ootype.Instance('C', ootype.ROOT, {})
-    ref = SomeOOInstance(C)
-    assert annotation_to_lltype(ref) == C
     s_singlefloat = SomeSingleFloat()
     s_singlefloat.const = r_singlefloat(0.0)
     assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
-    
+
 def test_ll_union():
     PS1 = lltype.Ptr(lltype.GcStruct('s'))
     PS2 = lltype.Ptr(lltype.GcStruct('s'))
@@ -172,29 +165,6 @@
     py.test.raises(AssertionError, "unionof(SomeInteger(), SomePtr(PS1))")
     py.test.raises(AssertionError, "unionof(SomeObject(), SomePtr(PS1))")
 
-def test_oo_union():
-    C1 = ootype.Instance("C1", ootype.ROOT)
-    C2 = ootype.Instance("C2", C1)
-    C3 = ootype.Instance("C3", C1)
-    D = ootype.Instance("D", ootype.ROOT)
-    assert unionof(SomeOOInstance(C1), SomeOOInstance(C1)) == SomeOOInstance(C1)
-    assert unionof(SomeOOInstance(C1), SomeOOInstance(C2)) == SomeOOInstance(C1)
-    assert unionof(SomeOOInstance(C2), SomeOOInstance(C1)) == SomeOOInstance(C1)
-    assert unionof(SomeOOInstance(C2), SomeOOInstance(C3)) == SomeOOInstance(C1)
-
-    assert unionof(SomeOOInstance(C1),SomeImpossibleValue()) == SomeOOInstance(C1)
-    assert unionof(SomeImpossibleValue(), SomeOOInstance(C1)) == SomeOOInstance(C1)
-
-    assert unionof(SomeOOInstance(C1), SomeOOInstance(D)) == SomeOOInstance(ootype.ROOT)
-
-def test_ooclass_array_contains():
-    A = ootype.Array(ootype.Signed)
-    cls = ootype.runtimeClass(A)
-    s1 = SomeOOClass(A)
-    s2 = SomeOOClass(A)
-    s2.const=cls
-    assert s1.contains(s2)
-
 def test_nan():
     f1 = SomeFloat()
     f1.const = float("nan")
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -758,7 +758,6 @@
 
 # annotation of low-level types
 from rpython.annotator.model import SomePtr, SomeLLADTMeth
-from rpython.annotator.model import SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth
 from rpython.annotator.model import ll_to_annotation, lltype_to_annotation, annotation_to_lltype
 
 class __extend__(SomePtr):
@@ -813,56 +812,6 @@
         s_func = bookkeeper.immutablevalue(adtmeth.func)
         return s_func.call(args.prepend(lltype_to_annotation(adtmeth.ll_ptrtype)))
 
-from rpython.rtyper.ootypesystem import ootype
-class __extend__(SomeOOInstance):
-    def getattr(r, s_attr):
-        assert s_attr.is_constant(), "getattr on ref %r with non-constant field-name" % r.ootype
-        v = getattr(r.ootype._example(), s_attr.const)
-        if isinstance(v, ootype._bound_meth):
-            return SomeOOBoundMeth(r.ootype, s_attr.const)
-        return ll_to_annotation(v)
-
-    def setattr(r, s_attr, s_value):
-        assert s_attr.is_constant(), "setattr on ref %r with non-constant field-name" % r.ootype
-        v = annotation_to_lltype(s_value)
-        example = r.ootype._example()
-        if example is not None:
-            setattr(r.ootype._example(), s_attr.const, v._example())
-
-    def is_true(p):
-        return s_Bool
-
-class __extend__(SomeOOBoundMeth):
-    def simple_call(m, *args_s):
-        _, meth = m.ootype._lookup(m.name)
-        if isinstance(meth, ootype._overloaded_meth):
-            return meth._resolver.annotate(args_s)
-        else:
-            METH = ootype.typeOf(meth)
-            return lltype_to_annotation(METH.RESULT)
-
-    def call(m, args):
-        args_s, kwds_s = args.unpack()
-        if kwds_s:
-            raise Exception("keyword arguments to call to a low-level bound method")
-        inst = m.ootype._example()
-        _, meth = ootype.typeOf(inst)._lookup(m.name)
-        METH = ootype.typeOf(meth)
-        return lltype_to_annotation(METH.RESULT)
-
-
-class __extend__(SomeOOStaticMeth):
-
-    def call(m, args):
-        args_s, kwds_s = args.unpack()
-        if kwds_s:
-            raise Exception("keyword arguments to call to a low-level static method")
-        info = 'argument to ll static method call'
-        llargs = [annotation_to_lltype(s_arg, info)._defl() for s_arg in args_s]
-        v = m.method._example()(*llargs)
-        return ll_to_annotation(v)
-
-
 #_________________________________________
 # weakrefs
 


More information about the pypy-commit mailing list