lang::typecheck::meta_reflect

lang/src/typecheck/meta_reflect.mo

Data-shape conversions between self-hosted Term/Decl/Inductive/ Struct (lang/types.mo) and the reflection-as-data Value (lang/core_value.mo) shape of init/meta.mo's TypeInfo/CtorInfo/ FieldInfo/Expr/MetaMatchArm/MetaParam/MetaDecl types -- mirrors rust/core/src/eval/meta_reflect.rs (Rust). Pure: no evaluation, no IO. lang/typecheck/meta_eval.mo is the sibling module that actually EVALUATES a meta-def against the Value this module builds; this module only converts data shapes on both sides of that call.

Constructor tags are hardcoded, not looked up. CtorInfo/FieldInfo are single-constructor types (init/meta.mo), so their own constructor's tag is always 0. TypeInfo has two (type_info tag 0 for a monomorphic type, type_info_params tag 1 for a generic one; see init/meta.mo's bootstrap note), so type_info_val/type_info_params_val name their tags directly. Expr/MetaDecl/MetaMatchArm/MetaParam are also types THIS design fully owns (init/meta.mo), so their tags are hardcoded directly from that file's own literal declaration order below, matching this whole codebase's own established precedent for this exact situation (lang/core_eval.mo's bool_value/lang/lower_core_ir.mo's own doc comment on Bool's hardcoded true=0/false=1 tag order). List/ Option/Bool (prelude types) are hardcoded the same way, citing init/prelude.mo's own literal declaration order. If any of these declarations are ever reordered, this file's own tests below (which exercise real round-trips) will catch it.

De-Bruijn locals convention. Reifying Expr.e_lam/e_match/a MetaDecl.d_def's own params into real Term.lam/Literal.match_ nodes needs to assign correct de-Bruijn indices to any nested e_var reference that names a LOCALLY bound name (a lambda param, a match-arm-bound field, an outer d_def param) -- confirmed directly against lang/typecheck/infer.mo's prepend_typed (the type checker's own positional local-type list builder for match-case arg lists) that the convention throughout this codebase is: the LAST-declared name in a same-level binder group ends up de-Bruijn index 0 (innermost), matching lang/core_eval.mo's own extend_env_with_fields/dispatch_arm runtime behavior exactly. push_locals below is the one place that convention is applied.

defreify_value_to_term#
pub def reify_value_to_term (v : Value) : Result String Term

The term-position entry point: an arbitrary Expr returned by a String -> Expr (or any other) meta function, reified at top level, where there are no enclosing binders to resolve against. Mirrors rust/core/src/eval/meta_reflect.rs's reify_value_to_term.