def op_MAKE_FUNCTION( self, inst, name, code, closure, annotations, kwdefaults, defaults, res ): if annotations is not None: raise NotImplementedError( "op_MAKE_FUNCTION with annotations is not implemented" ) if kwdefaults is not None: raise NotImplementedError( "op_MAKE_FUNCTION with kwdefaults is not implemented" ) if defaults: if isinstance(defaults, tuple): defaults = tuple([self.get(name) for name in defaults]) else: defaults = self.get(defaults) assume_code_const = self.definitions[code][0] if not isinstance(assume_code_const, ir.Const): msg = ( "Unsupported use of closure. " "Probably caused by complex control-flow constructs; " "e.g. try-except" ) raise errors.UnsupportedError(msg, loc=self.loc) fcode = assume_code_const.value if name: name = self.get(name) if closure: closure = self.get(closure) expr = ir.Expr.make_function(name, fcode, closure, defaults, self.loc) self.store(expr, res)
def _break_constant(self, const, loc): """ Break down constant exception. """ if isinstance(const, tuple): # it's a tuple(exception class, args) if not self._is_exception_type(const[0]): msg = "Encountered unsupported exception constant %r" raise errors.UnsupportedError(msg % (const[0], ), loc) return const[0], tuple(const[1]) elif self._is_exception_type(const): return const, None else: if isinstance(const, str): msg = ("Directly raising a string constant as an exception is " "not supported.") else: msg = "Encountered unsupported constant type used for exception" raise errors.UnsupportedError(msg, loc)
def _getargs(fn_sig): """ Returns list of positional and keyword argument names in order. """ params = fn_sig.parameters args = [] for k, v in params.items(): if (v.kind & v.POSITIONAL_OR_KEYWORD) == v.POSITIONAL_OR_KEYWORD: args.append(k) else: msg = "%s argument type unsupported in jitclass" % v.kind raise errors.UnsupportedError(msg) return args
def exception_match(typingctx, exc_value, exc_class): """Basically do ``isinstance(exc_value, exc_class)`` for exception objects. Used in ``except Exception:`` syntax. """ # Check for our limitation if exc_class.exc_class is not Exception: msg = "Exception matching is limited to {}" raise errors.UnsupportedError(msg.format(Exception)) def codegen(context, builder, signature, args): # Intentionally always True. return cgutils.true_bit restype = types.boolean return restype(exc_value, exc_class), codegen
def unpack_single_tuple(tyctx, tup): """This exists to handle the situation y = (*x,), the interpreter injects a call to it in the case of a single value unpack. It's not possible at interpreting time to differentiate between an unpack on a variable sized container e.g. list and a fixed one, e.g. tuple. This function handles the situation should it arise. """ # See issue #6534 if not isinstance(tup, types.BaseTuple): msg = (f"Only tuples are supported when unpacking a single item, " f"got type: {tup}") raise errors.UnsupportedError(msg) sig = tup(tup) def codegen(context, builder, signature, args): return args[0] # there's only one tuple and it's a simple pass through return sig, codegen
def match(self, func_ir, block, typemap, calltypes): self.prints = prints = {} self.block = block # Find all assignments with a right-hand print() call for inst in block.find_insts(ir.Assign): if isinstance(inst.value, ir.Expr) and inst.value.op == "call": expr = inst.value try: callee = func_ir.infer_constant(expr.func) except errors.ConstantInferenceError: continue if callee is print: if expr.kws: # Only positional args are supported msg = ( "Numba's print() function implementation does not " "support keyword arguments.") raise errors.UnsupportedError(msg, inst.loc) prints[inst] = expr return len(prints) > 0
def _legalize_exception_vars(self): """Search for unsupported use of exception variables. Note, they cannot be stored into user variable. """ # Build a set of exception variables excvars = self._exception_vars.copy() # Propagate the exception variables to LHS of assignment for varname, defnvars in self.definitions.items(): for v in defnvars: if isinstance(v, ir.Var): k = v.name if k in excvars: excvars.add(varname) # Filter out the user variables. uservar = list(filter(lambda x: not x.startswith("$"), excvars)) if uservar: # Complain about the first user-variable storing an exception first = uservar[0] loc = self.current_scope.get(first).loc msg = "Exception object cannot be stored into variable ({})." raise errors.UnsupportedError(msg.format(first), loc=loc)
def get_call_type(self, context, args, kws): from numba.core.target_extension import (target_registry, get_local_target) prefer_lit = [True, False] # old behavior preferring literal prefer_not = [False, True] # new behavior preferring non-literal failures = _ResolutionFailures(context, self, args, kws, depth=self._depth) # get the current target target target_hw = get_local_target(context) # fish out templates that are specific to the target if a target is # specified DEFAULT_TARGET = 'generic' usable = [] for ix, temp_cls in enumerate(self.templates): # ? Need to do something about this next line hw = temp_cls.metadata.get('target', DEFAULT_TARGET) if hw is not None: hw_clazz = target_registry[hw] if target_hw.inherits_from(hw_clazz): usable.append((temp_cls, hw_clazz, ix)) # sort templates based on target specificity def key(x): return target_hw.__mro__.index(x[1]) order = [x[0] for x in sorted(usable, key=key)] if not order: msg = (f"Function resolution cannot find any matches for function" f" '{self.key[0]}' for the current target: '{target_hw}'.") raise errors.UnsupportedError(msg) self._depth += 1 for temp_cls in order: temp = temp_cls(context) # The template can override the default and prefer literal args choice = prefer_lit if temp.prefer_literal else prefer_not for uselit in choice: try: if uselit: sig = temp.apply(args, kws) else: nolitargs = tuple([_unlit_non_poison(a) for a in args]) nolitkws = {k: _unlit_non_poison(v) for k, v in kws.items()} sig = temp.apply(nolitargs, nolitkws) except Exception as e: sig = None failures.add_error(temp, False, e, uselit) else: if sig is not None: self._impl_keys[sig.args] = temp.get_impl_key(sig) self._depth -= 1 return sig else: registered_sigs = getattr(temp, 'cases', None) if registered_sigs is not None: msg = "No match for registered cases:\n%s" msg = msg % '\n'.join(" * {}".format(x) for x in registered_sigs) else: msg = 'No match.' failures.add_error(temp, True, msg, uselit) failures.raise_error()