Skip to main content

Module inference

Module inference 

Source
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 resolution
  • bidirectionalCheckMode and the check_expr entry point
  • expressions – 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 walk
  • items – top-level item inference (functions, types, impls, extends)
  • operators – binary and unary operator type rules
  • statements – statement-level inference (let, assignment, return, for, while, blocks)

Structs§

PropertyAssignment
Collected property assignment information
PropertyAssignmentCollector
Visitor that collects all property assignments in a program
TypeInferenceEngine

Enums§

CheckMode
Mode for bidirectional type checking