[pypy-svn] r76839 - in pypy/branch/no-_immutable_/pypy: jit/codewriter rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 2 16:23:33 CEST 2010
Author: arigo
Date: Thu Sep 2 16:23:32 2010
New Revision: 76839
Modified:
pypy/branch/no-_immutable_/pypy/jit/codewriter/jtransform.py
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/opimpl.py
Log:
A few fixes. Untested so far.
Modified: pypy/branch/no-_immutable_/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/jit/codewriter/jtransform.py (original)
+++ pypy/branch/no-_immutable_/pypy/jit/codewriter/jtransform.py Thu Sep 2 16:23:32 2010
@@ -511,14 +511,11 @@
arraydescr)
return []
# check for deepfrozen structures that force constant-folding
- hints = v_inst.concretetype.TO._hints
- accessor = hints.get("immutable_fields")
- if accessor and c_fieldname.value in accessor.fields:
+ immut = v_inst.concretetype.TO._immutable_field(c_fieldname.value)
+ if immut:
pure = '_pure'
- if accessor.fields[c_fieldname.value] == "[*]":
+ if immut == "[*]":
self.immutable_arrays[op.result] = True
- elif hints.get('immutable'):
- pure = '_pure'
else:
pure = ''
argname = getattr(v_inst.concretetype.TO, '_gckind', 'gc')
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py Thu Sep 2 16:23:32 2010
@@ -85,16 +85,17 @@
fold = roproperty(get_fold_impl)
def is_pure(self, args_v):
- return (self.canfold or # canfold => pure operation
- self is llop.debug_assert or # debug_assert is pure enough
- # reading from immutable
- (self in (llop.getfield, llop.getarrayitem) and
- args_v[0].concretetype.TO._hints.get('immutable')) or
- (self is llop.getfield and # reading from immutable_field
- 'immutable_fields' in args_v[0].concretetype.TO._hints and
- args_v[1].value in args_v[0].concretetype.TO
- ._hints['immutable_fields'].fields))
- # XXX: what about ootype immutable arrays?
+ return (
+ self.canfold or # canfold => pure operation
+ self is llop.debug_assert or # debug_assert is pure enough
+ # reading from immutable (lltype)
+ (self in (llop.getfield, llop.getarrayitem) and
+ isinstance(args_v[1], Constant) and
+ args_v[0].concretetype.TO._immutable_field(args_v[1].value)) or
+ # reading from immutable (ootype) (xxx what about arrays?)
+ (self is llop.oogetfield and
+ isinstance(args_v[1], Constant) and
+ args_v[0].concretetype._immutable_field(args_v[1].value)))
def __repr__(self):
return '<LLOp %s>' % (getattr(self, 'opname', '?'),)
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py Thu Sep 2 16:23:32 2010
@@ -400,6 +400,9 @@
def _container_example(self):
return _array(self, 1, initialization='example')
+ def _immutable_field(self, index):
+ return self._hints.get('immutable', False)
+
class GcArray(Array):
_gckind = 'gc'
def _inline_is_varsize(self, last):
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/opimpl.py Thu Sep 2 16:23:32 2010
@@ -150,12 +150,7 @@
# we can constant-fold this if the innermost structure from which we
# read the final field is immutable.
T = lltype.typeOf(innermostcontainer).TO
- if T._hints.get('immutable'):
- pass
- elif ('immutable_fields' in T._hints and
- offsets[-1] in T._hints['immutable_fields'].fields):
- pass
- else:
+ if not T._immutable_field(offsets[-1]):
raise TypeError("cannot fold getinteriorfield on mutable struct")
assert not isinstance(ob, lltype._interior_ptr)
return ob
@@ -418,19 +413,15 @@
def op_getfield(p, name):
checkptr(p)
TYPE = lltype.typeOf(p).TO
- if TYPE._hints.get('immutable'):
- pass
- elif ('immutable_fields' in TYPE._hints and
- name in TYPE._hints['immutable_fields'].fields):
- pass
- else:
+ if not TYPE._immutable_field(name):
raise TypeError("cannot fold getfield on mutable struct")
return getattr(p, name)
def op_getarrayitem(p, index):
checkptr(p)
- if not lltype.typeOf(p).TO._hints.get('immutable'):
- raise TypeError("cannot fold getfield on mutable array")
+ ARRAY = lltype.typeOf(p).TO
+ if not ARRAY._immutable_field(index):
+ raise TypeError("cannot fold getarrayitem on mutable array")
return p[index]
def _normalize(x):
More information about the Pypy-commit
mailing list