def lowlevelspecialize(funcdesc, args_s, key_for_args): args_s, key1, builder = flatten_star_args(funcdesc, args_s) key = [] new_args_s = [] for i, s_obj in enumerate(args_s): if i in key_for_args: key.append(key_for_args[i]) new_args_s.append(s_obj) elif isinstance(s_obj, annmodel.SomePBC): assert s_obj.is_constant(), "ambiguous low-level helper specialization" key.append(KeyComp(s_obj.const)) new_args_s.append(s_obj) else: new_args_s.append(annmodel.not_const(s_obj)) try: key.append(annotation_to_lltype(s_obj)) except ValueError: # passing non-low-level types to a ll_* function is allowed # for module/ll_* key.append(s_obj.__class__) key = (tuple(key),) if key1 is not None: key += (key1,) flowgraph = funcdesc.cachedgraph(key, builder=builder) args_s[:] = new_args_s return flowgraph
def lowlevelspecialize(funcdesc, args_s, key_for_args): args_s, key1, builder = flatten_star_args(funcdesc, args_s) key = [] new_args_s = [] for i, s_obj in enumerate(args_s): if i in key_for_args: key.append(key_for_args[i]) new_args_s.append(s_obj) elif isinstance(s_obj, annmodel.SomePBC): assert s_obj.is_constant( ), "ambiguous low-level helper specialization" key.append(KeyComp(s_obj.const)) new_args_s.append(s_obj) elif isinstance(s_obj, annmodel.SomeNone): key.append(KeyComp(None)) new_args_s.append(s_obj) else: new_args_s.append(annmodel.not_const(s_obj)) try: key.append(annotation_to_lltype(s_obj)) except ValueError: # passing non-low-level types to a ll_* function is allowed # for module/ll_* key.append(s_obj.__class__) key = (tuple(key), ) if key1 is not None: key += (key1, ) flowgraph = funcdesc.cachedgraph(key, builder=builder) args_s[:] = new_args_s return flowgraph
def __call__(self, funcdesc, inputcells): from rpython.rlib.objectmodel import NOT_CONSTANT from rpython.rtyper.lltypesystem import lltype args_s = [] from rpython.annotator import model as annmodel for i, argtype in enumerate(self.argtypes): if isinstance(argtype, (types.FunctionType, types.MethodType)): argtype = argtype(*inputcells) if argtype is lltype.Void: # XXX the mapping between Void and annotation # is not quite well defined s_input = inputcells[i] assert isinstance(s_input, (annmodel.SomePBC, annmodel.SomeNone)) assert s_input.is_constant() args_s.append(s_input) elif argtype is None: args_s.append(inputcells[i]) # no change elif argtype is NOT_CONSTANT: from rpython.annotator.model import not_const args_s.append(not_const(inputcells[i])) else: args_s.append(annotation(argtype, bookkeeper=funcdesc.bookkeeper)) if len(inputcells) != len(args_s): raise SignatureError("%r: expected %d args, got %d" % (funcdesc, len(args_s), len(inputcells))) for i, (s_arg, s_input) in enumerate(zip(args_s, inputcells)): s_input = unionof(s_input, s_arg) if not s_arg.contains(s_input): raise SignatureError( "%r argument %d:\n" "expected %s,\n" " got %s" % (funcdesc, i + 1, s_arg, s_input) ) inputcells[:] = args_s
def __call__(self, funcdesc, inputcells): from rpython.rlib.objectmodel import NOT_CONSTANT from rpython.rtyper.lltypesystem import lltype args_s = [] from rpython.annotator import model as annmodel for i, argtype in enumerate(self.argtypes): if isinstance(argtype, (types.FunctionType, types.MethodType)): argtype = argtype(*inputcells) if argtype is lltype.Void: # XXX the mapping between Void and annotation # is not quite well defined s_input = inputcells[i] assert isinstance(s_input, (annmodel.SomePBC, annmodel.SomeNone)) assert s_input.is_constant() args_s.append(s_input) elif argtype is None: args_s.append(inputcells[i]) # no change elif argtype is NOT_CONSTANT: from rpython.annotator.model import not_const args_s.append(not_const(inputcells[i])) else: args_s.append( annotation(argtype, bookkeeper=funcdesc.bookkeeper)) if len(inputcells) != len(args_s): raise SignatureError("%r: expected %d args, got %d" % (funcdesc, len(args_s), len(inputcells))) for i, (s_arg, s_input) in enumerate(zip(args_s, inputcells)): s_input = unionof(s_input, s_arg) if not s_arg.contains(s_input): raise SignatureError("%r argument %d:\n" "expected %s,\n" " got %s" % (funcdesc, i + 1, s_arg, s_input)) inputcells[:] = args_s
def compute_result_annotation(self, s_x, **kwds_s): from rpython.annotator import model as annmodel s_x = annmodel.not_const(s_x) access_directly = 's_access_directly' in kwds_s fresh_virtualizable = 's_fresh_virtualizable' in kwds_s if access_directly or fresh_virtualizable: assert access_directly, "lone fresh_virtualizable hint" if isinstance(s_x, annmodel.SomeInstance): from rpython.flowspace.model import Constant classdesc = s_x.classdef.classdesc virtualizable = classdesc.read_attribute( '_virtualizable_', Constant(None)).value if virtualizable is not None: flags = s_x.flags.copy() flags['access_directly'] = True if fresh_virtualizable: flags['fresh_virtualizable'] = True s_x = annmodel.SomeInstance(s_x.classdef, s_x.can_be_None, flags) return s_x
def compute_result_annotation(self, s_x, **kwds_s): from rpython.annotator import model as annmodel s_x = annmodel.not_const(s_x) access_directly = 's_access_directly' in kwds_s fresh_virtualizable = 's_fresh_virtualizable' in kwds_s if access_directly or fresh_virtualizable: assert access_directly, "lone fresh_virtualizable hint" if isinstance(s_x, annmodel.SomeInstance): from rpython.flowspace.model import Constant classdesc = s_x.classdef.classdesc virtualizable = classdesc.get_param('_virtualizable_') if virtualizable is not None: flags = s_x.flags.copy() flags['access_directly'] = True if fresh_virtualizable: flags['fresh_virtualizable'] = True s_x = annmodel.SomeInstance(s_x.classdef, s_x.can_be_None, flags) return s_x
def compute_result_annotation(self, s_arg): return not_const(s_arg)