[pypy-svn] r49898 - in pypy/dist/pypy: jit/hintannotator jit/hintannotator/test translator
antocuni at codespeak.net
antocuni at codespeak.net
Tue Dec 18 18:58:12 CET 2007
Author: antocuni
Date: Tue Dec 18 18:58:11 2007
New Revision: 49898
Modified:
pypy/dist/pypy/jit/hintannotator/model.py
pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
pypy/dist/pypy/translator/simplify.py
Log:
- add some new tests that calls methods instead of functions, to make them test oosend in ootype
- make these tests passing
Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py (original)
+++ pypy/dist/pypy/jit/hintannotator/model.py Tue Dec 18 18:58:11 2007
@@ -3,7 +3,7 @@
from pypy.jit.hintannotator.bookkeeper import getbookkeeper
from pypy.rpython.lltypesystem import lltype, lloperation
from pypy.rpython.ootypesystem import ootype
-from pypy.translator.simplify import get_funcobj
+from pypy.translator.simplify import get_funcobj, get_functype
UNARY_OPERATIONS = """same_as hint getfield setfield getsubstruct getarraysize
getinteriorfield getinteriorarraysize setinteriorfield
@@ -107,6 +107,13 @@
retdeps.append(v_callable)
elif self.spaceop.opname == 'oosend':
args = self.spaceop.args[1:]
+ methname = self.spaceop.args[0].value
+ TYPE = self.spaceop.args[1].concretetype
+ graphs = TYPE._lookup_graphs(methname)
+ if len(graphs) > 1:
+ v_self = self.spaceop.args[1]
+ retdeps = greenorigindependencies.setdefault(self, [])
+ retdeps.append(v_self)
else:
raise AssertionError(self.spaceop.opname)
@@ -174,7 +181,6 @@
c.__dict__.update(self.__dict__)
return c
-
class SomeLLAbstractConstant(SomeLLAbstractValue):
" color: dont know yet.. "
@@ -409,9 +415,13 @@
args_hs = args_hs[:-1]
assert hs_graph_list.is_constant()
graph_list = hs_graph_list.const
+ FUNC = get_functype(hs_v1.concretetype)
+ return hs_v1._call_multiple_graphs(graph_list, FUNC.RESULT, *args_hs)
+
+ def _call_multiple_graphs(hs_v1, graph_list, RESULT, *args_hs):
if graph_list is None:
# cannot follow indirect calls to unknown targets
- return variableoftype(hs_v1.concretetype.TO.RESULT)
+ return variableoftype(RESULT)
bookkeeper = getbookkeeper()
myorigin = bookkeeper.myorigin()
@@ -430,12 +440,9 @@
# function
return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
- def oosend(hs_v1, hs_name, *args_hs):
+ def oosend(hs_v1, hs_name, *args_hs):
RESTYPE = getbookkeeper().current_op_concretetype()
- if RESTYPE is not ootype.Void:
- return SomeLLAbstractVariable(RESTYPE)
- else:
- return # XXX: is it right?
+ return variableoftype(RESTYPE)
class __extend__(SomeLLAbstractConstant):
@@ -494,14 +501,8 @@
myorigin.any_called_graph = tsgraphs_accum[0]
if isinstance(hs_res, SomeLLAbstractConstant):
- hs_res.myorigin = myorigin
+ hs_res.myorigin = myorigin
-## elif fnobj.graph.name.startswith('ll_stritem'):
-## if isinstance(hs_res, SomeLLAbstractVariable):
-## print hs_res
-## import pdb; pdb.set_trace()
-
-
# we need to make sure that hs_res does not become temporarily less
# general as a result of calling another specialized version of the
# function
@@ -511,13 +512,14 @@
TYPE = hs_c1.concretetype
name = hs_name.const
_, meth = TYPE._lookup(name)
+ METH = lltype.typeOf(meth)
graph_list = TYPE._lookup_graphs(name)
if not graph_list:
# it's a method of a BuiltinType
bk = getbookkeeper()
origin = bk.myorigin()
d = setadd(hs_c1.origins, origin)
- RESTYPE = bk.current_op_concretetype()
+ RESTYPE = bk.current_op_concretetype()
hs_res = SomeLLAbstractConstant(RESTYPE, d,
eager_concrete = hs_c1.eager_concrete,
myorigin = origin)
@@ -526,11 +528,10 @@
elif len(graph_list) == 1:
# like a direct_call
graph = graph_list.pop()
- METH = lltype.typeOf(meth)
return hs_c1._call_single_graph(graph, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args
else:
# like an indirect_call
- XXX-fixme
+ return hs_c1._call_multiple_graphs(graph_list, METH.RESULT, hs_c1, *args_hs)
def getfield(hs_c1, hs_fieldname):
S = hs_c1.concretetype.TO
Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py Tue Dec 18 18:58:11 2007
@@ -335,6 +335,18 @@
assert hs.concretetype == lltype.Signed
assert len(hs.origins) == 5
+ def test_simple_method_call_var(self):
+ class A:
+ def ll2(self, x, y, z):
+ return x + (y + 42)
+ def ll1(x, y, z):
+ obj = A()
+ return obj.ll2(x, y - z, x + y + z)
+ hs = self.hannotate(ll1, [int, int, int], policy=P_NOVIRTUAL)
+ assert isinstance(hs, SomeLLAbstractConstant)
+ assert hs.concretetype == lltype.Signed
+ assert len(hs.origins) == 5
+
def test_simple_list_operations(self):
def ll_function(x, y, index):
l = [x]
@@ -705,6 +717,23 @@
hs = self.hannotate(ll_function, [int, int], policy=P_NOVIRTUAL)
assert not hs.is_green()
+ def test_indirect_method_yellow_call(self):
+ class A:
+ def h1(self, n):
+ return 123
+
+ class B(A):
+ def h1(self, n):
+ return 456
+
+ lst = [A(), B()]
+
+ def ll_function(n, m):
+ obj = hint(lst, deepfreeze=True)[m]
+ return obj.h1(n)
+ hs = self.hannotate(ll_function, [int, int], policy=P_NOVIRTUAL)
+ assert not hs.is_green()
+
def test_indirect_sometimes_residual_pure_red_call(self):
def h1(x):
return x-2
@@ -1040,3 +1069,6 @@
f = Foo()
f.bar()
hs = self.hannotate(fn, [], policy=P_OOPSPEC_NOVIRTUAL)
+
+ def test_simple_method_call_var(self):
+ py.test.skip('fixme!')
Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py (original)
+++ pypy/dist/pypy/translator/simplify.py Tue Dec 18 18:58:11 2007
@@ -10,7 +10,8 @@
from pypy.objspace.flow.model import Variable, Constant, Block, Link
from pypy.objspace.flow.model import c_last_exception
from pypy.objspace.flow.model import checkgraph, traverse, mkentrymap
-from pypy.rpython.lltypesystem import lloperation
+from pypy.rpython.lltypesystem import lloperation, lltype
+from pypy.rpython.ootypesystem import ootype
def get_funcobj(func):
"""
@@ -21,6 +22,12 @@
else:
return func # ootypesystem
+def get_functype(TYPE):
+ if isinstance(TYPE, lltype.Ptr):
+ return TYPE.TO
+ elif isinstance(TYPE, ootype.StaticMethod):
+ return TYPE
+ assert False
def get_graph(arg, translator):
from pypy.translator.translator import graphof
More information about the pypy-svn
mailing list