[pypy-svn] r70314 - in pypy/branch/jit-delayed-write/pypy: rpython rpython/test translator/backendopt/test
arigo at codespeak.net
arigo at codespeak.net
Mon Dec 28 22:03:09 CET 2009
Author: arigo
Date: Mon Dec 28 22:03:08 2009
New Revision: 70314
Modified:
pypy/branch/jit-delayed-write/pypy/rpython/rptr.py
pypy/branch/jit-delayed-write/pypy/rpython/test/test_rptr.py
pypy/branch/jit-delayed-write/pypy/translator/backendopt/test/test_writeanalyze.py
Log:
Don't generate a dummy "Void=getfield(p,'name')"
for all ADT fields 'name'. It's in principle wrong
because 'name' is not the name of a field, although
it did not show up so far because it's always a Void.
Added a test to test_writeanalyze that shows in which
situation the issue caused a problem.
Modified: pypy/branch/jit-delayed-write/pypy/rpython/rptr.py
==============================================================================
--- pypy/branch/jit-delayed-write/pypy/rpython/rptr.py (original)
+++ pypy/branch/jit-delayed-write/pypy/rpython/rptr.py Mon Dec 28 22:03:08 2009
@@ -39,6 +39,14 @@
attr = hop.args_s[1].const
if isinstance(hop.s_result, annmodel.SomeLLADTMeth):
return hop.inputarg(hop.r_result, arg=0)
+ try:
+ self.lowleveltype._example()._lookup_adtmeth(attr)
+ except AttributeError:
+ pass
+ else:
+ assert hop.s_result.is_constant()
+ return hop.inputconst(hop.r_result, hop.s_result.const)
+ assert attr in self.lowleveltype.TO._flds # check that the field exists
FIELD_TYPE = getattr(self.lowleveltype.TO, attr)
if isinstance(FIELD_TYPE, lltype.ContainerType):
if (attr, FIELD_TYPE) == self.lowleveltype.TO._first_struct():
Modified: pypy/branch/jit-delayed-write/pypy/rpython/test/test_rptr.py
==============================================================================
--- pypy/branch/jit-delayed-write/pypy/rpython/test/test_rptr.py (original)
+++ pypy/branch/jit-delayed-write/pypy/rpython/test/test_rptr.py Mon Dec 28 22:03:08 2009
@@ -337,3 +337,13 @@
return f([1])
s, t = ll_rtype(lltest, [])
assert s.is_constant() == False
+
+def test_staticadtmeths():
+ ll_func = staticAdtMethod(lambda x: x + 42)
+ S = GcStruct('S', adtmeths={'ll_func': ll_func})
+ def f():
+ return malloc(S).ll_func(5)
+ s, t = ll_rtype(f, [])
+ graphf = t.graphs[0]
+ for op in graphf.startblock.operations:
+ assert op.opname != 'getfield'
Modified: pypy/branch/jit-delayed-write/pypy/translator/backendopt/test/test_writeanalyze.py
==============================================================================
--- pypy/branch/jit-delayed-write/pypy/translator/backendopt/test/test_writeanalyze.py (original)
+++ pypy/branch/jit-delayed-write/pypy/translator/backendopt/test/test_writeanalyze.py Mon Dec 28 22:03:08 2009
@@ -306,3 +306,26 @@
ARRAYPTR = list(result)[0][1]
assert list(result) == [("readarray", ARRAYPTR)]
assert isinstance(ARRAYPTR.TO, lltype.GcArray)
+
+ def test_adt_method(self):
+ def ll_callme(n):
+ return n
+ ll_callme = lltype.staticAdtMethod(ll_callme)
+ S = lltype.GcStruct('S', ('x', lltype.Signed),
+ adtmeths = {'yep': True,
+ 'callme': ll_callme})
+ def g(x, y, z):
+ p = lltype.malloc(S)
+ p.x = x
+ if p.yep:
+ z *= p.callme(y)
+ return z
+ def f(x, y, z):
+ return g(x, y, z)
+
+ t, wa = self.translate(f, [int, int, int])
+ fgraph = graphof(t, f)
+ assert fgraph.startblock.operations[-1].opname == 'direct_call'
+
+ result = wa.analyze(fgraph.startblock.operations[-1])
+ assert list(result) == [("struct", lltype.Ptr(S), "x")]
More information about the Pypy-commit
mailing list