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 -- a derive_beq! Point would otherwise look like the consumer reaching into std::derive for derive_beq_meta, a name no use line could ever sensibly name. The gate re-parses the source (the one it was handed, or the file) through decls_parser_located alone, which is exactly the parse parse_all_decls runs minus the expansion.
  • The bare/qualified axis survives in DebugName. The host reads it off NameRef; this compiler's canonical Term is 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.
defvisibility_visible_from#
pub def visibility_visible_from (consumer : ModulePath) (consumer_mote : Option String) (owner : ModulePath) (vis : Visibility) : Bool

consumer_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.

structSelection#
pub struct Selection {
    bare : AllowedNames,
    qual : AllowedNames,
}

What one consumer's use lines select from ONE module.

structDeclRow#
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).

structRefs#
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.

structOpens#
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.

defuse_completeness_errors#
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 String

The 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).