Mlsem_system.ReconstructionReconstruction of typing derivations.
Mlsem_system.Checker can verify a derivation but not find one. This module searches for one: starting from a skeleton in which every choice is undecided, it repeatedly picks a node it cannot type as is, asks the constraint solver which instantiations of the inference variables would make it typeable, and commits to them.
The search. Refining a node returns one of three outcomes:
In the last case the node cannot decide alone, because the substitutions also constrain the rest of the expression. Two things can happen:
Annot.Domain).That side condition is also what keeps the cached types of Annot.t valid: a substitution is only ever applied to a derivation when it cannot affect the environment that derivation was typed under.
Termination. Every substitution outcome returns derivations that are strictly more decided than the one it was given — an undecided node has become a completed sub-derivation, a resolved branch, or Untyp — so the re-exploration cannot cycle. Any change to the search must preserve this.
val initial :
?direct_narrowing:bool ->
?partition_narrowing:bool ->
Refinement.Refinements.t ->
Ast.t ->
Annot.IAnnot.tThe skeleton derivation of an expression, in which every choice is left undecided. The two flags select how the precomputed refinements are used: direct_narrowing attaches them to program points, partition_narrowing turns them into decompositions of let-bound variables (cf. Refinement). Both default to true.
val refine : Mlsem_common.Env.t -> Annot.IAnnot.t -> Ast.t -> Annot.Annot.tSearches for a complete derivation, starting from the given skeleton.
val infer :
?direct_narrowing:bool ->
?partition_narrowing:bool ->
Mlsem_common.Env.t ->
Refinement.Refinements.t ->
Ast.t ->
Annot.Annot.t