Commit 31afacaf authored by Ronan Lamy's avatar Ronan Lamy
Browse files

merge branch unify-call-ops

......@@ -11,3 +11,4 @@ Annotator cleanups
.. branch: release-2.3.x
.. branch: unify-call-ops
......@@ -18,7 +18,7 @@ from rpython.annotator.listdef import ListDef, ListItem
from rpython.annotator.dictdef import DictDef
from rpython.annotator import description
from rpython.annotator.signature import annotationoftype
from rpython.annotator.argument import simple_args, complex_args
from rpython.annotator.argument import simple_args
from rpython.rlib.objectmodel import r_dict, Symbolic
from rpython.tool.algo.unionfind import UnionFind
from rpython.rtyper import extregistry
......@@ -103,8 +103,9 @@ class Bookkeeper(object):
self.consider_call_site(call_op)
for pbc, args_s in self.emulated_pbc_calls.itervalues():
self.consider_call_site_for_pbc(pbc, 'simple_call',
args_s, s_ImpossibleValue, None)
args = simple_args(args_s)
self.consider_call_site_for_pbc(pbc, args,
s_ImpossibleValue, None)
self.emulated_pbc_calls = {}
finally:
self.leave()
......@@ -152,16 +153,16 @@ class Bookkeeper(object):
args_s = [lltype_to_annotation(adtmeth.ll_ptrtype)] + args_s
if isinstance(s_callable, SomePBC):
s_result = binding(call_op.result, s_ImpossibleValue)
self.consider_call_site_for_pbc(s_callable, call_op.opname, args_s,
args = call_op.build_args(args_s)
self.consider_call_site_for_pbc(s_callable, args,
s_result, call_op)
def consider_call_site_for_pbc(self, s_callable, opname, args_s, s_result,
def consider_call_site_for_pbc(self, s_callable, args, s_result,
call_op):
descs = list(s_callable.descriptions)
if not descs:
return
family = descs[0].getcallfamily()
args = self.build_args(opname, args_s)
s_callable.getKind().consider_call_site(self, family, descs, args,
s_result, call_op)
......@@ -562,12 +563,6 @@ class Bookkeeper(object):
assert self.annotator.binding(op.args[pos]) == s_type
return op
def build_args(self, op, args_s):
if op == "simple_call":
return simple_args(args_s)
elif op == "call_args":
return complex_args(args_s)
def ondegenerated(self, what, s_value, where=None, called_from_graph=None):
self.annotator.ondegenerated(what, s_value, where=where,
called_from_graph=called_from_graph)
......
......@@ -14,6 +14,7 @@ from rpython.flowspace.model import (Constant, WrapException, const, Variable,
SpaceOperation)
from rpython.flowspace.specialcase import register_flow_sc
from rpython.annotator.model import SomeTuple
from rpython.annotator.argument import ArgumentsForTranslation
from rpython.flowspace.specialcase import SPECIAL_CASES
......@@ -511,6 +512,9 @@ class SimpleCall(SingleDispatchMixin, CallOp):
return sc(ctx, *args_w)
return ctx.do_op(self)
def build_args(self, args_s):
return ArgumentsForTranslation(list(args_s))
class CallArgs(SingleDispatchMixin, CallOp):
opname = 'call_args'
......@@ -529,6 +533,10 @@ class CallArgs(SingleDispatchMixin, CallOp):
"should not call %r with keyword arguments" % (fn,))
return ctx.do_op(self)
def build_args(self, args_s):
return ArgumentsForTranslation.fromshape(args_s[0].const,
list(args_s[1:]))
# Other functions that get directly translated to SpaceOperators
func2op[type] = op.type
......
......@@ -31,7 +31,7 @@ def getsig(rtyper, graph):
getrinputs(rtyper, graph),
getrresult(rtyper, graph))
def callparse(rtyper, graph, hop, opname, r_self=None):
def callparse(rtyper, graph, hop, r_self=None):
"""Parse the arguments of 'hop' when calling the given 'graph'.
"""
rinputs = getrinputs(rtyper, graph)
......@@ -43,6 +43,7 @@ def callparse(rtyper, graph, hop, opname, r_self=None):
else:
start = 0
rinputs[0] = r_self
opname = hop.spaceop.opname
if opname == "simple_call":
arguments = ArgumentsForRtype(args_h(start))
elif opname == "call_args":
......
......@@ -183,10 +183,10 @@ class SmallFunctionSetPBCRepr(Repr):
return self.convert_desc(funcdesc)
def rtype_simple_call(self, hop):
return self.call('simple_call', hop)
return self.call(hop)
def rtype_call_args(self, hop):
return self.call('call_args', hop)
return self.call(hop)
def dispatcher(self, shape, index, argtypes, resulttype):
key = shape, index, tuple(argtypes), resulttype
......@@ -224,9 +224,9 @@ class SmallFunctionSetPBCRepr(Repr):
c_ret = self._dispatch_cache[key] = inputconst(typeOf(ll_ret), ll_ret)
return c_ret
def call(self, opname, hop):
def call(self, hop):
bk = self.rtyper.annotator.bookkeeper
args = bk.build_args(opname, hop.args_s[1:])
args = hop.spaceop.build_args(hop.args_s[1:])
s_pbc = hop.args_s[0] # possibly more precise than self.s_pbc
descs = list(s_pbc.descriptions)
vfcs = description.FunctionDesc.variant_for_call_site
......@@ -234,7 +234,7 @@ class SmallFunctionSetPBCRepr(Repr):
row_of_graphs = self.callfamily.calltables[shape][index]
anygraph = row_of_graphs.itervalues().next() # pick any witness
vlist = [hop.inputarg(self, arg=0)]
vlist += callparse.callparse(self.rtyper, anygraph, hop, opname)
vlist += callparse.callparse(self.rtyper, anygraph, hop)
rresult = callparse.getrresult(self.rtyper, anygraph)
hop.exception_is_here()
v_dispatcher = self.dispatcher(shape, index, [v.concretetype for v in vlist[1:]], rresult.lowleveltype)
......@@ -353,11 +353,6 @@ class MethodsPBCRepr(AbstractMethodsPBCRepr):
v_func = r_class.getclsfield(v_cls, self.methodname, hop.llops)
hop2 = self.add_instance_arg_to_hop(hop, call_args)
opname = 'simple_call'
if call_args:
opname = 'call_args'
hop2.forced_opname = opname
hop2.v_s_insertfirstarg(v_func, s_func) # insert 'function'
if type(hop2.args_r[0]) is SmallFunctionSetPBCRepr and type(r_func) is FunctionsPBCRepr:
......
......@@ -10,6 +10,7 @@ the tuples returned by os.stat().
from rpython.annotator import model as annmodel
from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.flowspace.model import Constant
from rpython.flowspace.operation import op
from rpython.tool.pairtype import pairtype
from rpython.rtyper.rmodel import Repr
from rpython.rtyper.rint import IntegerRepr
......@@ -36,8 +37,10 @@ class StatResultRepr(Repr):
rtyper = self.rtyper
s_index = rtyper.annotator.bookkeeper.immutablevalue(index)
hop2 = hop.copy()
hop2.forced_opname = 'getitem'
hop2.args_v = [hop2.args_v[0], Constant(index)]
spaceop = op.getitem(hop.args_v[0], Constant(index))
spaceop.result = hop.spaceop.result
hop2.spaceop = spaceop
hop2.args_v = spaceop.args
hop2.args_s = [self.s_tuple, s_index]
hop2.args_r = [self.r_tuple, rtyper.getrepr(s_index)]
return hop2.dispatch()
......@@ -87,8 +90,10 @@ class StatvfsResultRepr(Repr):
rtyper = self.rtyper
s_index = rtyper.annotator.bookkeeper.immutablevalue(index)
hop2 = hop.copy()
hop2.forced_opname = 'getitem'
hop2.args_v = [hop2.args_v[0], Constant(index)]
spaceop = op.getitem(hop.args_v[0], Constant(index))
spaceop.result = hop.result
hop2.spaceop = spaceop
hop2.args_v = spaceop.args
hop2.args_s = [self.s_tuple, s_index]
hop2.args_r = [self.r_tuple, rtyper.getrepr(s_index)]
return hop2.dispatch()
......
from rpython.flowspace.model import Constant
from rpython.flowspace.operation import op
from rpython.rtyper.error import TyperError
from rpython.rtyper.rmodel import Repr
from rpython.tool.pairtype import pairtype
......@@ -71,5 +72,7 @@ def rtypedelegate(callable, hop, revealargs=[0], revealresult=False):
s_new, r_new = r_controlled.s_real_obj, r_controlled.r_real_obj
hop2.s_result, hop2.r_result = s_new, r_new
hop2.v_s_insertfirstarg(c_meth, s_meth)
hop2.forced_opname = 'simple_call'
spaceop = op.simple_call(*hop2.args_v)
spaceop.result = hop2.spaceop.result
hop2.spaceop = spaceop
return hop2.dispatch()
......@@ -300,14 +300,14 @@ class AbstractFunctionsPBCRepr(CanBeNull, Repr):
return inputconst(typeOf(llfn), llfn)
def rtype_simple_call(self, hop):
return self.call('simple_call', hop)
return self.call(hop)
def rtype_call_args(self, hop):
return self.call('call_args', hop)
return self.call(hop)
def call(self, opname, hop):
def call(self, hop):
bk = self.rtyper.annotator.bookkeeper
args = bk.build_args(opname, hop.args_s[1:])
args = hop.spaceop.build_args(hop.args_s[1:])
s_pbc = hop.args_s[0] # possibly more precise than self.s_pbc
descs = list(s_pbc.descriptions)
vfcs = description.FunctionDesc.variant_for_call_site
......@@ -317,7 +317,7 @@ class AbstractFunctionsPBCRepr(CanBeNull, Repr):
vfn = hop.inputarg(self, arg=0)
vlist = [self.convert_to_concrete_llfn(vfn, shape, index,
hop.llops)]
vlist += callparse.callparse(self.rtyper, anygraph, hop, opname)
vlist += callparse.callparse(self.rtyper, anygraph, hop)
rresult = callparse.getrresult(self.rtyper, anygraph)
hop.exception_is_here()
if isinstance(vlist[0], Constant):
......
......@@ -650,8 +650,6 @@ RPythonTyper._registeroperations(unaryop.UNARY_OPERATIONS, binaryop.BINARY_OPERA
class HighLevelOp(object):
forced_opname = None
def __init__(self, rtyper, spaceop, exceptionlinks, llops):
self.rtyper = rtyper
self.spaceop = spaceop
......@@ -679,12 +677,11 @@ class HighLevelOp(object):
if type(value) is list: # grunt
value = value[:]
setattr(result, key, value)
result.forced_opname = self.forced_opname
return result
def dispatch(self):
rtyper = self.rtyper
opname = self.forced_opname or self.spaceop.opname
opname = self.spaceop.opname
translate_meth = getattr(rtyper, 'translate_op_' + opname,
rtyper.default_translate_operation)
return translate_meth(self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment