Author: Spenser Bauman <saba...@gmail.com> Branch: value-classes Changeset: r87283:b71c2014dd9d Date: 2016-09-21 12:11 -0400 http://bitbucket.org/pypy/pypy/changeset/b71c2014dd9d/
Log: Replace all _immutable_=True annotations with _immutable_fields_=[...] Tests converted to use _value_class_=True diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py --- a/pypy/interpreter/gateway.py +++ b/pypy/interpreter/gateway.py @@ -332,7 +332,6 @@ activation_cls = type("BuiltinActivation_UwS_%s" % label, (BuiltinActivation,), d) - activation_cls._immutable_ = True cache[key] = activation_cls, self.run_args return activation_cls @@ -346,7 +345,7 @@ class BuiltinActivation(object): - _immutable_ = True + _immutable_fields_ = ['behavior'] def __init__(self, behavior): """NOT_RPYTHON""" @@ -564,7 +563,10 @@ class BuiltinCode(Code): "The code object implementing a built-in (interpreter-level) hook." - _immutable_ = True + _immutable_fields_ = ['docstring', 'identifier', '_argnames', + 'descrmismatch_op', 'descr_reqcls', + 'sig', 'minargs', 'maxargs', 'activation', + '_bltin', '_unwrap_spec', 'func__args__'] hidden_applevel = True descrmismatch_op = None descr_reqcls = None @@ -727,7 +729,6 @@ class BuiltinCodePassThroughArguments0(BuiltinCode): - _immutable_ = True def funcrun(self, func, args): space = func.space @@ -747,7 +748,6 @@ class BuiltinCodePassThroughArguments1(BuiltinCode): - _immutable_ = True fast_natural_arity = Code.PASSTHROUGHARGS1 def funcrun_obj(self, func, w_obj, args): @@ -768,7 +768,6 @@ class BuiltinCode0(BuiltinCode): - _immutable_ = True fast_natural_arity = 0 def fastcall_0(self, space, w_func): @@ -785,7 +784,6 @@ class BuiltinCode1(BuiltinCode): - _immutable_ = True fast_natural_arity = 1 def fastcall_1(self, space, w_func, w1): @@ -805,7 +803,6 @@ class BuiltinCode2(BuiltinCode): - _immutable_ = True fast_natural_arity = 2 def fastcall_2(self, space, w_func, w1, w2): @@ -825,7 +822,6 @@ class BuiltinCode3(BuiltinCode): - _immutable_ = True fast_natural_arity = 3 def fastcall_3(self, space, func, w1, w2, w3): @@ -845,7 +841,6 @@ class BuiltinCode4(BuiltinCode): - _immutable_ = True fast_natural_arity = 4 def fastcall_4(self, space, func, w1, w2, w3, w4): diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -1344,14 +1344,13 @@ WHY_CONTINUE, SContinueLoop WHY_YIELD not needed """ - _immutable_ = True def nomoreblocks(self): raise BytecodeCorruption("misplaced bytecode - should not return") class SReturnValue(SuspendedUnroller): """Signals a 'return' statement. Argument is the wrapped object to return.""" - _immutable_ = True + _immutable_fields_ = ['w_returnvalue'] kind = 0x01 def __init__(self, w_returnvalue): self.w_returnvalue = w_returnvalue @@ -1361,7 +1360,7 @@ class SApplicationException(SuspendedUnroller): """Signals an application-level exception (i.e. an OperationException).""" - _immutable_ = True + _immutable_fields_ = ['operr'] kind = 0x02 def __init__(self, operr): self.operr = operr @@ -1370,14 +1369,13 @@ class SBreakLoop(SuspendedUnroller): """Signals a 'break' statement.""" - _immutable_ = True kind = 0x04 SBreakLoop.singleton = SBreakLoop() class SContinueLoop(SuspendedUnroller): """Signals a 'continue' statement. Argument is the bytecode position of the beginning of the loop.""" - _immutable_ = True + _immutable_fields_ = ['jump_to'] kind = 0x08 def __init__(self, jump_to): self.jump_to = jump_to @@ -1387,7 +1385,7 @@ """Abstract base class for frame blocks from the blockstack, used by the SETUP_XXX and POP_BLOCK opcodes.""" - _immutable_ = True + _immutable_fields_ = ['handlerposition', 'valuestackdepth', 'previous'] def __init__(self, frame, handlerposition, previous): self.handlerposition = handlerposition @@ -1426,7 +1424,6 @@ class LoopBlock(FrameBlock): """A loop block. Stores the end-of-loop pointer in case of 'break'.""" - _immutable_ = True _opname = 'SETUP_LOOP' handling_mask = SBreakLoop.kind | SContinueLoop.kind @@ -1448,7 +1445,6 @@ class ExceptBlock(FrameBlock): """An try:except: block. Stores the position of the exception handler.""" - _immutable_ = True _opname = 'SETUP_EXCEPT' handling_mask = SApplicationException.kind @@ -1472,7 +1468,6 @@ class FinallyBlock(FrameBlock): """A try:finally: block. Stores the position of the exception handler.""" - _immutable_ = True _opname = 'SETUP_FINALLY' handling_mask = -1 # handles every kind of SuspendedUnroller @@ -1487,8 +1482,6 @@ class WithBlock(FinallyBlock): - _immutable_ = True - def handle(self, frame, unroller): if isinstance(unroller, SApplicationException): unroller.operr.normalize_exception(frame.space) diff --git a/pypy/interpreter/signature.py b/pypy/interpreter/signature.py --- a/pypy/interpreter/signature.py +++ b/pypy/interpreter/signature.py @@ -1,8 +1,7 @@ from rpython.rlib import jit class Signature(object): - _immutable_ = True - _immutable_fields_ = ["argnames[*]"] + _immutable_fields_ = ["argnames[*]", "varargname", "kwargname"] __slots__ = ("argnames", "varargname", "kwargname") def __init__(self, argnames, varargname=None, kwargname=None): diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -353,7 +353,7 @@ class Member(W_Root): """For slots.""" - _immutable_ = True + _immutable_fields_ = ["index", "name", "w_cls"] def __init__(self, index, name, w_cls): self.index = index diff --git a/pypy/module/__pypy__/bytebuffer.py b/pypy/module/__pypy__/bytebuffer.py --- a/pypy/module/__pypy__/bytebuffer.py +++ b/pypy/module/__pypy__/bytebuffer.py @@ -7,7 +7,7 @@ class ByteBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['data', 'readonly'] def __init__(self, len): self.data = ['\x00'] * len diff --git a/pypy/module/_cffi_backend/allocator.py b/pypy/module/_cffi_backend/allocator.py --- a/pypy/module/_cffi_backend/allocator.py +++ b/pypy/module/_cffi_backend/allocator.py @@ -7,7 +7,8 @@ class W_Allocator(W_Root): - _immutable_ = True + _immutable_fields_ = ['ffi', 'w_alloc', 'w_free', + 'should_clear_after_alloc'] def __init__(self, ffi, w_alloc, w_free, should_clear_after_alloc): self.ffi = ffi # may be None diff --git a/pypy/module/_cffi_backend/cbuffer.py b/pypy/module/_cffi_backend/cbuffer.py --- a/pypy/module/_cffi_backend/cbuffer.py +++ b/pypy/module/_cffi_backend/cbuffer.py @@ -11,7 +11,7 @@ class LLBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['raw_cdata', 'size', 'readonly'] def __init__(self, raw_cdata, size): self.raw_cdata = raw_cdata diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py --- a/pypy/module/_cffi_backend/ctypeptr.py +++ b/pypy/module/_cffi_backend/ctypeptr.py @@ -378,7 +378,7 @@ rffi_fclose = rffi.llexternal("fclose", [FILEP], rffi.INT) class CffiFileObj(object): - _immutable_ = True + _immutable_fields_ = ['llf'] def __init__(self, fd, mode): self.llf = rffi_fdopen(fd, mode) diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py --- a/pypy/module/_cffi_backend/ctypestruct.py +++ b/pypy/module/_cffi_backend/ctypestruct.py @@ -189,7 +189,7 @@ class W_CField(W_Root): - _immutable_ = True + _immutable_fields_ = ['ctype', 'offset', 'bitshift', 'bitsize', 'flags'] BS_REGULAR = -1 BS_EMPTY_ARRAY = -2 diff --git a/pypy/module/_cffi_backend/libraryobj.py b/pypy/module/_cffi_backend/libraryobj.py --- a/pypy/module/_cffi_backend/libraryobj.py +++ b/pypy/module/_cffi_backend/libraryobj.py @@ -14,7 +14,7 @@ class W_Library(W_Root): - _immutable_ = True + _immutable_fields_ = ['handle', 'name'] def __init__(self, space, filename, flags): self.space = space diff --git a/pypy/module/_cffi_backend/wrapper.py b/pypy/module/_cffi_backend/wrapper.py --- a/pypy/module/_cffi_backend/wrapper.py +++ b/pypy/module/_cffi_backend/wrapper.py @@ -24,7 +24,8 @@ This class cannot be used for variadic functions. """ - _immutable_ = True + _immutable_fields_ = ['ffi', 'fnptr', 'directfnptr', 'rawfunctype', + 'fnname', 'modulename'] def __init__(self, space, ffi, fnptr, directfnptr, rawfunctype, fnname, modulename): diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py --- a/pypy/module/_io/interp_bufferedio.py +++ b/pypy/module/_io/interp_bufferedio.py @@ -106,7 +106,7 @@ ) class RawBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['buf', 'start', 'length', 'readonly'] def __init__(self, buf, start, length): self.buf = buf diff --git a/pypy/module/_rawffi/buffer.py b/pypy/module/_rawffi/buffer.py --- a/pypy/module/_rawffi/buffer.py +++ b/pypy/module/_rawffi/buffer.py @@ -5,7 +5,7 @@ class RawFFIBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['datainstance', 'readonly'] def __init__(self, datainstance): self.datainstance = datainstance diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -591,7 +591,7 @@ unroll_typecodes = unrolling_iterable(types.keys()) class ArrayBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ["array", "readonly"] def __init__(self, array, readonly): self.array = array diff --git a/pypy/module/cppyy/capi/loadable_capi.py b/pypy/module/cppyy/capi/loadable_capi.py --- a/pypy/module/cppyy/capi/loadable_capi.py +++ b/pypy/module/cppyy/capi/loadable_capi.py @@ -20,7 +20,7 @@ std_string_name = 'std::basic_string<char>' class _Arg: # poor man's union - _immutable_ = True + _immutable_fields_ = ['_handle', '_long', '_string', '_voidp'] def __init__(self, h = 0, l = -1, s = '', vp = rffi.cast(rffi.VOIDP, 0)): self._handle = h self._long = l diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py --- a/pypy/module/cppyy/converter.py +++ b/pypy/module/cppyy/converter.py @@ -723,11 +723,10 @@ for c_type, names in type_info: class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter): - _immutable_ = True + _immutable_fields_ = ['default'] def __init__(self, space, default): self.default = rffi.cast(self.c_type, capi.c_strtoll(space, default)) class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter): - _immutable_ = True libffitype = jit_libffi.types.pointer for name in names: _converters[name] = BasicConverter @@ -740,11 +739,10 @@ for c_type, names in type_info: class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter): - _immutable_ = True + _immutable_fields_ = ['default'] def __init__(self, space, default): self.default = rffi.cast(self.c_type, capi.c_strtoll(space, default)) class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter): - _immutable_ = True libffitype = jit_libffi.types.pointer typecode = 'r' def convert_argument(self, space, w_obj, address, call_local): @@ -766,11 +764,10 @@ for c_type, names in type_info: class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter): - _immutable_ = True + _immutable_fields_ = ['default'] def __init__(self, space, default): self.default = rffi.cast(self.c_type, capi.c_strtoull(space, default)) class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter): - _immutable_ = True libffitype = jit_libffi.types.pointer for name in names: _converters[name] = BasicConverter diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py --- a/pypy/module/cppyy/executor.py +++ b/pypy/module/cppyy/executor.py @@ -326,7 +326,6 @@ for c_type, stub, names in type_info: class BasicExecutor(ffitypes.typeid(c_type), NumericExecutorMixin, FunctionExecutor): - _immutable_ = True c_stubcall = staticmethod(stub) class BasicRefExecutor(ffitypes.typeid(c_type), NumericRefExecutorMixin, FunctionExecutor): _immutable_fields_ = ['libffitype'] diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py --- a/pypy/module/cppyy/interp_cppyy.py +++ b/pypy/module/cppyy/interp_cppyy.py @@ -136,7 +136,7 @@ class W_CPPLibrary(W_Root): - _immutable_ = True + _immutable_fields_ = ["cdll"] def __init__(self, space, cdll): self.cdll = cdll @@ -156,7 +156,9 @@ _attrs_ = ['space', 'scope', 'index', 'cppmethod', 'arg_defs', 'args_required', 'converters', 'executor', '_funcaddr', 'cif_descr', 'uses_local'] - _immutable_ = True + _immutable_fields_ = ['scope', 'index', 'cppmethod', 'arg_defs', 'args_required', + 'converters', 'executor', '_funcaddr', 'cif_descr', 'uses_local'] + def __init__(self, space, declaring_scope, method_index, arg_defs, args_required): self.space = space @@ -403,8 +405,6 @@ class CPPFunction(CPPMethod): """Global (namespaced) function dispatcher.""" - _immutable_ = True - @staticmethod def unpack_cppthis(space, w_cppinstance, declaring_scope): return capi.C_NULL_OBJECT @@ -417,7 +417,7 @@ """Method dispatcher that first resolves the template instance.""" _attrs_ = ['space', 'templ_args'] - _immutable_ = True + _immutable_fields_ = ['templ_args'] def __init__(self, space, templ_args, declaring_scope, method_index, arg_defs, args_required): self.space = space @@ -452,8 +452,6 @@ reflection layer only, since the C++ class may have an overloaded operator new, disallowing malloc here.""" - _immutable_ = True - @staticmethod def unpack_cppthis(space, w_cppinstance, declaring_scope): return rffi.cast(capi.C_OBJECT, declaring_scope.handle) @@ -473,8 +471,6 @@ operator[](int). The former function takes an extra argument to assign to the return type of the latter.""" - _immutable_ = True - def call(self, cppthis, args_w): end = len(args_w)-1 if 0 <= end: @@ -624,7 +620,7 @@ class W_CPPDataMember(W_Root): _attrs_ = ['space', 'scope', 'converter', 'offset'] - _immutable_fields = ['scope', 'converter', 'offset'] + _immutable_fields_ = ['scope', 'converter', 'offset'] def __init__(self, space, declaring_scope, type_name, offset): self.space = space @@ -998,7 +994,7 @@ class W_CPPTemplateType(W_Root): _attrs_ = ['space', 'name', 'handle'] - _immutable_fields = ['name', 'handle'] + _immutable_fields_ = ['name', 'handle'] def __init__(self, space, name, opaque_handle): self.space = space diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -300,7 +300,8 @@ class CPyBuffer(Buffer): # Similar to Py_buffer - _immutable_ = True + _immutable_fields_ = ['ptr', 'size', 'w_obj', 'format', 'shape', 'strides', + 'ndim', 'itemsize', 'readonly'] def __init__(self, ptr, size, w_obj, format='B', shape=None, strides=None, ndim=1, itemsize=1, readonly=True): diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -702,7 +702,7 @@ class ArrayBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['impl', 'readonly'] def __init__(self, impl, readonly): self.impl = impl diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py --- a/pypy/module/mmap/interp_mmap.py +++ b/pypy/module/mmap/interp_mmap.py @@ -331,7 +331,7 @@ class MMapBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['mmap', 'readonly'] def __init__(self, space, mmap, readonly): self.space = space diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -1217,7 +1217,7 @@ class BytearrayBuffer(Buffer): - _immutable_ = True + _immutable_fields_ = ['data', 'readonly'] def __init__(self, data, readonly): self.data = data diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -100,7 +100,7 @@ the first is either the same or a parent layout of the second. The Layouts have single inheritance, unlike W_TypeObjects. """ - _immutable_ = True + _immutable_fields_ = ['typedef', 'nslots', 'base_layout'] def __init__(self, typedef, nslots, newslotnames=[], base_layout=None): self.typedef = typedef diff --git a/rpython/flowspace/argument.py b/rpython/flowspace/argument.py --- a/rpython/flowspace/argument.py +++ b/rpython/flowspace/argument.py @@ -4,8 +4,7 @@ from rpython.flowspace.model import const class Signature(object): - _immutable_ = True - _immutable_fields_ = ["argnames[*]"] + _immutable_fields_ = ["argnames[*]", "varargnames", "kwargname"] __slots__ = ("argnames", "varargname", "kwargname") def __init__(self, argnames, varargname=None, kwargname=None): diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py --- a/rpython/flowspace/generator.py +++ b/rpython/flowspace/generator.py @@ -12,7 +12,6 @@ class AbstractPosition(object): - _immutable_ = True _attrs_ = () def make_generator_entry_graph(func): @@ -42,7 +41,6 @@ def make_generatoriterator_class(var_names): class GeneratorIterator(object): class Entry(AbstractPosition): - _immutable_ = True varnames = var_names def __init__(self, entry): @@ -135,8 +133,7 @@ varnames = get_variable_names(newlink.args) # class Resume(AbstractPosition): - _immutable_ = True - _attrs_ = varnames + _immutable_fields_ = _attrs_ = varnames block = newblock Resume.__name__ = 'Resume%d' % len(mappings) mappings.append(Resume) diff --git a/rpython/flowspace/test/test_generator.py b/rpython/flowspace/test/test_generator.py --- a/rpython/flowspace/test/test_generator.py +++ b/rpython/flowspace/test/test_generator.py @@ -39,11 +39,11 @@ return self class AbstractPosition(object): - _immutable_ = True + _immutable_fields_ = [] class Entry1(AbstractPosition): - _immutable_ = True + _immutable_fields_ = [] class Yield1(AbstractPosition): - _immutable_ = True + _immutable_fields_ = [] def f_explicit(n): e = Entry1() diff --git a/rpython/jit/backend/arm/locations.py b/rpython/jit/backend/arm/locations.py --- a/rpython/jit/backend/arm/locations.py +++ b/rpython/jit/backend/arm/locations.py @@ -2,7 +2,7 @@ from rpython.jit.backend.arm.arch import WORD, DOUBLE_WORD, JITFRAME_FIXED_SIZE class AssemblerLocation(object): - _immutable_ = True + _immutable_fields_ = ['type'] type = INT def is_imm(self): @@ -33,7 +33,7 @@ raise NotImplementedError # only for stack class RegisterLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['value'] width = WORD def __init__(self, value): @@ -50,7 +50,6 @@ class VFPRegisterLocation(RegisterLocation): - _immutable_ = True type = FLOAT width = 2 * WORD @@ -71,7 +70,6 @@ class SVFPRegisterLocation(VFPRegisterLocation): """Single Precission VFP Register""" - _immutable_ = True width = WORD type = 'S' @@ -79,7 +77,7 @@ return 'vfp(s%d)' % self.value class ImmLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['value'] width = WORD def __init__(self, value): @@ -98,7 +96,7 @@ class ConstFloatLoc(AssemblerLocation): """This class represents an imm float value which is stored in memory at the address stored in the field value""" - _immutable_ = True + _immutable_fields_ = ['value'] width = 2 * WORD type = FLOAT @@ -121,7 +119,7 @@ return True class StackLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['width', 'position', 'value'] def __init__(self, position, fp_offset, type=INT): if type == FLOAT: @@ -154,7 +152,7 @@ return self.type == FLOAT class RawSPStackLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['width', 'value'] def __init__(self, sp_offset, type=INT): if type == FLOAT: diff --git a/rpython/jit/backend/ppc/locations.py b/rpython/jit/backend/ppc/locations.py --- a/rpython/jit/backend/ppc/locations.py +++ b/rpython/jit/backend/ppc/locations.py @@ -12,7 +12,6 @@ class AssemblerLocation(object): - _immutable_ = True type = INT def is_imm(self): @@ -40,7 +39,7 @@ raise NotImplementedError class RegisterLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ["value"] width = WORD def __init__(self, value): @@ -56,7 +55,6 @@ return self.value class FPRegisterLocation(RegisterLocation): - _immutable_ = True type = FLOAT width = FWORD @@ -76,7 +74,7 @@ return self.value + 100 class ImmLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ["value"] width = WORD @@ -95,7 +93,7 @@ class ConstFloatLoc(AssemblerLocation): """This class represents an imm float value which is stored in memory at the address stored in the field value""" - _immutable_ = True + _immutable_fields_ = ["value"] width = FWORD type = FLOAT @@ -115,7 +113,7 @@ return self.value class StackLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ["width", "position", "value", "type"] def __init__(self, position, fp_offset, type=INT): if type == FLOAT: diff --git a/rpython/jit/backend/x86/regloc.py b/rpython/jit/backend/x86/regloc.py --- a/rpython/jit/backend/x86/regloc.py +++ b/rpython/jit/backend/x86/regloc.py @@ -18,7 +18,7 @@ class AssemblerLocation(object): _attrs_ = ('value', '_location_code') - _immutable_ = True + _immutable_fields_ = ['value', '_location_code'] def _getregkey(self): return self.value @@ -55,7 +55,7 @@ """ The same as stack location, but does not know it's position. Mostly usable for raw frame access """ - _immutable_ = True + _immutable_fields_ = ['type'] _location_code = 'b' def __init__(self, value, type=INT): @@ -85,7 +85,7 @@ class RawEspLoc(AssemblerLocation): """ Esp-based location """ - _immutable_ = True + _immutable_fields_ = ['type'] _location_code = 's' def __init__(self, value, type): @@ -111,7 +111,7 @@ return self.type == FLOAT class FrameLoc(RawEbpLoc): - _immutable_ = True + _immutable_fields_ = ['position', 'type'] def __init__(self, position, ebp_offset, type): # _getregkey() returns self.value; the value returned must not @@ -129,7 +129,7 @@ return self.position class RegLoc(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['is_xmm'] def __init__(self, regnum, is_xmm): assert regnum >= 0 self.value = regnum @@ -175,10 +175,10 @@ return True class ImmediateAssemblerLocation(AssemblerLocation): - _immutable_ = True + pass class ImmedLoc(ImmediateAssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['_is_float'] _location_code = 'i' def __init__(self, value, is_float=False): @@ -205,7 +205,7 @@ return self._is_float class AddressLoc(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['loc_a', 'loc_m'] # The address is base_loc + (scaled_loc << scale) + static_offset def __init__(self, base_loc, scaled_loc, scale=0, static_offset=0): @@ -277,7 +277,6 @@ return result class ConstFloatLoc(ImmediateAssemblerLocation): - _immutable_ = True _location_code = 'j' def __init__(self, address): @@ -298,7 +297,7 @@ # any assembler instruction. Instead, it is meant to be decomposed # in two 32-bit halves. On 64-bit, FloatImmedLoc() is a function # instead; see below. - _immutable_ = True + _immutable_fields_ = ['aslonglong'] _location_code = '#' # don't use me def __init__(self, floatstorage): diff --git a/rpython/jit/backend/zarch/conditions.py b/rpython/jit/backend/zarch/conditions.py --- a/rpython/jit/backend/zarch/conditions.py +++ b/rpython/jit/backend/zarch/conditions.py @@ -2,7 +2,6 @@ from rpython.rlib.objectmodel import specialize class ConditionLocation(loc.ImmLocation): - _immutable_ = True def __repr__(self): s = "" if self.value & 0x1 != 0: diff --git a/rpython/jit/backend/zarch/locations.py b/rpython/jit/backend/zarch/locations.py --- a/rpython/jit/backend/zarch/locations.py +++ b/rpython/jit/backend/zarch/locations.py @@ -4,8 +4,8 @@ FWORD = 8 class AssemblerLocation(object): - _immutable_ = True type = INT + _immutable_fields_ = ['type'] def is_imm(self): return False @@ -41,7 +41,7 @@ raise NotImplementedError # only for stack class RegisterLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['value'] width = WORD def __init__(self, value): @@ -65,7 +65,7 @@ class ConstFloatLoc(AssemblerLocation): """This class represents an imm float value which is stored in memory at the address stored in the field value""" - _immutable_ = True + _immutable_fields_ = ['value'] width = FWORD type = FLOAT @@ -88,7 +88,6 @@ return self.value class FloatRegisterLocation(RegisterLocation): - _immutable_ = True type = FLOAT width = DOUBLE_WORD @@ -108,7 +107,7 @@ return True class ImmLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['value'] width = WORD def __init__(self, value): @@ -124,7 +123,7 @@ return True class StackLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['width', 'position', 'value'] def __init__(self, position, fp_offset, type=INT): if type == FLOAT: @@ -157,7 +156,8 @@ return self.type == FLOAT class AddressLocation(AssemblerLocation): - _immutable_ = True + _immutable_fields_ = ['displace', 'base', 'index', 'length', 'basereg', + 'base', 'index', 'length'] def __init__(self, basereg, indexreg, displace, length): self.displace = displace @@ -177,7 +177,7 @@ self.length = length.value class PoolLoc(AddressLocation): - _immutable_ = True + _immutable_fields_ = ['isfloat'] width = WORD def __init__(self, offset, isfloat=False): diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -304,7 +304,7 @@ myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) class I: __slots__ = 'intval' - _immutable_ = True + _immutable_fields_ = ['intval'] def __init__(self, intval): self.intval = intval def f(i, y): @@ -845,7 +845,7 @@ def test_getfield_immutable(self): class A: - _immutable_ = True + _immutable_fields_ = ['foo'] a1 = A() a1.foo = 5 a2 = A() diff --git a/rpython/jit/metainterp/test/test_immutable.py b/rpython/jit/metainterp/test/test_immutable.py --- a/rpython/jit/metainterp/test/test_immutable.py +++ b/rpython/jit/metainterp/test/test_immutable.py @@ -90,7 +90,7 @@ def test_array_in_immutable(self): class X(object): - _immutable_ = True + _value_class_ = True _immutable_fields_ = ["lst[*]"] def __init__(self, lst, y): diff --git a/rpython/jit/metainterp/test/test_virtual.py b/rpython/jit/metainterp/test/test_virtual.py --- a/rpython/jit/metainterp/test/test_virtual.py +++ b/rpython/jit/metainterp/test/test_virtual.py @@ -288,12 +288,12 @@ myjitdriver = JitDriver(greens=['stufflist'], reds=['n', 'i']) class Stuff(object): - _immutable_ = True + _immutable_fields_ = ['x'] def __init__(self, x): self.x = x class StuffList(object): - _immutable_ = True + _immutable_fields_ = ['lst'] def f(n, a, i): stufflist = StuffList() diff --git a/rpython/jit/tl/tiny2_hotpath.py b/rpython/jit/tl/tiny2_hotpath.py --- a/rpython/jit/tl/tiny2_hotpath.py +++ b/rpython/jit/tl/tiny2_hotpath.py @@ -43,7 +43,7 @@ pass class IntBox(Box): - _immutable_ = True + _immutable_fields_ = ['intval'] def __init__(self, intval): self.intval = intval def as_int(self): @@ -52,7 +52,7 @@ return str(self.intval) class StrBox(Box): - _immutable_ = True + _immutable_fields_ = ['strval'] def __init__(self, strval): self.strval = strval def as_int(self): diff --git a/rpython/jit/tl/tiny3_hotpath.py b/rpython/jit/tl/tiny3_hotpath.py --- a/rpython/jit/tl/tiny3_hotpath.py +++ b/rpython/jit/tl/tiny3_hotpath.py @@ -45,7 +45,7 @@ pass class IntBox(Box): - _immutable_ = True + _immutable_fields_ = ['intval'] def __init__(self, intval): self.intval = intval def as_int(self): @@ -56,7 +56,7 @@ return str(self.intval) class FloatBox(Box): - _immutable_ = True + _immutable_fields_ = ['floatval'] def __init__(self, floatval): self.floatval = floatval def as_int(self): diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py --- a/rpython/rlib/buffer.py +++ b/rpython/rlib/buffer.py @@ -7,7 +7,7 @@ class Buffer(object): """Abstract base class for buffers.""" __slots__ = ['readonly'] - _immutable_ = True + _immutable_fields_ = __slots__ def getlength(self): """Returns the size in bytes (even if getitemsize() > 1).""" @@ -77,7 +77,7 @@ class StringBuffer(Buffer): __slots__ = ['value'] - _immutable_ = True + _immutable_fields_ = ['value'] def __init__(self, value): self.value = value @@ -108,7 +108,7 @@ class SubBuffer(Buffer): __slots__ = ['buffer', 'offset', 'size'] - _immutable_ = True + _immutable_fields_ = __slots__ def __init__(self, buffer, offset, size): self.readonly = buffer.readonly diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -136,8 +136,7 @@ class rbigint(object): """This is a reimplementation of longs using a list of digits.""" - _immutable_ = True - _immutable_fields_ = ["_digits"] + _immutable_fields_ = ["_digits", "size", "sign"] def __init__(self, digits=[NULLDIGIT], sign=0, size=0): if not we_are_translated(): diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py --- a/rpython/rlib/rsre/rsre_core.py +++ b/rpython/rlib/rsre/rsre_core.py @@ -243,7 +243,7 @@ # ____________________________________________________________ class Mark(object): - _immutable_ = True + _immutable_fields_ = ['gid', 'position', 'prev'] def __init__(self, gid, position, prev): self.gid = gid diff --git a/rpython/rtyper/test/test_generator.py b/rpython/rtyper/test/test_generator.py --- a/rpython/rtyper/test/test_generator.py +++ b/rpython/rtyper/test/test_generator.py @@ -23,11 +23,11 @@ # merging two different generators is not supported # right now, but we can use workarounds like here class MyGen: - _immutable_ = True + _immutable_fields_ = [] def next(self): raise NotImplementedError class MyG1(MyGen): - _immutable_ = True + _immutable_fields_ = ["_gen"] def __init__(self, a): self._gen = self.g1(a) def next(self): @@ -37,7 +37,7 @@ yield a + 1 yield a + 2 class MyG2(MyGen): - _immutable_ = True + _immutable_fields_ = ["_gen"] def __init__(self): self._gen = self.g2() def next(self): diff --git a/rpython/rtyper/test/test_rclass.py b/rpython/rtyper/test/test_rclass.py --- a/rpython/rtyper/test/test_rclass.py +++ b/rpython/rtyper/test/test_rclass.py @@ -745,9 +745,9 @@ assert res == 0 - def test_immutable(self): + def test_value_class(self): class I(object): - _immutable_ = True + _value_class_ = True def __init__(self, v): self.v = v @@ -849,10 +849,10 @@ class A(object): pass class B(A): - _immutable_ = True + _value_class_ = True def f(): A().v = 123 - B() # crash: class B has _immutable_ = True + B() # crash: class B has _value_class_ = True # but class A defines 'v' to be mutable py.test.raises(ImmutableConflictError, self.gengraph, f, []) @@ -861,7 +861,7 @@ class A(object): _immutable_fields_ = ['v'] class B(A): - _immutable_ = True + _value_class_ = True def f(): A().v = 123 B().w = 456 @@ -877,7 +877,7 @@ from rpython.rtyper.rclass import ImmutableConflictError from rpython.jit.metainterp.typesystem import deref class A(object): - _immutable_ = True + _value_class_ = True class B(A): pass def f(): @@ -891,7 +891,7 @@ class A(object): pass class B(A): - _immutable_ = True + _value_class_ = True def f(): A() B().v = 123 @@ -905,12 +905,12 @@ class A(object): pass class B(A): - _immutable_ = True + _value_class_ = True def myfunc(): pass def f(): A().f = myfunc # it's ok to add Void attributes to A - B().v = 123 # even though only B is declared _immutable_ + B().v = 123 # even though only B is declared _value_class_ return B() t, typer, graph = self.gengraph(f, []) B_TYPE = deref(graph.getreturnvar().concretetype) @@ -946,7 +946,7 @@ def test_quasi_immutable_clashes_with_immutable(self): from rpython.jit.metainterp.typesystem import deref class A(object): - _immutable_ = True + _value_class_ = True _immutable_fields_ = ['a?'] def f(): a = A() @@ -1306,70 +1306,70 @@ return a.next.next.next.next is not None assert self.interpret(f, []) == True - def test_value_class(self): +# def test_value_class(self): +# +# class I(object): +# _value_class_ = True +# +# def __init__(self, v): +# self.v = v +# +# i = I(3) +# def f(): +# return i.v +# +# t, typer, graph = self.gengraph(f, [], backendopt=True) +# assert summary(graph) == {} +# +# def test_value_class_conflicts_with_immut(self): +# from rpython.rtyper.rclass import ImmutableConflictError +# +# class I(object): +# _immutable_ = False +# _value_class_ = True +# +# def __init__(self, v): +# self.v = v +# +# i = I(3) +# def f(): +# return i.v +# +# py.test.raises(ImmutableConflictError, self.gengraph, f, []) +# +# def test_value_class_implies_immutable(self): +# from rpython.jit.metainterp.typesystem import deref +# +# class I(object): +# _value_class_ = True +# +# def __init__(self, v): +# self.v = v +# +# i = I(3) +# def f(): +# return i +# +# t, typer, graph = self.gengraph(f, []) +# I_TYPE = deref(graph.getreturnvar().concretetype) +# assert I_TYPE._hints['immutable'] +# assert I_TYPE._hints['value_class'] +# +# def test_value_class_subclass_not_value_class(self): +# from rpython.rtyper.rclass import ValueClassConflictError +# +# class Base(object): +# _value_class_ = True +# +# class I(Base): +# _immutable_ = True +# +# def __init__(self, v): +# self.v = v +# +# i = I(3) +# def f(): +# return i.v +# +# py.test.raises(ValueClassConflictError, self.gengraph, f, []) - class I(object): - _value_class_ = True - - def __init__(self, v): - self.v = v - - i = I(3) - def f(): - return i.v - - t, typer, graph = self.gengraph(f, [], backendopt=True) - assert summary(graph) == {} - - def test_value_class_conflicts_with_immut(self): - from rpython.rtyper.rclass import ImmutableConflictError - - class I(object): - _immutable_ = False - _value_class_ = True - - def __init__(self, v): - self.v = v - - i = I(3) - def f(): - return i.v - - py.test.raises(ImmutableConflictError, self.gengraph, f, []) - - def test_value_class_implies_immutable(self): - from rpython.jit.metainterp.typesystem import deref - - class I(object): - _value_class_ = True - - def __init__(self, v): - self.v = v - - i = I(3) - def f(): - return i - - t, typer, graph = self.gengraph(f, []) - I_TYPE = deref(graph.getreturnvar().concretetype) - assert I_TYPE._hints['immutable'] - assert I_TYPE._hints['value_class'] - - def test_value_class_subclass_not_value_class(self): - from rpython.rtyper.rclass import ValueClassConflictError - - class Base(object): - _value_class_ = True - - class I(Base): - _immutable_ = True - - def __init__(self, v): - self.v = v - - i = I(3) - def f(): - return i.v - - py.test.raises(ValueClassConflictError, self.gengraph, f, []) - _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit