lang::lower_core_ir

lang/src/lower_core_ir.mo

typeLowerError#
pub type LowerError {
    le_unresolved_name (name : Identifier),
    le_unresolved_module_path (path : ModulePath),
    le_unknown_inductive (path : ModulePath),
    le_unknown_constructor (path : ModulePath),
    le_unknown_native (name : Identifier),
    /// `Term.pi`/`type_`/`hole` reached at lowering time -- these
    /// are type-level-only and should never occur in a well-typed
    /// runtime-relevant subterm.
    le_type_level_term,
    /// A constructor's `args : List (Option Term)` had a hole before a
    /// filled slot -- see this module's own doc comment.
    le_con_hole_before_filled_arg,
    /// `inner` occurred while lowering `path`'s own body -- wrapped by
    /// `lower_one_global`/`lower_root` so a failure deep in a large
    /// whole-graph worklist (e.g. `reflect_type_info!`'s meta-eval,
    /// `lang/typecheck/meta_eval.mo`, reaching hundreds of transitively
    /// referenced stdlib defs) still names which specific def it was in,
    /// not just the underlying error kind.
    le_in_def (path : ModulePath) (inner : LowerError),
    /// A `Literal.struct_lit`/`Literal.struct_update` survived all
    /// desugaring and reached lowering -- the type checker's
    /// `type_check_struct_lit` (`lang/typecheck/infer.mo`) and codegen's
    /// `desugar_struct_lits_decls` pass (`codegen/emit.mo`) should
    /// both have turned it into a `Term.con` before here. The eval-path
    /// (`lower_root`/`meta_eval`) counterpart of `codegen/emit.mo`'s
    /// `validate_no_undesugared_struct_lits` compile gate: this used to
    /// be a bare missing arm, i.e. a non-exhaustive-match crash with no
    /// named cause.
    le_struct_lit_survived,
    /// A float literal reached lowering: the eval IR has no way to carry
    /// one. `IrLit.ir_float` exists and every consumer already has an arm
    /// for it, but nothing can CONSTRUCT one -- the literal arrives as
    /// text (`Literal.flt`) and the only text-to-float conversion in the
    /// prelude is `F64.bits_of_string`, which answers with the bit pattern
    /// as an `I64` for codegen to emit. Closing this needs a decision
    /// about what the eval IR should hold (the bits, the text, or a real
    /// `F64` behind a native that does not exist yet), which is why this
    /// is a named diagnostic rather than a silent fall-through:
    /// `lower_literal` is `#[partial]` and a missing arm took the LAST
    /// one, so `def main : F64 := 1.5` reported a struct-literal error and
    /// sent its reader to the wrong file entirely.
    /// `plans/implementations/2026-09-26-external-mote-gaps-for-forge.md`,
    /// Gap 5.
    le_float_literal_unsupported,
    /// A `Term.quote_`/`Term.var_macro` reached lowering. Unlike
    /// `le_type_level_term`'s callers, this one has no type-check
    /// prerequisite (this module's own doc comment, and `meta_eval.mo`'s
    /// caller contract): `expand_decls_graph`'s best-effort macro expansion
    /// can legitimately leave either shape in place mid-expansion. Named
    /// rather than reused, following `le_struct_lit_survived`'s own
    /// precedent -- this used to be a bare missing arm too.
    le_unresolved_macro_artifact,
    /// A `Term.elim` that `elim_to_literal` could not lower: an unresolvable
    /// inductive, a minor with fewer lambdas than its constructor has fields,
    /// or a minor/constructor count mismatch. Every `Term.elim` the checker
    /// produces is well-formed, so this is a defensive diagnostic for a
    /// hand-built or best-effort term rather than a reachable program state.
    le_elim_ill_formed (reason : String),
}
defshow_lower_error#
pub def show_lower_error (e : LowerError) : String
deflower_root#
pub def lower_root (ctx : LowerCtx) (root : NamePath) : Result LowerError (Pair CoreIr GlobalTable)

Lower the root def's body to CoreIr, plus a GlobalTable covering every def transitively reachable from it -- ready to feed straight into lang/core_eval.mo's eval (together with lang.core_eval.basic_native_table).

deflower_ctx_from_decls#
pub def lower_ctx_from_decls (path : ModulePath) (decl_list : List Decl) : LowerCtx

Build a LowerCtx from a flat List Decl -- pulls Defs out directly (for find_def_body) and builds a Scope from the same decl_list (for scope_resolve_name/scope_find_inductive).