Resolve builtin calls for type inference. Only applies high-level transformations such as type coercions. A subsequent pass in LateSpecializer performs low-level transformations.
Mixing that deals with NumPy array slicing.
- normalize ellipses
- recognize newaxes
- track how contiguity is affected (C or Fortran)
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.
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
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).
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
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