Author: Ronan Lamy <[email protected]>
Branch: no-class-specialize
Changeset: r80166:14ab1bb7584d
Date: 2015-10-13 16:54 +0100
http://bitbucket.org/pypy/pypy/changeset/14ab1bb7584d/
Log: Remove class specialisation
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -417,8 +417,7 @@
_detect_invalid_attrs = None
def __init__(self, bookkeeper, cls,
- name=None, basedesc=None, classdict=None,
- specialize=None):
+ name=None, basedesc=None, classdict=None):
super(ClassDesc, self).__init__(bookkeeper, cls)
if '__NOT_RPYTHON__' in cls.__dict__:
raise AnnotatorError('Bad class')
@@ -430,9 +429,10 @@
if classdict is None:
classdict = {} # populated below
self.classdict = classdict # {attr: Constant-or-Desc}
- if specialize is None:
- specialize = cls.__dict__.get('_annspecialcase_', '')
- self.specialize = specialize
+ if cls.__dict__.get('_annspecialcase_', ''):
+ raise AnnotatorError(
+ "Class specialization has been removed. The "
+ "'_annspecialcase_' class tag is now unsupported.")
self._classdefs = {}
if is_mixin(cls):
@@ -516,16 +516,6 @@
# for debugging
if not hasattr(value, 'class_'):
value.class_ = self.pyobj
- if self.specialize:
- # make a custom funcdesc that specializes on its first
- # argument (i.e. 'self').
- from rpython.annotator.specialize import specialize_argtype
- def argtype0(funcdesc, args_s):
- return specialize_argtype(funcdesc, args_s, 0)
- funcdesc = FunctionDesc(self.bookkeeper, value,
- specializer=argtype0)
- self.classdict[name] = funcdesc
- return
if mixin:
# make a new copy of the FunctionDesc for this class,
# but don't specialize further for all subclasses
@@ -618,26 +608,11 @@
return classdef
def getuniqueclassdef(self):
- if self.specialize:
- raise Exception("not supported on class %r because it needs "
- "specialization" % (self.name,))
return self.getclassdef(None)
def pycall(self, whence, args, s_previous_result, op=None):
from rpython.annotator.model import SomeInstance, SomeImpossibleValue
- if self.specialize:
- if self.specialize == 'specialize:ctr_location':
- # We use the SomeInstance annotation returned the last time
- # to make sure we use the same ClassDef this time.
- if isinstance(s_previous_result, SomeInstance):
- classdef = s_previous_result.classdef
- else:
- classdef = self.getclassdef(object())
- else:
- raise Exception("unsupported specialization tag: %r" % (
- self.specialize,))
- else:
- classdef = self.getuniqueclassdef()
+ classdef = self.getuniqueclassdef()
s_instance = SomeInstance(classdef)
# look up __init__ directly on the class, bypassing the normal
# lookup mechanisms ClassDef (to avoid influencing Attribute placement)
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -758,19 +758,6 @@
s = a.build_types(snippet.call_star_args_multiple, [int])
assert s.knowntype == int
- def test_class_spec(self):
- a = self.RPythonAnnotator(policy=AnnotatorPolicy())
- s = a.build_types(snippet.class_spec, [])
- assert s.items[0].knowntype == int
- assert s.items[1].knowntype == str
-
- def test_class_spec_confused(self):
- x = snippet.PolyStk()
- def f():
- return x
- a = self.RPythonAnnotator(policy=AnnotatorPolicy())
- py.test.raises(Exception, a.build_types, f, [])
-
def test_exception_deduction_with_raise1(self):
a = self.RPythonAnnotator()
s = a.build_types(snippet.exception_deduction_with_raise1, [bool])
@@ -3298,8 +3285,8 @@
b.x = str(n)
return len(b.x) + a.x
a = self.RPythonAnnotator()
- s = a.build_types(f, [int])
- assert isinstance(s, annmodel.SomeInteger)
+ with py.test.raises(annmodel.AnnotatorError):
+ s = a.build_types(f, [int])
def test_weakref(self):
import weakref
diff --git a/rpython/translator/test/snippet.py
b/rpython/translator/test/snippet.py
--- a/rpython/translator/test/snippet.py
+++ b/rpython/translator/test/snippet.py
@@ -1035,33 +1035,6 @@
raise Exception
-# class specialization
-
-class PolyStk:
- _annspecialcase_ = "specialize:ctr_location"
-
- def __init__(self):
- self.itms = []
-
- def push(self, v):
- self.itms.append(v)
-
- def top(self):
- return self.itms[-1]
-
-
-def class_spec():
- istk = PolyStk()
- istk.push(1)
- sstk = PolyStk()
- sstk.push("a")
- istk.push(2)
- sstk.push("b")
- #if not isinstance(istk, PolyStk):
- # return "confused"
- return istk.top(), sstk.top()
-
-
from rpython.rlib.rarithmetic import ovfcheck
def add_func(i=numtype):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit