Skip to main content

Module constraints

Module constraints 

Source
Expand description

Type Constraint Solver

Solves type constraints generated during type inference to determine concrete types for type variables. The solver operates in three phases:

§Phase 1: Eager unification

Each constraint (T1, T2) is attempted immediately via solve_constraint. Simple bindings (variable-to-concrete, variable-to-variable) succeed here. Constraints that fail (e.g. because a variable is not yet resolved) are deferred to the next phase.

§Phase 2: Fixed-point iteration on deferred constraints

Deferred constraints are retried in a loop. Each successful resolution may unlock further deferred constraints by refining substitutions. The loop terminates when a full pass makes no progress. Any constraints still unsolved after the fixed-point are reported as UnsolvedConstraints.

§Phase 3: Bound application

After all equality constraints are resolved, apply_bounds validates type variable bounds (Numeric, Comparable, Iterable, HasField, HasMethod, ImplementsTrait). HasField constraints additionally perform backward propagation: when a structural object field is found, the field’s result type variable is bound to the actual field type.

The solver delegates low-level variable binding and substitution to the Unifier (Robinson’s algorithm with path compression).

Structs§

ConstraintSolver