lang::use_completeness
lang/src/use_completeness.mo
The self-hosted twin of the Rust host's use-completeness gate
(check_use_completeness, rust/core/src/term/module.rs): every name a
module reaches from another module must be named in its own use
line, unless the owner is ambient, the consumer itself, or the name
was open-ed. Enforced by lang/module.mo's gate_use_completeness
on every load's MAIN module, so it holds for every entry point at
once (check/test/compile/the LSP), exactly as the host's
loader-level gate does.
Where this differs from the host, and why:
- References are collected from the main module's PRE-expansion
parse. The host clones its decls before macro expansion;
this compiler's loader parses through
expand_decls(parse_all_decls, lang/module.mo), which inlines a decl-gen template's body into the consumer's own decl list -- aderive_beq! Pointwould otherwise look like the consumer reaching intostd::deriveforderive_beq_meta, a name nouseline could ever sensibly name. The gate re-parses the source (the one it was handed, or the file) throughdecls_parser_locatedalone, which is exactly the parseparse_all_declsruns minus the expansion. - The bare/qualified axis survives in
DebugName. The host reads it offNameRef; this compiler's canonicalTermis de Bruijn, but lowering (lang/parser/lower_parse.mo) keeps a free variable's whole written spelling --::in the middle for a module-qualified reference (qualified_ref_symbol's convention), bare otherwise -- and a bound variable is already an index, so the walk needs no binder tracking at all. - Macro-GENERATED names are silent, on both sides of the rule.
The host folds the elaborated module's declared names into its
own-name set; this gate has only the parse, so a name a
reflect_type_info!call generates is absent from the index (dependencies are parsed too) as well as from the consumer's own-name set -- invisible, which is a false negative, never a false report. The load-time expansion's declared names ARE folded in (they are already in the stored decl list), which covers every name expansion declares but the consumer does not write.
pub def visibility_visible_from (consumer : ModulePath) (consumer_mote : Option String) (owner : ModulePath) (vis : Visibility) : Boolconsumer_mote is the consumer FILE's mote, resolved from its
manifest -- not derived from consumer, because the entry module of a
monad check path/to/file.mo run is named by its stem (copy_tests),
while every module it reaches is mote-qualified (init::copy).
Deriving the consumer's mote from that path would put every sibling
module in a different mote. None means the file is outside any mote
(a script, or examples/ at the virtual workspace root), where there
is no package boundary to cross -- the same answer the Rust host gives.
pub struct Selection {
bare : AllowedNames,
qual : AllowedNames,
}What one consumer's use lines select from ONE module.
pub struct DeclRow {
owner : ModulePath,
/// The declaration's own spelled name (`List.length`, `Type.ctor`).
name : NamePath,
/// Its last segment, which is what a bare reference writes.
bare_tail : Identifier,
is_ctor : Bool,
/// The declaration's own visibility. Constructors and class methods
/// inherit the visibility of the block that declares them, exactly
/// as the scope builder treats them. DELIBERATELY NOT DEFAULTED: the
/// Rust host's checker does not give a defaulted field's expression a
/// lowering path when the literal is lowered in another def, and
/// `bare_finding` failed the self-compile with `UnresolvedAtom`
/// because of it.
vis : Visibility,
}One declaration a loaded module provides, as the judgment needs it:
the owner, the declaration's own spelled name, its bare tail, and
whether it is a constructor of an ordinary inductive (a struct's
synthesized mk is deliberately absent, exactly as it is absent
from the host's declaration_index: no brace item could ever
select it).
pub struct Refs {
bare : List NamePath,
bare_seen : NamePathSet,
qualified : List QualifiedName,
qual_seen : QualifiedNameSet,
}The names a module's own declarations reference, kept apart by the
axis each one was WRITTEN on -- the twin of the host's References
(rust/core/src/term/module.rs). Merging the axes would make
use std::base {} plus a qualified std::base::Ordering.lt look
unimported.
pub struct Opens {
names : NamePathSet,
}The names an open T {n} makes bare. An unfiltered open T can put
an unbounded set of names in scope, so anything said about the rest
of the file would be a guess: collect_opens returns none for the
whole file there, and silence is a false negative, never a false
positive.
pub def use_completeness_errors (file_path : String) (consumer : ModulePath)
(consumer_mote : Option String)
(pre_decls : List Decl) (expanded_decls : List Decl)
(world : List (Pair ModulePath (List Decl))) : List StringThe use-completeness rule, as error messages. Empty means the
module is complete. pre_decls are the consumer's PRE-expansion
declarations (where the references are read from), expanded_decls
its stored, load-expanded list (whose declared names count as its
own), and world every loaded module's (path, decls).