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_quotepair, called bylang/typecheck/macro_queue.mo's per-fileexpand_decls. It has only a macro lookup, so it expands ordinary term macros and leaves everymeta!call untouched. - The
Result-returningexpand_term_with_meta, called by the whole-graph pass (lang/module.mo'sexpand_decls_graph), which additionally carries aMetaIntrinsicCtxso a term-positionmeta!/reflect_type_info!can be evaluated and itsExprreified. Evaluation can fail, which is why this half returnsResult(the pure wrappers cannot, and swallow a depth-limit failure by leaving the term unexpanded — the graph pass diagnoses it).
pub struct MetaIntrinsicCtx {
mic_dispatched : List Decl,
mic_inductives : List Inductive,
}pub def scan_live_call (lookup : Identifier -> Option Term) (t : Term) : Result String TermDetection-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.
pub def term_has_live_call (lookup : Identifier -> Option Term) (t : Term) : Boolpub def expand_term (lookup : Identifier -> Option Term) (t : Term) : TermThe 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.
pub def resolve_quote (lookup : Identifier -> Option Term) (t : Term) : Termpub def expand_term_with_meta
(lookup : Identifier -> Option Term)
(ctx : MetaIntrinsicCtx)
(t : Term) : Result String TermThe whole-graph entry point: ordinary macros plus the term-position
meta!/reflect_type_info! intrinsic, with real error propagation.