Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r65360:d1430383faa5 Date: 2013-07-12 09:19 +1000 http://bitbucket.org/pypy/pypy/changeset/d1430383faa5/
Log: A failing (xfail) test for VirtualizableAnalyzer with indirect construction of an object. diff --git a/rpython/jit/codewriter/test/test_effectinfo.py b/rpython/jit/codewriter/test/test_effectinfo.py --- a/rpython/jit/codewriter/test/test_effectinfo.py +++ b/rpython/jit/codewriter/test/test_effectinfo.py @@ -1,15 +1,22 @@ +import pytest + +from rpython.jit.codewriter.effectinfo import (effectinfo_from_writeanalyze, + EffectInfo, VirtualizableAnalyzer) +from rpython.rlib import jit +from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.rclass import OBJECT -from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.ootypesystem import ootype -from rpython.jit.codewriter.effectinfo import effectinfo_from_writeanalyze,\ - EffectInfo +from rpython.translator.translator import TranslationContext, graphof -class FakeCPU: + +class FakeCPU(object): def fielddescrof(self, T, fieldname): return ('fielddescr', T, fieldname) + def arraydescrof(self, A): return ('arraydescr', A) + def test_no_oopspec_duplicate(): # check that all the various EffectInfo.OS_* have unique values oopspecs = set() @@ -18,6 +25,7 @@ assert value not in oopspecs oopspecs.add(value) + def test_include_read_field(): S = lltype.GcStruct("S", ("a", lltype.Signed)) effects = frozenset([("readstruct", lltype.Ptr(S), "a")]) @@ -26,6 +34,7 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_include_write_field(): S = lltype.GcStruct("S", ("a", lltype.Signed)) effects = frozenset([("struct", lltype.Ptr(S), "a")]) @@ -34,6 +43,7 @@ assert not effectinfo.readonly_descrs_fields assert not effectinfo.write_descrs_arrays + def test_include_read_array(): A = lltype.GcArray(lltype.Signed) effects = frozenset([("readarray", lltype.Ptr(A))]) @@ -43,6 +53,7 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_include_write_array(): A = lltype.GcArray(lltype.Signed) effects = frozenset([("array", lltype.Ptr(A))]) @@ -51,6 +62,7 @@ assert not effectinfo.write_descrs_fields assert list(effectinfo.write_descrs_arrays) == [('arraydescr', A)] + def test_dont_include_read_and_write_field(): S = lltype.GcStruct("S", ("a", lltype.Signed)) effects = frozenset([("readstruct", lltype.Ptr(S), "a"), @@ -60,6 +72,7 @@ assert list(effectinfo.write_descrs_fields) == [('fielddescr', S, "a")] assert not effectinfo.write_descrs_arrays + def test_dont_include_read_and_write_array(): A = lltype.GcArray(lltype.Signed) effects = frozenset([("readarray", lltype.Ptr(A)), @@ -78,6 +91,7 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_filter_out_array_of_void(): effects = frozenset([("array", lltype.Ptr(lltype.GcArray(lltype.Void)))]) effectinfo = effectinfo_from_writeanalyze(effects, None) @@ -85,6 +99,7 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_filter_out_struct_with_void(): effects = frozenset([("struct", lltype.Ptr(lltype.GcStruct("x", ("a", lltype.Void))), "a")]) effectinfo = effectinfo_from_writeanalyze(effects, None) @@ -92,6 +107,7 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_filter_out_ooarray_of_void(): effects = frozenset([("array", ootype.Array(ootype.Void))]) effectinfo = effectinfo_from_writeanalyze(effects, None) @@ -99,9 +115,44 @@ assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + def test_filter_out_instance_with_void(): effects = frozenset([("struct", ootype.Instance("x", ootype.ROOT, {"a": ootype.Void}), "a")]) effectinfo = effectinfo_from_writeanalyze(effects, None) assert not effectinfo.readonly_descrs_fields assert not effectinfo.write_descrs_fields assert not effectinfo.write_descrs_arrays + + +class TestVirtualizableAnalyzer(object): + def analyze(self, func, sig): + t = TranslationContext() + t.buildannotator().build_types(func, sig) + t.buildrtyper().specialize() + fgraph = graphof(t, func) + return VirtualizableAnalyzer(t).analyze(fgraph.startblock.operations[0]) + + @pytest.mark.xfail + def test_constructor(self): + class A(object): + x = 1 + + class B(A): + x = 2 + + @jit.elidable + def g(cls): + return cls() + + def f(x): + if x: + cls = A + else: + cls = B + return g(cls).x + + def entry(x): + return f(x) + + res = self.analyze(entry, [int]) + assert not res _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit