Best-effort metavariable substitution for a Typ, named after Lean.Meta.instantiateMVars
since it does the same job for the same reason: an already-resolved metavariable (e.g. pinned by
an earlier operand in the same call) is substituted with its solution; one that's never been
constrained is left as Typ.mvar n (rendered ?n) rather than erroring. Needed wherever a Typ
is about to be embedded in a thrown TCError (so the message shows a concrete type instead of a
raw ?n), and wherever a Typ obtained from inferExpr is about to be pattern-matched against a
specific shape (.record/.set/.function/…): a scheme operator's result can carry a
metavariable its own argument-checking already solved, but nothing rewrites the Typ tree in
place, so a bare structural match sees .mvar n and not the solution — e.g. \E m \in DOMAIN someBag : m.field elaborates m.field only because m's type is instantiated first. Read-only
over the metavariable context, so calling it anywhere never affects checking's soundness, only
whether an already-decided type is visible yet.
Instances For
instantiateMVars, except that a type still a bare unresolved metavariable is shown as one of
its upper bounds when it has any — what an error message should call the type, rather than ?n.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Defaults every unresolved metavariable reachable from roots that has upper bounds (directly,
or through other metavariables) to the tightest of them, repeating until nothing more can be
defaulted — one defaulting can resolve a metavariable another's bounds mention. A metavariable with
no such bound is left unresolved. Two bounds with no common subtype are a
TCError.conflictingUpperBounds error.
Closes out a definition with no annotation, whose signature is sig and whose elaborated
parts are es: defaults every metavariable that can be defaulted, merges those bounded only by one
another, and turns each one still left in sig into a fresh rigid type variable. Returns the
resulting signature, generalized over those variables. es still need resolveMVars, which
rejects any metavariable left that sig does not mention.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Closes out an elaborated expression: defaults every metavariable it reaches that has an upper
bound (defaultMVars), eliminates every Expression.mvar wrapper node (resolveExprMVars),
then walks the result once more resolving any Typ.mvar left behind in a stored type field.
Equations
- resolveMVars e = do defaultMVars (posOf e) (List.flatMap typeMVars (exprTypes✝ e)) let e' ← resolveExprMVars✝ e TypedTLAPlus.Expression.traverse (resolveTypeMVars✝ (posOf e')) e'