def test_cancollect_external(): fext1 = rffi.llexternal('fext1', [], lltype.Void, threadsafe=False) def g(): fext1() t = rtype(g, []) gg = graphof(t, g) assert not CollectAnalyzer(t).analyze_direct_call(gg) fext2 = rffi.llexternal('fext2', [], lltype.Void, threadsafe=True) def g(): fext2() t = rtype(g, []) gg = graphof(t, g) assert CollectAnalyzer(t).analyze_direct_call(gg) S = lltype.GcStruct('S', ('x', lltype.Signed)) FUNC = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Void)) fext3 = rffi.llexternal('fext3', [FUNC], lltype.Void, threadsafe=False) def h(x): lltype.malloc(S, zero=True) def g(): fext3(h) t = rtype(g, []) gg = graphof(t, g) assert CollectAnalyzer(t).analyze_direct_call(gg)
def test_cancollect_stack_check(): from pypy.rlib import rstack def with_check(): rstack.stack_check() t = rtype(with_check, []) with_check_graph = graphof(t, with_check) assert not t.config.translation.stackless can_collect = CollectAnalyzer(t).analyze_direct_call(with_check_graph) assert not can_collect t.config.translation.stackless = True can_collect = CollectAnalyzer(t).analyze_direct_call(with_check_graph) assert can_collect
def test_cancollect(): S = lltype.GcStruct('S', ('x', lltype.Signed)) def g(): lltype.malloc(S, zero=True) t = rtype(g, []) gg = graphof(t, g) assert CollectAnalyzer(t).analyze_direct_call(gg) def g(x): return -x t = rtype(g, [int]) gg = graphof(t, g) assert not CollectAnalyzer(t).analyze_direct_call(gg)
def test_find_initializing_stores_across_blocks(): class A(object): pass class B(object): pass def f(x): a1 = A() a2 = A() a = A() b = B() b.a = a if x: b.b = a1 b.c = a2 else: b.c = a1 b.b = a2 t = rtype(f, [int]) etrafo = ExceptionTransformer(t) graphs = etrafo.transform_completely() collect_analyzer = CollectAnalyzer(t) init_stores = find_initializing_stores(collect_analyzer, t.graphs[0]) assert len(init_stores) == 5
def test_list_operations(): class A(object): pass def f(): l = [A(), A()] l.append(A()) l[1] = l[0] return len(l) t = rtype(f, []) backend_optimizations(t, clever_malloc_removal=False, storesink=True) etrafo = ExceptionTransformer(t) graph = etrafo.transform_completely() collect_analyzer = CollectAnalyzer(t) clean_setarrayitems = find_clean_setarrayitems(collect_analyzer, t.graphs[0]) assert len(clean_setarrayitems) == 1
def test_find_initializing_stores(): class A(object): pass class B(object): pass def f(): a = A() b = B() b.a = a b.b = 1 t = rtype(f, []) etrafo = ExceptionTransformer(t) graphs = etrafo.transform_completely() collect_analyzer = CollectAnalyzer(t) init_stores = find_initializing_stores(collect_analyzer, t.graphs[0]) assert len(init_stores) == 1
def test_find_clean_setarrayitems(): S = lltype.GcStruct('S') A = lltype.GcArray(lltype.Ptr(S)) def f(): l = lltype.malloc(A, 3) l[0] = lltype.malloc(S) l[1] = lltype.malloc(S) l[2] = lltype.malloc(S) x = l[1] l[0] = x return len(l) t = rtype(f, []) etrafo = ExceptionTransformer(t) graph = etrafo.transform_completely() collect_analyzer = CollectAnalyzer(t) clean_setarrayitems = find_clean_setarrayitems(collect_analyzer, t.graphs[0]) assert len(clean_setarrayitems) == 1