[pypy-svn] r24708 - in pypy/dist/pypy/jit: . test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Mar 21 18:29:49 CET 2006
Author: pedronis
Date: Tue Mar 21 18:29:42 2006
New Revision: 24708
Modified:
pypy/dist/pypy/jit/hintcontainer.py
pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
(arre, pedronis)
record the structural information about the parent index in virtual struct def annotations.
extend union to consider.
test for this behavior.
Modified: pypy/dist/pypy/jit/hintcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/hintcontainer.py (original)
+++ pypy/dist/pypy/jit/hintcontainer.py Tue Mar 21 18:29:42 2006
@@ -32,19 +32,19 @@
# ____________________________________________________________
-def virtualcontainerdef(bookkeeper, T, vparent=None):
+def virtualcontainerdef(bookkeeper, T, vparent=None, vparentindex=0):
"""Build and return a VirtualXxxDef() corresponding to a
freshly allocated virtual container.
"""
if isinstance(T, lltype.Struct):
- return VirtualStructDef(bookkeeper, T, vparent)
+ return VirtualStructDef(bookkeeper, T, vparent, vparentindex)
elif isinstance(T, lltype.Array):
return VirtualArrayDef(bookkeeper, T)
raise TypeError("unsupported container type %r" % (T,))
-def make_item_annotation(bookkeeper, TYPE, vparent=None):
+def make_item_annotation(bookkeeper, TYPE, vparent=None, vparentindex=0):
if isinstance(TYPE, lltype.ContainerType):
- vdef = virtualcontainerdef(bookkeeper, TYPE, vparent=vparent)
+ vdef = virtualcontainerdef(bookkeeper, TYPE, vparent, vparentindex)
return hintmodel.SomeLLAbstractContainer(vdef)
elif isinstance(TYPE, lltype.Ptr):
return annmodel.s_ImpossibleValue
@@ -76,16 +76,17 @@
class VirtualStructDef(AbstractContainerDef):
- def __init__(self, bookkeeper, TYPE, vparent=None):
+ def __init__(self, bookkeeper, TYPE, vparent=None, vparentindex=0):
AbstractContainerDef.__init__(self, bookkeeper, TYPE)
self.fields = {}
self.names = TYPE._names
- for name in self.names:
+ for index, name in enumerate(self.names):
FIELD_TYPE = self.fieldtype(name)
- hs = make_item_annotation(bookkeeper, FIELD_TYPE, vparent=self)
+ hs = make_item_annotation(bookkeeper, FIELD_TYPE, vparent=self, vparentindex=index)
fv = self.fields[name] = FieldValue(bookkeeper, name, hs)
fv.itemof[self] = True
self.vparent = vparent
+ self.vparentindex = vparentindex
def cast(self, TO):
down_or_up = lltype.castable(TO,
@@ -119,7 +120,7 @@
incompatible = False
if self.vparent is not None:
if other.vparent is not None:
- if self.vparent.T != other.vparent.T:
+ if self.vparent.T != other.vparent.T or self.vparentindex != other.vparentindex:
incompatible = True
else:
self.vparent.union(other.vparent)
Modified: pypy/dist/pypy/jit/test/test_hint_annotation.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_annotation.py (original)
+++ pypy/dist/pypy/jit/test/test_hint_annotation.py Tue Mar 21 18:29:42 2006
@@ -329,6 +329,33 @@
assert isinstance(hs1, SomeLLAbstractContainer)
assert hs1.contentdef.degenerated
+def test_degenerated_merge_cross_substructure():
+ from pypy.rpython import objectmodel
+ S = lltype.Struct('S', ('n', lltype.Signed))
+ T = lltype.GcStruct('T', ('s', S), ('s1', S), ('n', lltype.Float))
+
+ def ll_function(flag):
+ t = lltype.malloc(T)
+ t.s.n = 3
+ t.s1.n = 3
+ if flag:
+ s = t.s
+ else:
+ s = t.s1
+ objectmodel.keepalive_until_here(t)
+ return s, t
+ hs = hannotate(ll_function, [bool])
+ assert isinstance(hs, SomeLLAbstractContainer)
+ assert not hs.contentdef.degenerated
+ assert len(hs.contentdef.fields) == 2
+ hs0 = hs.contentdef.fields['item0'].s_value # 's'
+ assert isinstance(hs0, SomeLLAbstractContainer)
+ assert hs0.contentdef.degenerated
+ hs1 = hs.contentdef.fields['item1'].s_value # 't'
+ assert isinstance(hs1, SomeLLAbstractContainer)
+ assert hs1.contentdef.degenerated
+
+
def test_simple_fixed_call():
def ll_help(cond, x, y):
if cond:
More information about the Pypy-commit
mailing list