Create a deferred type for an AST node
Set the ast.Call as uninferable for now
Bases: numba.visitors.NumbaTransformer
Type inference. Initialize with a minivect context, a Python ast, and a function type with a given or absent, return type.
Infers and checks types and inserts type coercion nodes.
See transform.py for an overview of AST transformations.
Check for immediate resolved parents
Analyze all variable assignments and phis.
Assert a type in the type graph can be resolved
Assert a type in the type graph is resolved somewhere down the line
Types with in-degree zero
Raise an exception for a circular dependence we can’t resolve
Process entries in the locals={...} dict
Infer types for the function.
Populate symbol table for local variables and constants.
Initialize argument types
Propagate argument types to first rename of the variable in the block
Return whether the type directly refers to itself
Find and resolve any final reduced self-referential portions in the graph
Type promotion but demote objects to numeric types
Remove a resolved type from the type graph
Resolve the types for all variable assignments. We run type inference on each assignment which builds a type graph in case of dependencies. The dependencies are resolved after type inference completes.
and/or expression
Normal index
Bases: numba.visitors.NumbaTransformer
Set node.type for all AST nodes after type inference from node.variable. Allows for deferred coercions (may be removed in the future).
Resolve any resolved types, and resolve any final disconnected type graphs that haven’t been simplified. This can be the case if the type of a variable does not depend on the type of a sub-expression which may be unresolved, e.g.:
y = 0 for i in range(...):
- x = int(y + 4) # y is unresolved here, so we have
- # promote(deferred(y), int)
y += 1
Resolve deferred coercions
Get a function object given a function name
Support for type functions for external code.
See modules/numpy*.py for type inference for NumPy.
Bases: object
Builds the module type inferers for the modules we can handle
Return the module (or None) to which a registered value belongs
Register an type function (a type inferer) for a known function value.
E.g. np.add() can be mapped as follows:
module=np, attr=’add’, inferrer=my_inferer
Register an type function for a dotted attribute path of a value,
E.g. my_module.my_obj.foo.bar() can be mapped as follows:
module=my_module, attr=’my_obj’, dotted_path=’foo.bar’, inferrer=my_inferer
Register an unbound method or dotted attribute path (allow for transience).
E.g. np.add.reduce() can be mapped as follows:
module=np, attr=’add’, method_name=’reduce’, inferrer=my_inferer
Bases: numba.error.NumbaError
Raised when no matching specialization is found for a registered signature (register_callable).
Bases: numba.error.NumbaError
Raised when a type inferer is registered multiple times for the same value.
Return whether the type function can handle deferred argument types
Dispatch a call of a module attribute by value.
For instance, a method
- def empty(shape, dtype, order):
- ...
would be called with those arguments. Parameters not present as arguments in user code are None.
Returns the result type, or None
See if the object is registered to any module which might handle type inference on the object.
Parse positional and keyword arguments.
@register(module) def my_type_function(arg1, ..., argN):
...
signature := function | typeset(signature *)
@register_callable(signature) def my_function(...):
...
Find the right type inferrer function for a call to an attribute of a certain module.
- call_node: the original ast.Call node that we need to resolve
- the type for
- obj_call_node: the nodes.ObjectCallNode that would replace the
- ast.Call unless we override that with another node.
- func_type: module_attribute
- |__________> module: Python module |__________> attr: Attribute name |__________> value: Attribute value
Returns a new AST node that should replace the ast.Call node.