lang::typecheck::macro_expand

lang/src/typecheck/macro_expand.mo

The term-level expansion walk — expand_term/resolve_quote, mirroring rust/core/src/eval/macro_expand.rs's own pair of the same name, built on [[lang/typecheck/macro_apply.mo]]'s apply_term_macro (itself built on [[lang/typecheck/subst.mo]]).

Two layers:

  • The pure expand_term/resolve_quote pair, called by lang/typecheck/macro_queue.mo's per-file expand_decls. It has only a macro lookup, so it expands ordinary term macros and leaves every meta! call untouched.
  • The Result-returning expand_term_with_meta, called by the whole-graph pass (lang/module.mo's expand_decls_graph), which additionally carries a MetaIntrinsicCtx so a term-position meta!/reflect_type_info! can be evaluated and its Expr reified. Evaluation can fail, which is why this half returns Result (the pure wrappers cannot, and swallow a depth-limit failure by leaving the term unexpanded — the graph pass diagnoses it).
structMetaIntrinsicCtx#
pub struct MetaIntrinsicCtx {
    mic_dispatched : List Decl,
    mic_inductives : List Inductive,
}
defscan_live_call#
pub def scan_live_call (lookup : Identifier -> Option Term) (t : Term) : Result String Term

Detection-only walk: Result.err as soon as a term-position macro call the whole-graph pass could still expand appears — an intrinsic, or any name the graph-wide registry knows. Reuses the Result traversal's short-circuit rather than adding a second scan pass.

defterm_has_live_call#
pub def term_has_live_call (lookup : Identifier -> Option Term) (t : Term) : Bool
defexpand_term#
pub def expand_term (lookup : Identifier -> Option Term) (t : Term) : Term

The per-file walk macro_queue.mo uses: no evaluation environment, so an intrinsic is left in place. A depth-limit failure (a macro that expands into itself) leaves the term unexpanded; the whole-graph pass is where that becomes a diagnostic.

defresolve_quote#
pub def resolve_quote (lookup : Identifier -> Option Term) (t : Term) : Term
defexpand_term_with_meta#
pub def expand_term_with_meta
    (lookup : Identifier -> Option Term)
    (ctx : MetaIntrinsicCtx)
(t : Term) : Result String Term

The whole-graph entry point: ordinary macros plus the term-position meta!/reflect_type_info! intrinsic, with real error propagation.