numba.ast_type_inference

class numba.ast_type_inference.BuiltinResolverMixin

Resolve builtin calls for type inference. Only applies high-level transformations such as type coercions. A subsequent pass in LateSpecializer performs low-level transformations.

class numba.ast_type_inference.NumpyMixin

Mixing that deals with NumPy array slicing.

  • normalize ellipses
  • recognize newaxes
  • track how contiguity is affected (C or Fortran)
class numba.ast_type_inference.TypeInferer(context, func, ast, closure_scope=None, **kwds)

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.

add_resolved_parents(unvisited, start_points, strongly_connected)

Check for immediate resolved parents

analyse_assignments()

Analyze all variable assignments and phis.

candidates(unvisited)

Types with in-degree zero

error_unresolved_types(unvisited)

Raise an exception for a circular dependence we can’t resolve

handle_locals(arg_types)

Process entries in the locals={...} dict

infer_types()

Infer types for the function.

init_locals()

Populate symbol table for local variables and constants.

initialize_argtypes(arg_types)

Initialize argument types

initialize_ssa()

Propagate argument types to first rename of the variable in the block

is_trivial_cycle(type)

Return whether the type directly refers to itself

kill_unused_phis(cfg)

Kill phis which are not referenced. We need to do this bottom-up, i.e. in reverse topological dominator-tree order, since in SSA a definition always lexically precedes a reference.

This is important, since it kills any unnecessary promotions (e.g. ones to object, which LLVM wouldn’t be able to optimize out).

promote_types_numeric(t1, t2)

Type promotion but demote objects to numeric types

remove_resolved_type(start_point)

Remove a resolved type from the type graph

resolve_variable_types()

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.

visit_BoolOp(node)

and/or expression

visit_Index(node)

Normal index

class numba.ast_type_inference.TypeSettingVisitor(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Set node.type for all AST nodes after type inference from node.variable. Allows for deferred coercions (may be removed in the future).

resolve(variable)

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

visit_DeferredCoercionNode(node)

Resolve deferred coercions

Previous topic

numba.ast_translate

Next topic

numba.cfg

This Page