Expand description
Type Inference Engine
Implements Hindley-Milner style type inference with extensions for Shape’s domain-specific features.
§Bidirectional type checking
The engine supports three checking modes (see bidirectional.rs):
- Infer – purely synthesise a type from the expression structure.
- Check(T) – verify the expression against an expected type (hard constraint, emitted for annotated bindings and return positions).
- Synth(T) – synthesise with a hint (soft constraint, used for closure parameter inference from generic method signatures).
When a method call like arr.map(|x| ...) is encountered, the engine
looks up the GenericMethodSignature for the receiver type, extracts
the expected closure parameter types, and passes them as Synth hints
so that x receives the array element type without annotation.
§Sub-modules
access– property access, index access, field resolutionbidirectional–CheckModeand thecheck_exprentry pointexpressions– expression-level inference (literals, calls, closures, match, if/else, binary/unary ops)hoisting– optimistic pre-pass that collects property assignments to widen object types before the main inference walkitems– top-level item inference (functions, types, impls, extends)operators– binary and unary operator type rulesstatements– statement-level inference (let, assignment, return, for, while, blocks)
Structs§
- Property
Assignment - Collected property assignment information
- Property
Assignment Collector - Visitor that collects all property assignments in a program
- Type
Inference Engine
Enums§
- Check
Mode - Mode for bidirectional type checking