Author: Ronan Lamy <ronan.l...@gmail.com> Branch: desc-specialize Changeset: r82482:fd243b77d69b Date: 2016-02-21 15:00 +0100 http://bitbucket.org/pypy/pypy/changeset/fd243b77d69b/
Log: Use @specialize decorators instead of direct assignments to ._annspecialcase_ diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -356,12 +356,12 @@ class BufferInterfaceNotFound(Exception): pass +@specialize.memo() def wrappable_class_name(Class): try: return Class.typedef.name except AttributeError: return 'internal subclass of %s' % (Class.__name__,) -wrappable_class_name._annspecialcase_ = 'specialize:memo' class CannotHaveLock(Exception): """Raised by space.allocate_lock() if we're translating.""" @@ -391,7 +391,7 @@ self.check_signal_action = None # changed by the signal module self.user_del_action = UserDelAction(self) self._code_of_sys_exc_info = None - + # can be overridden to a subclass self.initialize() @@ -808,12 +808,13 @@ assert type(s) is str return self.interned_strings.get(s) is not None + @specialize.arg(1) def descr_self_interp_w(self, RequiredClass, w_obj): if not isinstance(w_obj, RequiredClass): raise DescrMismatch() return w_obj - descr_self_interp_w._annspecialcase_ = 'specialize:arg(1)' + @specialize.arg(1) def interp_w(self, RequiredClass, w_obj, can_be_None=False): """ Unwrap w_obj, checking that it is an instance of the required internal @@ -828,7 +829,6 @@ wrappable_class_name(RequiredClass), w_obj.getclass(self)) return w_obj - interp_w._annspecialcase_ = 'specialize:arg(1)' def unpackiterable(self, w_iterable, expected_length=-1): """Unpack an iterable into a real (interpreter-level) list. @@ -1245,6 +1245,7 @@ self.setitem(w_globals, w_key, self.wrap(self.builtin)) return statement.exec_code(self, w_globals, w_locals) + @specialize.arg(2) def appexec(self, posargs_w, source): """ return value from executing given source at applevel. EXPERIMENTAL. The source must look like @@ -1256,7 +1257,6 @@ w_func = self.fromcache(AppExecCache).getorbuild(source) args = Arguments(self, list(posargs_w)) return self.call_args(w_func, args) - appexec._annspecialcase_ = 'specialize:arg(2)' def _next_or_none(self, w_it): try: @@ -1266,6 +1266,7 @@ raise return None + @specialize.arg(3) def compare_by_iteration(self, w_iterable1, w_iterable2, op): w_it1 = self.iter(w_iterable1) w_it2 = self.iter(w_iterable2) @@ -1288,7 +1289,6 @@ if op == 'gt': return self.gt(w_x1, w_x2) if op == 'ge': return self.ge(w_x1, w_x2) assert False, "bad value for op" - compare_by_iteration._annspecialcase_ = 'specialize:arg(3)' def decode_index(self, w_index_or_slice, seqlength): """Helper for custom sequence implementations diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -446,6 +446,7 @@ space.wrap(msg)) return OperationError(exc, w_error) +@specialize.arg(3) def wrap_oserror2(space, e, w_filename=None, exception_name='w_OSError', w_exception_class=None): assert isinstance(e, OSError) @@ -473,8 +474,8 @@ w_error = space.call_function(exc, space.wrap(errno), space.wrap(msg)) return OperationError(exc, w_error) -wrap_oserror2._annspecialcase_ = 'specialize:arg(3)' +@specialize.arg(3) def wrap_oserror(space, e, filename=None, exception_name='w_OSError', w_exception_class=None): if filename is not None: @@ -485,7 +486,6 @@ return wrap_oserror2(space, e, None, exception_name=exception_name, w_exception_class=w_exception_class) -wrap_oserror._annspecialcase_ = 'specialize:arg(3)' def exception_from_saved_errno(space, w_type): from rpython.rlib.rposix import get_saved_errno diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -138,6 +138,7 @@ # / \ # 5 6 +@specialize.memo() def get_unique_interplevel_subclass(config, cls, hasdict, wants_slots, needsdel=False, weakrefable=False): "NOT_RPYTHON: initialization-time only" @@ -153,7 +154,6 @@ assert key not in _subclass_cache _subclass_cache[key] = subcls return subcls -get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo" _subclass_cache = {} def enum_interplevel_subclasses(config, cls): diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -1,4 +1,5 @@ import sys +from rpython.rlib.objectmodel import specialize from pypy.interpreter import gateway from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.typedef import TypeDef, make_weakref_descr @@ -320,12 +321,12 @@ w_currently_in_repr = ec._py_repr = space.newdict() return dequerepr(space, w_currently_in_repr, space.wrap(self)) + @specialize.arg(2) def compare(self, w_other, op): space = self.space if not isinstance(w_other, W_Deque): return space.w_NotImplemented return space.compare_by_iteration(space.wrap(self), w_other, op) - compare._annspecialcase_ = 'specialize:arg(2)' def lt(self, w_other): return self.compare(w_other, 'lt') diff --git a/pypy/module/_pypyjson/targetjson.py b/pypy/module/_pypyjson/targetjson.py --- a/pypy/module/_pypyjson/targetjson.py +++ b/pypy/module/_pypyjson/targetjson.py @@ -4,6 +4,7 @@ sys.path.insert(0, str(ROOT)) import time +from rpython.rlib.objectmodel import specialize from pypy.interpreter.error import OperationError from pypy.module._pypyjson.interp_decoder import loads @@ -91,6 +92,7 @@ def wrapfloat(self, x): return W_Float(x) + @specialize.argtype(1) def wrap(self, x): if isinstance(x, int): return W_Int(x) @@ -100,7 +102,6 @@ ## assert False else: return W_Unicode(unicode(x)) - wrap._annspecialcase_ = "specialize:argtype(1)" fakespace = FakeSpace() diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -8,6 +8,7 @@ from rpython.rtyper.tool import rffi_platform from rpython.rlib.unroll import unrolling_iterable import rpython.rlib.rposix as rposix +from rpython.rlib.objectmodel import specialize _MS_WINDOWS = os.name == "nt" @@ -251,6 +252,7 @@ _ARM = rffi_platform.getdefined('__arm__', '') +@specialize.arg(2) def read_ptr(ptr, ofs, TP): T = lltype.Ptr(rffi.CArray(TP)) for c in unroll_letters_for_floats: @@ -270,8 +272,8 @@ return ptr_val else: return rffi.cast(T, ptr)[ofs] -read_ptr._annspecialcase_ = 'specialize:arg(2)' +@specialize.argtype(2) def write_ptr(ptr, ofs, value): TP = lltype.typeOf(value) T = lltype.Ptr(rffi.CArray(TP)) @@ -292,7 +294,6 @@ return else: rffi.cast(T, ptr)[ofs] = value -write_ptr._annspecialcase_ = 'specialize:argtype(2)' def segfault_exception(space, reason): w_mod = space.getbuiltinmodule("_rawffi") @@ -365,14 +366,15 @@ def getrawsize(self): raise NotImplementedError("abstract base class") +@specialize.arg(0) def unwrap_truncate_int(TP, space, w_arg): if space.isinstance_w(w_arg, space.w_int): return rffi.cast(TP, space.int_w(w_arg)) else: return rffi.cast(TP, space.bigint_w(w_arg).ulonglongmask()) -unwrap_truncate_int._annspecialcase_ = 'specialize:arg(0)' +@specialize.arg(1) def unwrap_value(space, push_func, add_arg, argdesc, letter, w_arg): w = space.wrap if letter in TYPEMAP_PTR_LETTERS: @@ -414,10 +416,10 @@ else: raise OperationError(space.w_TypeError, space.wrap("cannot directly write value")) -unwrap_value._annspecialcase_ = 'specialize:arg(1)' ll_typemap_iter = unrolling_iterable(LL_TYPEMAP.items()) +@specialize.arg(1) def wrap_value(space, func, add_arg, argdesc, letter): for c, ll_type in ll_typemap_iter: if letter == c: @@ -430,7 +432,6 @@ return space.wrap(func(add_arg, argdesc, ll_type)) raise OperationError(space.w_TypeError, space.wrap("cannot directly read value")) -wrap_value._annspecialcase_ = 'specialize:arg(1)' class W_FuncPtr(W_Root): diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py --- a/pypy/module/_rawffi/structure.py +++ b/pypy/module/_rawffi/structure.py @@ -18,6 +18,7 @@ from rpython.rlib.rarithmetic import intmask, signedtype, r_uint, \ r_ulonglong from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rlib.objectmodel import specialize @@ -269,6 +270,7 @@ def NUM_BITS(x): return x >> 16 +@specialize.arg(1) def BIT_MASK(x, ll_t): if ll_t is lltype.SignedLongLong or ll_t is lltype.UnsignedLongLong: one = r_ulonglong(1) @@ -276,8 +278,8 @@ one = r_uint(1) # to avoid left shift by x == sizeof(ll_t) return (((one << (x - 1)) - 1) << 1) + 1 -BIT_MASK._annspecialcase_ = 'specialize:arg(1)' +@specialize.argtype(2) def push_field(self, num, value): ptr = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[num]) TP = lltype.typeOf(value) @@ -298,8 +300,8 @@ value = rffi.cast(TP, current) break write_ptr(ptr, 0, value) -push_field._annspecialcase_ = 'specialize:argtype(2)' +@specialize.arg(2) def cast_pos(self, i, ll_t): pos = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[i]) value = read_ptr(pos, 0, ll_t) @@ -322,7 +324,6 @@ value = rffi.cast(ll_t, value) break return value -cast_pos._annspecialcase_ = 'specialize:arg(2)' class W_StructureInstance(W_DataInstance): def __init__(self, space, shape, address): diff --git a/pypy/module/cppyy/test/test_zjit.py b/pypy/module/cppyy/test/test_zjit.py --- a/pypy/module/cppyy/test/test_zjit.py +++ b/pypy/module/cppyy/test/test_zjit.py @@ -124,13 +124,13 @@ assert isinstance(w_obj, FakeFloat) return w_obj.val + @specialize.arg(1) def interp_w(self, RequiredClass, w_obj, can_be_None=False): if can_be_None and w_obj is None: return None if not isinstance(w_obj, RequiredClass): raise TypeError return w_obj - interp_w._annspecialcase_ = 'specialize:arg(1)' def getarg_w(self, code, w_obj): # for retrieving buffers return FakeBuffer(w_obj) diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -1107,7 +1107,7 @@ if not use_micronumpy: return use_micronumpy # import to register api functions by side-effect - import pypy.module.cpyext.ndarrayobject + import pypy.module.cpyext.ndarrayobject global GLOBALS, SYMBOLS_C, separate_module_files GLOBALS["PyArray_Type#"]= ('PyTypeObject*', "space.gettypeobject(W_NDimArray.typedef)") SYMBOLS_C += ['PyArray_Type', '_PyArray_FILLWBYTE', '_PyArray_ZEROS'] @@ -1295,9 +1295,8 @@ miniglobals = {'__name__': __name__, # for module name propagation } exec source.compile() in miniglobals - call_external_function = miniglobals['cpy_call_external'] + call_external_function = specialize.ll(miniglobals['cpy_call_external']) call_external_function._dont_inline_ = True - call_external_function._annspecialcase_ = 'specialize:ll' call_external_function._gctransformer_hint_close_stack_ = True # don't inline, as a hack to guarantee that no GC pointer is alive # anywhere in call_external_function diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py --- a/pypy/module/math/interp_math.py +++ b/pypy/module/math/interp_math.py @@ -2,6 +2,7 @@ import sys from rpython.rlib import rfloat +from rpython.rlib.objectmodel import specialize from pypy.interpreter.error import OperationError class State: @@ -17,6 +18,7 @@ else: return space.float_w(space.float(w_x)) +@specialize.arg(1) def math1(space, f, w_x): x = _get_double(space, w_x) try: @@ -28,8 +30,8 @@ raise OperationError(space.w_ValueError, space.wrap("math domain error")) return space.wrap(y) -math1._annspecialcase_ = 'specialize:arg(1)' +@specialize.arg(1) def math1_w(space, f, w_x): x = _get_double(space, w_x) try: @@ -41,8 +43,8 @@ raise OperationError(space.w_ValueError, space.wrap("math domain error")) return r -math1_w._annspecialcase_ = 'specialize:arg(1)' +@specialize.arg(1) def math2(space, f, w_x, w_snd): x = _get_double(space, w_x) snd = _get_double(space, w_snd) @@ -55,7 +57,6 @@ raise OperationError(space.w_ValueError, space.wrap("math domain error")) return space.wrap(r) -math2._annspecialcase_ = 'specialize:arg(1)' def trunc(space, w_x): """Truncate x.""" diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py --- a/pypy/module/pyexpat/interp_pyexpat.py +++ b/pypy/module/pyexpat/interp_pyexpat.py @@ -3,6 +3,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault from pypy.interpreter.error import OperationError, oefmt from rpython.rlib import rgc, jit +from rpython.rlib.objectmodel import specialize from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rtyper.tool import rffi_platform from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -565,6 +566,7 @@ return self.w_character_data_handler or space.w_None return self.handlers[index] + @specialize.arg(2) def sethandler(self, space, name, w_handler, index, setter, handler): if name == 'CharacterDataHandler': self.flush_character_buffer(space) @@ -576,8 +578,6 @@ self.handlers[index] = w_handler setter(self.itself, handler) - sethandler._annspecialcase_ = 'specialize:arg(2)' - all_chars = ''.join(chr(i) for i in range(256)) def UnknownEncodingHandler(self, space, name, info): diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -9,54 +9,54 @@ from rpython.rlib.objectmodel import specialize from rpython.rlib import jit +@specialize.memo() def object_getattribute(space): "Utility that returns the app-level descriptor object.__getattribute__." w_src, w_getattribute = space.lookup_in_type_where(space.w_object, '__getattribute__') return w_getattribute -object_getattribute._annspecialcase_ = 'specialize:memo' +@specialize.memo() def object_setattr(space): "Utility that returns the app-level descriptor object.__setattr__." w_src, w_setattr = space.lookup_in_type_where(space.w_object, '__setattr__') return w_setattr -object_setattr._annspecialcase_ = 'specialize:memo' +@specialize.memo() def object_delattr(space): "Utility that returns the app-level descriptor object.__delattr__." w_src, w_delattr = space.lookup_in_type_where(space.w_object, '__delattr__') return w_delattr -object_delattr._annspecialcase_ = 'specialize:memo' +@specialize.memo() def object_hash(space): "Utility that returns the app-level descriptor object.__hash__." w_src, w_hash = space.lookup_in_type_where(space.w_object, '__hash__') return w_hash -object_hash._annspecialcase_ = 'specialize:memo' +@specialize.memo() def type_eq(space): "Utility that returns the app-level descriptor type.__eq__." w_src, w_eq = space.lookup_in_type_where(space.w_type, '__eq__') return w_eq -type_eq._annspecialcase_ = 'specialize:memo' +@specialize.memo() def list_iter(space): "Utility that returns the app-level descriptor list.__iter__." w_src, w_iter = space.lookup_in_type_where(space.w_list, '__iter__') return w_iter -list_iter._annspecialcase_ = 'specialize:memo' +@specialize.memo() def tuple_iter(space): "Utility that returns the app-level descriptor tuple.__iter__." w_src, w_iter = space.lookup_in_type_where(space.w_tuple, '__iter__') return w_iter -tuple_iter._annspecialcase_ = 'specialize:memo' def raiseattrerror(space, w_obj, name, w_descr=None): if w_descr is None: diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -195,6 +195,7 @@ def wrapbytes(self, x): return w_some_obj() + @specialize.argtype(1) def wrap(self, x): if not we_are_translated(): if isinstance(x, gateway.interp2app): @@ -208,7 +209,6 @@ return w_some_obj() self._wrap_not_rpython(x) return w_some_obj() - wrap._annspecialcase_ = "specialize:argtype(1)" def _wrap_not_rpython(self, x): "NOT_RPYTHON" @@ -293,10 +293,10 @@ is_root(w_complex) return 1.1, 2.2 + @specialize.arg(1) def allocate_instance(self, cls, w_subtype): is_root(w_subtype) return instantiate(cls) - allocate_instance._annspecialcase_ = "specialize:arg(1)" def decode_index(self, w_index_or_slice, seqlength): is_root(w_index_or_slice) diff --git a/pypy/objspace/fake/test/test_checkmodule.py b/pypy/objspace/fake/test/test_checkmodule.py --- a/pypy/objspace/fake/test/test_checkmodule.py +++ b/pypy/objspace/fake/test/test_checkmodule.py @@ -9,9 +9,9 @@ def make_checker(): check = [] + @specialize.memo() def see(): check.append(True) - see._annspecialcase_ = 'specialize:memo' return see, check def test_wrap_interp2app(): diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -2,6 +2,7 @@ import sys from rpython.rlib import jit +from rpython.rlib.objectmodel import specialize from rpython.rlib.rarithmetic import INT_MAX from rpython.rlib.rfloat import DTSF_ALT, formatd, isnan, isinf from rpython.rlib.rstring import StringBuilder, UnicodeBuilder @@ -351,6 +352,7 @@ s, ord(c), self.fmtpos - 1) raise OperationError(space.w_ValueError, space.wrap(msg)) + @specialize.argtype(1) def std_wp(self, r): length = len(r) if do_unicode and isinstance(r, str): @@ -376,7 +378,6 @@ if padding > 0: result.append_multiple_char(const(' '), padding) # add any remaining padding at the right - std_wp._annspecialcase_ = 'specialize:argtype(1)' def std_wp_number(self, r, prefix=''): result = self.result 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 @@ -2,6 +2,7 @@ from rpython.rlib import jit, objectmodel, debug, rerased from rpython.rlib.rarithmetic import intmask, r_uint +from rpython.rlib.objectmodel import specialize from pypy.interpreter.baseobjspace import W_Root from pypy.objspace.std.dictmultiobject import ( @@ -507,6 +508,7 @@ class Object(ObjectMixin, BaseMapdictObject, W_Root): pass # mainly for tests +@specialize.arg(1) def get_subclass_of_correct_size(space, cls, w_type): assert space.config.objspace.std.withmapdict map = w_type.terminator @@ -519,11 +521,11 @@ return classes[size] else: return classes[len(classes)-1] -get_subclass_of_correct_size._annspecialcase_ = "specialize:arg(1)" SUBCLASSES_MIN_FIELDS = 5 # XXX tweak these numbers SUBCLASSES_MAX_FIELDS = 5 +@specialize.memo() def memo_get_subclass_of_correct_size(space, supercls): key = space, supercls try: @@ -539,7 +541,6 @@ assert len(set(result)) == 1 _subclass_cache[key] = result return result -memo_get_subclass_of_correct_size._annspecialcase_ = "specialize:memo" _subclass_cache = {} erase_item, unerase_item = rerased.new_erasing_pair("mapdict storage item") 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 @@ -340,6 +340,7 @@ assert isinstance(w_starttype, W_TypeObject) return w_type.lookup_starting_at(w_starttype, name) + @specialize.arg(1) def allocate_instance(self, cls, w_subtype): """Allocate the memory needed for an instance of an internal or user-defined type, without actually __init__ializing the instance.""" @@ -369,7 +370,6 @@ "%N.__new__(%N): only for the type %N", w_type, w_subtype, w_type) return instance - allocate_instance._annspecialcase_ = "specialize:arg(1)" # two following functions are almost identical, but in fact they # have different return type. First one is a resizable list, second _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit