lang::meta_env
lang/src/meta_env.mo
The environment macro meta-defs are evaluated in (meta_eval_invoke,
reached from meta! and reflect_type_info!): the defs reachable from
the meta-def names, elaborated, plus every non-def declaration. Building
it from the whole graph type-checked the entire program in post-load
only to evaluate a few derive/format helpers.
A def whose elaboration fails is kept in place with a body lowering
rejects (poisoned_decl), so a meta-def that reaches it fails with the
elaboration error instead of evaluating the unelaborated body, and a
def pulled in only by name and never lowered costs nothing.
Reachability is by name and over-approximates: a def is filed under its
bare name and under the segment after its last . (an opened
IO.println is referenced as println), and every def sharing a key is
kept. A reference the keys miss leaves its def out, and lowering then
fails on the unresolved name. Defs keep their original relative
order, so lowering's first-match lookup picks the same def it would in
the whole graph. The closure is taken over ELABORATED bodies, because
elaboration is what introduces the dictionary and instance-method
references a class call resolves to.
pub def ref_key (id : Identifier) : StringThe name a reference or a def is matched by: its spelling after the
last ::.
pub def term_ref_names (t : Term) (acc : List String) : List StringEvery global name t references: free variables, macro variables,
constructors and match-case constructor names.
pub def decl_def (d : Decl) : Option DefThe def a declaration carries, looking through a scoped_open_d.
pub def decl_ref_names (d : Decl) (acc : List String) : List StringEvery name a declaration's def references (type and body); a non-def references nothing here.
pub def elaboration_failed_marker : StringThe prefix of the name a poisoned def's body references; lowering reports it as an unresolved name, carrying the elaboration error.
pub def poisoned_decl (d : Decl) (err : String) : Decld with its def's body replaced by a reference lowering cannot
resolve, naming the def and the elaboration error.
pub def meta_env_decls (elab : Decl -> Result String Decl) (decls : List Decl) (roots : List String) : List Decldecls narrowed to every non-def plus the defs reachable from roots,
each reachable def passed through elab exactly once (poisoned when
it fails), in the original order.
pub def decl_all_ref_names (d : Decl) (acc : List String) : List StringEvery name a declaration mentions anywhere it can spell a meta-def: a def or macro body, a macro call's arguments, a decl-gen template.
pub def decls_all_ref_names (ds : List Decl) (acc : List String) : List String