[pypy-commit] pypy kill-flowobjspace: move build_flow() out of FlowObjSpace
rlamy
noreply at buildbot.pypy.org
Sun Jan 27 18:14:48 CET 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: kill-flowobjspace
Changeset: r60523:ec3af57266f4
Date: 2013-01-27 01:56 +0000
http://bitbucket.org/pypy/pypy/changeset/ec3af57266f4/
Log: move build_flow() out of FlowObjSpace
diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -13,7 +13,7 @@
from rpython.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong
from rpython.rlib.rarithmetic import r_singlefloat
from rpython.rlib import objectmodel
-from rpython.flowspace.objspace import FlowObjSpace, FlowingError
+from rpython.flowspace.objspace import build_flow, FlowingError
from rpython.translator.test import snippet
@@ -40,9 +40,6 @@
class TestAnnotateTestCase:
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
def teardown_method(self, meth):
assert annmodel.s_Bool == annmodel.SomeBool()
@@ -60,7 +57,7 @@
except AttributeError:
pass
name = func.func_name
- funcgraph = self.space.build_flow(func)
+ funcgraph = build_flow(func)
funcgraph.source = inspect.getsource(func)
return funcgraph
@@ -775,7 +772,7 @@
assert isinstance(s, annmodel.SomePBC)
assert s.const == myobj
- def test_cleanup_protocol(self):
+ def test_cleanup_protocol(self):
class Stuff:
def __init__(self):
self.called = False
@@ -2068,7 +2065,7 @@
s = a.build_types(f, [annmodel.SomeString(no_nul=True)])
assert isinstance(s, annmodel.SomeString)
assert s.no_nul
-
+
def test_non_none_and_none_with_isinstance(self):
class A(object):
@@ -3707,7 +3704,7 @@
def test_join_none_and_nonnull(self):
from rpython.rlib.rstring import assert_str0
-
+
def f(i):
a = str(i)
a = assert_str0(a)
@@ -3751,7 +3748,7 @@
class A(object):
def __iter__(self):
return self
-
+
def fn():
return iter(A())
@@ -3810,7 +3807,7 @@
return True
x = X()
-
+
def f(i):
if i:
x1 = x
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -84,6 +84,9 @@
# objects which should keep their SomeObjectness
not_really_const = NOT_REALLY_CONST
+ def build_flow(self, func):
+ return build_flow(func, self)
+
def is_w(self, w_one, w_two):
return self.is_true(self.is_(w_one, w_two))
@@ -262,28 +265,6 @@
w_type = w_instclass
return FSException(w_type, w_value)
- def build_flow(self, func):
- """
- """
- _assert_rpythonic(func)
- code = HostCode._from_code(func.func_code)
- if (code.is_generator and
- not hasattr(func, '_generator_next_method_of_')):
- graph = PyGraph(func, code)
- block = graph.startblock
- for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
- if isinstance(w_value, Variable):
- w_value.rename(name)
- return bootstrap_generator(graph)
- graph = PyGraph(func, code)
- frame = self.frame = FlowSpaceFrame(self, graph, code)
- frame.build_flow()
- fixeggblocks(graph)
- checkgraph(graph)
- if code.is_generator:
- tweak_generator_graph(graph)
- return graph
-
def unpackiterable(self, w_iterable, expected_length=None):
if not isinstance(w_iterable, Variable):
l = list(self.unwrap(w_iterable))
@@ -555,6 +536,29 @@
setattr(FlowObjSpace, name, generic_operator)
-
for (name, symbol, arity, specialnames) in operation.MethodTable:
make_op(name, arity)
+
+
+def build_flow(func, space=FlowObjSpace()):
+ """
+ Create the flow graph for the function.
+ """
+ _assert_rpythonic(func)
+ code = HostCode._from_code(func.func_code)
+ if (code.is_generator and
+ not hasattr(func, '_generator_next_method_of_')):
+ graph = PyGraph(func, code)
+ block = graph.startblock
+ for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
+ if isinstance(w_value, Variable):
+ w_value.rename(name)
+ return bootstrap_generator(graph)
+ graph = PyGraph(func, code)
+ frame = space.frame = FlowSpaceFrame(space, graph, code)
+ frame.build_flow()
+ fixeggblocks(graph)
+ checkgraph(graph)
+ if code.is_generator:
+ tweak_generator_graph(graph)
+ return graph
diff --git a/rpython/flowspace/test/test_framestate.py b/rpython/flowspace/test/test_framestate.py
--- a/rpython/flowspace/test/test_framestate.py
+++ b/rpython/flowspace/test/test_framestate.py
@@ -6,9 +6,6 @@
from rpython.flowspace.pygraph import PyGraph
class TestFrameState:
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
def getframe(self, func):
try:
func = func.im_func
@@ -16,7 +13,7 @@
pass
code = HostCode._from_code(func.func_code)
graph = PyGraph(func, code)
- frame = FlowSpaceFrame(self.space, graph, code)
+ frame = FlowSpaceFrame(FlowObjSpace(), graph, code)
# hack the frame
frame.setstate(graph.startblock.framestate)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(None)
diff --git a/rpython/flowspace/test/test_generator.py b/rpython/flowspace/test/test_generator.py
--- a/rpython/flowspace/test/test_generator.py
+++ b/rpython/flowspace/test/test_generator.py
@@ -1,5 +1,5 @@
from rpython.conftest import option
-from rpython.flowspace.objspace import FlowObjSpace
+from rpython.flowspace.objspace import build_flow
from rpython.flowspace.model import Variable
from rpython.flowspace.generator import (make_generatoriterator_class,
replace_graph_with_bootstrap, get_variable_names, attach_next_method)
@@ -67,7 +67,7 @@
yield n
yield n
#
- graph = FlowObjSpace().build_flow(func)
+ graph = build_flow(func)
if option.view:
graph.show()
block = graph.startblock
@@ -93,8 +93,7 @@
yield n + 1
z -= 10
#
- space = FlowObjSpace()
- graph = space.build_flow(f)
+ graph = build_flow(f)
GeneratorIterator = make_generatoriterator_class(graph)
replace_graph_with_bootstrap(GeneratorIterator, graph)
func1 = attach_next_method(GeneratorIterator, graph)
@@ -104,12 +103,12 @@
assert func1._generator_next_method_of_ is GeneratorIterator
assert hasattr(GeneratorIterator, 'next')
#
- graph_next = space.build_flow(GeneratorIterator.next.im_func)
+ graph_next = build_flow(GeneratorIterator.next.im_func)
join_blocks(graph_next)
if option.view:
graph_next.show()
#
- graph1 = space.build_flow(func1)
+ graph1 = build_flow(func1)
if option.view:
graph1.show()
@@ -119,7 +118,7 @@
yield n + 1
z -= 10
#
- graph = FlowObjSpace().build_flow(f)
+ graph = build_flow(f)
if option.view:
graph.show()
block = graph.startblock
diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -5,7 +5,7 @@
from rpython.flowspace.model import Constant, mkentrymap, c_last_exception
from rpython.translator.simplify import simplify_graph
-from rpython.flowspace.objspace import FlowObjSpace
+from rpython.flowspace.objspace import build_flow
from rpython.flowspace.flowcontext import FlowingError, FlowSpaceFrame
from rpython.conftest import option
from rpython.tool.stdlib_opcode import host_bytecode_spec
@@ -34,7 +34,7 @@
except AttributeError:
pass
#name = func.func_name
- graph = self.space.build_flow(func, **kwds)
+ graph = build_flow(func, **kwds)
graph.source = inspect.getsource(func)
self.show(graph)
return graph
@@ -43,9 +43,6 @@
if option.view:
graph.show()
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
def all_operations(self, graph):
result = {}
for node in graph.iterblocks():
@@ -740,7 +737,7 @@
def test_relative_import(self):
def f():
- from ..test.test_objspace import FlowObjSpace
+ from ..objspace import build_flow
# Check that the function works in Python
assert f() is None
self.codetest(f)
diff --git a/rpython/rlib/test/test_nonconst.py b/rpython/rlib/test/test_nonconst.py
--- a/rpython/rlib/test/test_nonconst.py
+++ b/rpython/rlib/test/test_nonconst.py
@@ -4,7 +4,6 @@
from rpython.rlib.nonconst import NonConstant
-from rpython.flowspace.objspace import FlowObjSpace
from rpython.annotator.annrpython import RPythonAnnotator
from rpython.conftest import option
from rpython.annotator.model import SomeInstance
@@ -13,20 +12,20 @@
def nonconst_f():
a = NonConstant(3)
return a
-
+
a = RPythonAnnotator()
s = a.build_types(nonconst_f, [])
assert s.knowntype is int
assert not hasattr(s, 'const')
#rtyper = a.translator.buildrtyper(type_system="ootype")
#rtyper.specialize()
-
+
def test_nonconst_list():
def nonconst_l():
a = NonConstant([1, 2, 3])
return a[0]
-
+
a = RPythonAnnotator()
s = a.build_types(nonconst_l, [])
assert s.knowntype is int
@@ -36,7 +35,7 @@
class A:
pass
a = A()
-
+
def nonconst_i():
return NonConstant(a)
@@ -51,9 +50,9 @@
def test_bool_nonconst():
def fn():
return bool(NonConstant(False))
-
+
assert not fn()
-
+
a = RPythonAnnotator()
s = a.build_types(fn, [])
assert s.knowntype is bool
diff --git a/rpython/rtyper/ootypesystem/test/test_ooann.py b/rpython/rtyper/ootypesystem/test/test_ooann.py
--- a/rpython/rtyper/ootypesystem/test/test_ooann.py
+++ b/rpython/rtyper/ootypesystem/test/test_ooann.py
@@ -1,7 +1,6 @@
import py
from rpython.rtyper.ootypesystem.ootype import *
from rpython.annotator import model as annmodel
-from rpython.flowspace.objspace import FlowObjSpace
from rpython.annotator.annrpython import RPythonAnnotator
import exceptions
from rpython.rtyper.ootypesystem import ooregistry # side effects
@@ -9,7 +8,7 @@
def test_simple_new():
C = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
c = new(C)
c.a = 5
@@ -23,7 +22,7 @@
def test_simple_instanceof():
C = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
c = new(C)
return instanceof(c, C)
@@ -36,7 +35,7 @@
def test_simple_null():
I = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
i = null(I)
return i
@@ -49,7 +48,7 @@
def test_simple_classof():
I = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
i = new(I)
return classof(i)
@@ -62,8 +61,8 @@
def test_subclassof():
I = Instance("test", ROOT, {'a': Signed})
- I1 = Instance("test1", I)
-
+ I1 = Instance("test1", I)
+
def oof():
i = new(I)
i1 = new(I1)
@@ -77,7 +76,7 @@
def test_simple_runtimenew():
I = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
i = new(I)
c = classof(i)
@@ -94,7 +93,7 @@
I = Instance("test", ROOT, {'a': Signed})
J = Instance("test2", I, {'b': Signed})
K = Instance("test2", I, {'b': Signed})
-
+
def oof(x):
k = new(K)
j = new(J)
@@ -124,7 +123,7 @@
def oof():
c = new(C)
return c.m(c)
-
+
a = RPythonAnnotator()
s = a.build_types(oof, [])
# a.translator.view()
@@ -152,7 +151,7 @@
def test_record():
R = Record({'foo': Signed})
r = new(R)
-
+
def oof():
return r
@@ -184,7 +183,7 @@
a = RPythonAnnotator()
s = a.build_types(oof, [])
-
+
assert s == annmodel.SomeOOStaticMeth(F)
def test_truth_value():
@@ -285,7 +284,7 @@
return a
a = RPythonAnnotator()
assert isinstance(a.build_types(f, []), annmodel.SomeFloat)
-
+
def test_overload_reannotate_unrelated():
py.test.skip("Maybe we want this to work")
# this test fails because the result type of c.foo(mylist[0])
diff --git a/rpython/rtyper/ootypesystem/test/test_oortype.py b/rpython/rtyper/ootypesystem/test/test_oortype.py
--- a/rpython/rtyper/ootypesystem/test/test_oortype.py
+++ b/rpython/rtyper/ootypesystem/test/test_oortype.py
@@ -5,7 +5,6 @@
from rpython.rtyper.ootypesystem.rlist import ListRepr
from rpython.rtyper.rint import signed_repr
from rpython.annotator import model as annmodel
-from rpython.flowspace.objspace import FlowObjSpace
from rpython.translator.translator import TranslationContext, graphof
from rpython.rtyper.test.test_llinterp import interpret
from rpython.rlib.objectmodel import r_dict
@@ -25,7 +24,7 @@
def test_simple_class():
C = Instance("test", ROOT, {'a': Signed})
-
+
def f():
c = new(C)
return c
@@ -33,10 +32,10 @@
g = gengraph(f)
rettype = g.getreturnvar().concretetype
assert rettype == C
-
+
def test_simple_field():
C = Instance("test", ROOT, {'a': (Signed, 3)})
-
+
def f():
c = new(C)
c.a = 5
@@ -45,7 +44,7 @@
g = gengraph(f)
rettype = g.getreturnvar().concretetype
assert rettype == Signed
-
+
def test_simple_method():
C = Instance("test", ROOT, {'a': (Signed, 3)})
M = Meth([], Signed)
@@ -53,7 +52,7 @@
return self.a
m = meth(M, _name="m", _callable=m_)
addMethods(C, {"m": m})
-
+
def f():
c = new(C)
return c.m()
@@ -83,7 +82,7 @@
def test_simple_classof():
I = Instance("test", ROOT, {'a': Signed})
-
+
def oof():
i = new(I)
return classof(i)
@@ -94,8 +93,8 @@
def test_subclassof():
I = Instance("test", ROOT, {'a': Signed})
- I1 = Instance("test1", I)
-
+ I1 = Instance("test1", I)
+
def oof():
i = new(I)
i1 = new(I1)
@@ -171,7 +170,7 @@
class A:
def method(self, number):
return number + 2
-
+
def oof():
a = A()
return a.method(3)
@@ -188,8 +187,8 @@
t.view()
rtyper = t.buildrtyper(type_system="ootype")
rtyper.specialize()
- graph = graphof(t, f)
-
+ graph = graphof(t, f)
+
INST = graph.getreturnvar().concretetype
assert rtyper.exceptiondata.is_exception_instance(INST)
@@ -297,7 +296,7 @@
def oof():
return r.foo
-
+
res = interpret(oof, [], type_system='ootype')
assert res == 42
@@ -347,7 +346,7 @@
lst = L.ll_newlist(1)
lst.ll_setitem_fast(0, 42)
return wrapper(lst, 0)
-
+
res = interpret(fn, [], type_system='ootype')
assert res == 42
diff --git a/rpython/rtyper/test/test_llann.py b/rpython/rtyper/test/test_llann.py
--- a/rpython/rtyper/test/test_llann.py
+++ b/rpython/rtyper/test/test_llann.py
@@ -2,7 +2,6 @@
from rpython.annotator import model as annmodel
from rpython.conftest import option
-from rpython.flowspace.objspace import FlowObjSpace
from rpython.rtyper.annlowlevel import (annotate_lowlevel_helper,
MixLevelHelperAnnotator, PseudoHighLevelCallable, llhelper,
cast_instance_to_base_ptr, cast_base_ptr_to_instance, base_ptr_lltype)
@@ -31,9 +30,6 @@
class TestLowLevelAnnotateTestCase:
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
from rpython.annotator.annrpython import RPythonAnnotator
def annotate(self, ll_function, argtypes):
diff --git a/rpython/translator/tool/make_dot.py b/rpython/translator/tool/make_dot.py
--- a/rpython/translator/tool/make_dot.py
+++ b/rpython/translator/tool/make_dot.py
@@ -1,7 +1,7 @@
import os
import inspect, linecache
from rpython.flowspace.model import *
-from rpython.flowspace.objspace import FlowObjSpace as Space
+from rpython.flowspace.objspace import build_flow
from rpython.tool.udir import udir
from py.process import cmdexec
from rpython.tool.error import offset2lineno
@@ -44,9 +44,9 @@
def leave_subgraph(self):
self.emit("}")
- def emit_edge(self, name1, name2, label="",
- style="dashed",
- color="black",
+ def emit_edge(self, name1, name2, label="",
+ style="dashed",
+ color="black",
dir="forward",
weight="5",
ports=None,
@@ -61,11 +61,11 @@
else:
self.emit('%s -> %s' % (safename(name1), safename(name2)))
- def emit_node(self, name,
- shape="diamond",
- label="",
+ def emit_node(self, name,
+ shape="diamond",
+ label="",
color="black",
- fillcolor="white",
+ fillcolor="white",
style="filled",
width="0.75",
):
@@ -134,7 +134,7 @@
data = "BROKEN BLOCK\\n%r" % (block,)
self.emit_node(name, label=data)
return
-
+
lines = []
for op in block.operations:
lines.extend(repr(op).split('\n'))
@@ -247,6 +247,5 @@
i += 1
return i
- space = Space()
- graph = space.build_flow(f)
+ graph = build_flow(f)
make_dot('f', graph)
diff --git a/rpython/translator/translator.py b/rpython/translator/translator.py
--- a/rpython/translator/translator.py
+++ b/rpython/translator/translator.py
@@ -8,7 +8,7 @@
from rpython.translator import simplify
from rpython.flowspace.model import FunctionGraph, checkgraph, Block
-from rpython.flowspace.objspace import FlowObjSpace
+from rpython.flowspace.objspace import build_flow
from rpython.tool.ansi_print import ansi_log
from rpython.tool.sourcetools import nice_repr_for_func
from rpython.config.translationoption import get_combined_translation_config
@@ -52,8 +52,7 @@
else:
if self.config.translation.verbose:
log.start(nice_repr_for_func(func))
- space = FlowObjSpace()
- graph = space.build_flow(func)
+ graph = build_flow(func)
if self.config.translation.simplifying:
simplify.simplify_graph(graph)
if self.config.translation.list_comprehension_operations:
More information about the pypy-commit
mailing list