Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r87383:5960b6ead8d1 Date: 2016-09-22 08:05 +0200 http://bitbucket.org/pypy/pypy/changeset/5960b6ead8d1/
Log: replace some _annspecialcase_ with @specialize in the interpreter diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -375,12 +375,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.""" @@ -829,12 +829,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 @@ -849,7 +850,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. @@ -1288,6 +1288,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 @@ -1299,7 +1300,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: @@ -1309,6 +1309,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) @@ -1331,7 +1332,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/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -109,6 +109,7 @@ # we need two subclasses of the app-level type, one to add mapdict, and then one # to add del to not slow down the GC. +@specialize.memo() def get_unique_interplevel_subclass(space, cls): "NOT_RPYTHON: initialization-time only" assert cls.typedef.acceptable_as_base_class @@ -119,7 +120,6 @@ assert cls not in _unique_subclass_cache _unique_subclass_cache[cls] = subcls return subcls -get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo" _unique_subclass_cache = {} def _getusercls(cls, reallywantdict=False): 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 @@ -6,6 +6,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.error import OperationError, oefmt from rpython.rlib.debug import check_nonneg +from rpython.rlib.objectmodel import specialize # A `dequeobject` is composed of a doubly-linked list of `block` nodes. @@ -316,12 +317,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 @@ -6,6 +6,7 @@ import time from pypy.interpreter.error import OperationError from pypy.module._pypyjson.interp_decoder import loads +from rpython.rlib.objectmodel import specialize ## MSG = open('msg.json').read() @@ -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 @@ -9,6 +9,7 @@ from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.tool import rffi_platform from rpython.rlib.unroll import unrolling_iterable +from rpython.rlib.objectmodel import specialize import rpython.rlib.rposix as rposix _MS_WINDOWS = os.name == "nt" @@ -255,6 +256,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: @@ -274,8 +276,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)) @@ -296,7 +298,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") @@ -374,14 +375,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): if letter in TYPEMAP_PTR_LETTERS: # check for NULL ptr @@ -422,10 +424,10 @@ return else: raise oefmt(space.w_TypeError, "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: @@ -437,7 +439,6 @@ else: return space.wrap(func(add_arg, argdesc, ll_type)) raise oefmt(space.w_TypeError, "cannot directly read value") -wrap_value._annspecialcase_ = 'specialize:arg(1)' NARROW_INTEGER_TYPES = 'cbhiBIH?' 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 import sys IS_BIG_ENDIAN = sys.byteorder == 'big' @@ -284,6 +285,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) @@ -291,8 +293,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) @@ -313,8 +315,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) @@ -337,7 +339,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/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, oefmt 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: @@ -26,8 +28,8 @@ except ValueError: raise oefmt(space.w_ValueError, "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: @@ -37,8 +39,8 @@ except ValueError: raise oefmt(space.w_ValueError, "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) @@ -49,7 +51,6 @@ except ValueError: raise oefmt(space.w_ValueError, "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 @@ -7,6 +7,7 @@ from rpython.rtyper.tool import rffi_platform from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.translator.platform import platform +from rpython.rlib.objectmodel import specialize import sys import weakref @@ -571,6 +572,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) @@ -582,8 +584,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,68 +9,68 @@ 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' +@specialize.memo() def str_getitem(space): "Utility that returns the app-level descriptor str.__getitem__." w_src, w_iter = space.lookup_in_type_where(space.w_str, '__getitem__') return w_iter -str_getitem._annspecialcase_ = 'specialize:memo' +@specialize.memo() def unicode_getitem(space): "Utility that returns the app-level descriptor unicode.__getitem__." w_src, w_iter = space.lookup_in_type_where(space.w_unicode, '__getitem__') return w_iter -unicode_getitem._annspecialcase_ = 'specialize:memo' def raiseattrerror(space, w_obj, name, w_descr=None): if w_descr is None: 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 @@ -7,6 +7,7 @@ from rpython.rlib.rstring import StringBuilder, UnicodeBuilder from rpython.rlib.unroll import unrolling_iterable from rpython.tool.sourcetools import func_with_new_name +from rpython.rlib.objectmodel import specialize from pypy.interpreter.error import OperationError, oefmt @@ -344,6 +345,7 @@ "unsupported format character '%s' (%s) at index %d", s, hex(ord(c)), self.fmtpos - 1) + @specialize.argtype(2) def std_wp(self, r): length = len(r) if do_unicode and isinstance(r, str): @@ -369,7 +371,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/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -351,6 +351,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.""" @@ -375,7 +376,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