lang::scope
lang/src/scope.mo
pub def alias_map_empty : HashMap String StringString-keyed map for the bare-name -> qualified-name rewrite tables
resolve_open_alias_decls drives. Mirrors modpath_map_* just
above (and codegen.emit's str_map_*) in bypassing Map's
typeclass dispatch for direct HashMap bucket calls.
Deliberately NOT called str_map_*: codegen.emit already
exports helpers by that name, and until every def carries its module
path those two would have been one LLVM symbol with one surviving
body -- the exact failure this whole change exists to remove. Named
apart so the gate never has to catch it.
pub def alias_map_insert (key : String) (val : String) (m : HashMap String String) : HashMap String Stringpub def alias_map_lookup (key : String) (m : HashMap String String) : Option Stringpub def scope_data_empty : ScopeDatapub def modpath_eq (a : ModulePath) (b : ModulePath) : BoolModule-PATH equality, for the places a real file/module identity is
still being compared (LowerAcc's interned seen list,
ModuleRegistry entry paths, codegen/qualify.mo's open-alias
tables) as opposed to a DECL's own name, which is a NamePath and
goes through npath_eq above.
pub def build_scope_from_decls (path : ModulePath) (decl_list : List Decl) : ScopeDataOne module's declarations -- the overwhelmingly common shape. A thin
wrapper over build_scope_from_groups with a single group, so the
whole list is stamped with path exactly as it was before the grouped
builder existed.
pub def build_scope_from_groups (groups : List DeclGroup) : ScopeDatabuild_scope_from_decls, with each GROUP's decls stamped with that
group's own module path instead of one path for the whole list.
Pass 1 (build_scope_from_decls_go) is per-decl independent -- it
folds one declaration's own registrations into the accumulator and
consults nothing else -- so folding it group by group, in order,
produces exactly the same ScopeData as one fold over
decl_groups_flatten groups would, apart from each ScopeDef.module.
That difference is the whole point: a dependency def stamped with the
CONSUMER's path can never pair-match in find_def_by_module_and_name,
so a qualified reference across a module boundary could not resolve.
Pass 2 (alias_decls_in_scope) deliberately still runs ONCE over the
flattened view: the flat-scope model lets one module's use/open
alias be visible to another module's defs, and narrowing that to
per-module aliasing is a separate behaviour change that no corpus case
asks for.
pub def refine_scope_instances (decl_list : List Decl) (sd : ScopeData) : ScopeDataRefine the instance registry's wildcards the same way the syntactic
class-call pass refines its own collect_instances list
(resolve_class_calls_decls), so the CHECKER's D4 resolution
(lang.typecheck.infer's resolve_class_method_carrier and
dict_forwarding_override) matches the same instances against the
same carriers that pass does.
Without it, an instance whose arg mentions an UNDECLARED type variable
-- instance [Monad M] Monad (TuiT M I I) names I with no {I : Type} binder -- has I missing from instance_wildcard_names in the
registry, so term_matches_carrier requires a literal I at that
position and the instance matches NO concrete carrier. The prelude's
bridge instance {I : Type} [IndexedMonad M] Monad (M I I) declares
both, matches every carrier, and took the call instead: the checker's
hint-channel rewrite committed the do-block's Monad.bind/Monad.pure
to the bridge's promoted methods, codegen never revisited the choice,
and the compiled driver died calling prelude::Monad_M_I_I_bind with
an IndexedMonad dictionary (motes/tui/src/tests/tuit_tests.mo,
do-notation at equal indices). The syntactic pass, whose list IS
refined, picked the wrapper -- the two passes disagreed, and the
checker's answer is final (resolve_class_method_d4's own doc
comment: "a call that succeeds HERE is rewritten and is never handed
to lang.scope's pass again").
WHOLE-GRAPH CALLERS ONLY. The known-name filter
(declared_type_names) must cover every type the program can name,
exactly like resolve_class_calls_decls' own call site -- which runs
"on the FULL loaded decl graph". Refining a scope built from ONE
module's decls recovers real imported types as pattern variables: in
a single-module scope, instance Copy I64 has no I64 in its
known list, so I64 becomes a wildcard, the instance stops being
fully concrete, is_copy (lang.typecheck.copy_class) denies ω,
and the affine walk reports a use-after-move in Copy's own method
body. This is why the refinement is NOT folded into
build_scope_from_groups itself despite that being the one funnel
every scope build passes through: the three whole-graph callers
(elaborate_loaded_modules, rebuild_target_scope,
compile_input_of_modules) apply it explicitly, and per-module
scope builds keep the registry exactly as the decls wrote it.
pub def decl_groups_flatten (groups : List DeclGroup) : List DeclThe flattened view of a group list -- every group's decls, in group order, with nothing added or dropped: the list the pre-group pipeline would have held at that point.
pub def modpath_of (np : NamePath) : ModulePathThe inverse boundary conversion: a NamePath handed to a position
that still carries a ModulePath (the core-IR match_fail node and
LowerError's path-carrying variants, both kept ModulePath on the
Rust host side too, converted only where the two meet). Mirrors the
Rust host's impl From<NamePath> for ModulePath.
pub def scope_globals (s : Scope) : ScopeDatapub def scope_find_inductive (name : NamePath) (s : Scope) : Result ScopeError Inductivepub def scope_data_class_index (sd : ScopeData) : ClassIndexpub def scope_find_class (name : NamePath) (s : Scope) : Option Classpub def scope_find_inductive_by_constructor (con_name : NamePath) (s : Scope) : Option Inductivepub def scope_resolve_name (nref : NameRef) (s : Scope) (locals : LocalScope) : Result ScopeError ScopeDefpub def split_qualified_identifier (i : Identifier) : Option QualifiedNameSplit a mod::name spelling back into a QualifiedName.
The parser builds a real NameRef.nqn, but lower_parse.mo renders
it to a flat DebugName string and every checker call site rebuilds
it as a bare nid -- so the nqn arm below was unreachable and a
qualified reference always reported unknown variable. Recovering
the structure here makes that arm live for all of them at once
(infer.mo's four sites, lower_core_ir.mo, module.mo).
pub def qualified_name_to_name_path (qn : QualifiedName) : NamePathmod::name flattened to the .-rendered NamePath key a
dotted-declared def registers under.
pub def scope_find_def_return_type (name : NamePath) (s : Scope) : Option TermTop-level Scope-based wrapper, same shape as scope_find_def_params.
pub def scope_find_def_body (name : NamePath) (s : Scope) : Option TermTop-level Scope-based wrapper, same shape as scope_find_def_sig.
Globals only (scope_globals), which is the point: delta unfolds
top-level defs, never local bindings.
pub def scope_find_def_sig (name : NamePath) (s : Scope) : Option TermTop-level Scope-based wrapper, same shape as
scope_find_def_return_type.
pub def scope_find_cubical_prim (name : NamePath) (s : Scope) : Option CubicalPrimTop-level Scope-based wrapper, same shape as scope_find_def_sig/
scope_find_def_body: globals only, because the binding is written by
build_scope_def at DECLARATION time and a local that shadows the name
must not inherit the primitive (the checker's rewrite sites each have
their own shadow guard, lang/typecheck/infer.mo).
pub def scope_find_def_constraints (name : NamePath) (s : Scope) : Option (List TypeConstraint)Globals only, same shape as scope_find_def_sig -- the constraints
are a property of the DECLARATION, so a local shadowing the name
does not inherit them.
pub def scope_find_def_dict_constraints (name : NamePath) (s : Scope) : Option (List TypeConstraint)Globals only, same shape as scope_find_def_constraints.
pub def collect_infixes (decl_list : List Decl) : List Infixpub def resolve_infix_decls (infixes : List Infix) (decl_list : List Decl) : List DeclResolves infix operators across a whole decl_list at once —
resolve_infix_decl applied to every entry.
pub def resolve_infix_decl_groups (infixes : List Infix) (groups : List DeclGroup) : List DeclGroupresolve_infix_decls over each group. The rewrite is per-decl -- it
consults only the globally collected infix table, never another
declaration -- so carrying the owner alongside changes nothing about
the result: decl_groups_flatten of this is exactly the list the flat
version would have returned.
pub struct OpenAlias {
bare_name : String,
qualified_name : String,
}pub def collect_open_aliases (decl_list : List Decl) : List OpenAliasCollects every open/use bare-name alias declared anywhere in
decl_list -- mirrors collect_infixes's identical role/doc
comment for operators. These are CANDIDATES only -- see filter_ valid_open_aliases's own doc comment for why the reconstructed
qualified name isn't always real, and must be validated against the
whole program's own known def names before being used to rewrite
anything.
pub def resolve_open_alias_decls (names : HashMap String String) (decl_list : List Decl) : List DeclResolves open/use names across a whole decl_list at once --
resolve_open_alias_decl applied to every entry. Wired in right
alongside resolve_infix_decls (codegen.emit's
compile_loaded_modules_to_ir).
pub def collect_classes (decl_list : List Decl) : List Classpub def class_name_eq (a : NamePath) (b : NamePath) : BoolClass-name equality, tolerant of the TWO spellings the same class arrives in:
- the class DECL's own name is ONE joined identifier --
class Json.Deserializer (D : Type)is recorded as the single segment"Json.Deserializer", becauseClass.nameis anIdentifierand the elaborated dotted name isshow_name_path-joined into it (class_own_namebelow re-wraps it the same way); - every REFERENCE to that class is a genuine multi-segment
NamePath--instance Json.Deserializer Bool { ... }'s head is parsed byname_path_parserinto[Json, Deserializer].
npath_eq is name_path_similar (types.mo), element-wise with
String.beq per segment, so the two spellings DISAGREE despite
show_name_path rendering both as Json.Deserializer: every dotted
class name found zero instances and zero declared signatures, and
lang/src/json.mo's Json.Deserializer.deserialize calls reported
no instance found however concrete the carrier (measured: the
filter_instances_by_class result was empty while the same file's
four Json.Deserializer instances were right there).
Render before comparing. join_identifiers is .-joined and an
Identifier cannot contain . (see BOrd Identifier, types.mo), so
equal renders mean the same name and nothing else; a module-qualified
spelling (json::Json.Deserializer) still renders differently and
stays distinct, where a last-segment comparison would coarsen the two
apart.
Item 5.1 addendum: also tolerant of ONE side being module-qualified
(prelude::Monad) while the other is the bare source spelling
(Monad) -- qualify_one_decl_name renames a class_d's own
declaration, but Instance.cls/TypeConstraint.class (REFERENCES
to that class, sitting in a position resolve_open_alias_decl
deliberately never rewrites -- see scope_data_find_inductive's own
doc comment for the full story) stay bare. Comparing via
unqualify_def_name on whichever side has a qualifier is exactly
the same "strip one qualifier prefix, compare the WHOLE remainder"
unqualify_def_name already does elsewhere -- not the "last segment
only" coarsening the comment above warns against; json::Json. Deserializer still only matches Json.Deserializer, never bare
Deserializer. Safe to leave this loose (no separate ambiguity
check here, unlike scope_data_find_inductive's own fallback):
qualify.mo's own ambiguity detection already covers class/struct/
inductive declarations (since item 5.0/5.1) and hard-errors the
whole build BEFORE build_scope_from_decls ever runs, so a
genuinely ambiguous bare class name never reaches this comparison.
Comparing via string_matches_bare (the no-allocation twin of
unqualify_def_name + String.beq, codegen/symbols.mo) --
this runs per instance/class comparison in
resolve_class_calls_decls, and a slice per compared byte per
comparison was a measured ~10x blowup of that stage.
pub def class_index_find (idx : ClassIndex) (cls_name : NamePath) : Option Classfind_class_by_name over the one bucket that can hold a match: the
same predicate in the same order, without scanning every class.
pub def instance_bare_name (insname : Identifier) : StringThe instance's own name with any module:: qualifier stripped -- the
identifier as declared in its own module.
pub def mangle_instance_method_name (insname : Identifier) (cls_name : NamePath) (ins_args : List Term) (method_name : Identifier) : NamePathThe mangled top-level name a promoted instance method gets. A
single-segment ModulePath (not dotted) -- filter_reachable_decls/
reachability matching is a string-based walk over already-flat
names, so single-segment sidesteps any dot-vs-underscore ambiguity
there, the same reasoning 28d98dc's infix-resolution pass already
established for its own resolved names.
The name is additionally prefixed with the instance's declaring
module (instance_module_prefix) -- see with_module_prefix for
why the class+type pair alone is not unique program-wide.
A NAMED instance (instance ShowA : Show I64) also appends its own
name: two named instances of the same class+carrier mint distinct
promoted methods (the hint feature's whole selection target), where
the bare class+type mangling gave both the same name. An anonymous
instance keeps the historical name.
pub def mangle_instance_dict_name (insname : Identifier) (cls_name : NamePath) (ins_args : List Term) : NamePathThe mangled name of an instance's own dictionary VALUE def. A NAMED
instance (instance ShowA : Show I64) appends its own name: two named
instances of the same class+carrier would otherwise mint the SAME
__Dict_<Cls>_<args> def -- the exact shape the #Named.Instance
hint selects between -- and collide. An anonymous instance keeps the
historical name.
pub def promote_instance_defs (decl_list : List Decl) : List DeclTop-level Phase 2 driver: scans decl_list for every Decl.instance_d,
looks up its own class (skipping it, silently, if not found -- a
dangling instance with no registered class is out of scope for this
pass, same "leave unresolved rather than guess" fallback style used
throughout this codebase), and APPENDS its promoted decls
(non-destructive -- the original instance_d stays in place,
ignored by reachability filtering exactly like an infix declaration
already is).
pub def promote_instance_decl_groups (groups : List DeclGroup) : List DeclGrouppromote_instance_defs, grouped -- and deliberately NOT a per-group
application of it.
promote_instance_defs collects its class table from its OWN argument,
so promoting each module's decls in isolation would skip every
instance whose class is declared in a different module (std's
instances of init's classes, for one) -- a silent drop that would
surface much later as a symbol codegen never emitted.
So the class table is still collected GLOBALLY, from the flattened view, and the promoted decls are appended as their own per-owner groups AFTER every original group. That reproduces the flat result exactly -- every original decl in order, then every promotion in order -- while attributing each promotion to the module that owns its instance. (The instance walk order matches too: groups are held in the same order the flat list holds their decls.)
pub def qualifying_dict_constraints (dict_classes : NameSet) (constraints : List TypeConstraint) (typ : Term) (body : Term) : List TypeConstraintThe constraints that become dictionary PARAMETERS: every
single-variable constraint whose class carries a dictionary
(collect_dict_classes), on a def that has a real body and does not
return a type. Decided from the DECLARATION alone, never from the
body: a def's arity is part of its ABI, so the callee and every call
site (def_dict_constraints, emitted_dict_constraints) must reach
the same answer without re-reading a body that elaboration may have
rewritten -- and whether the body uses the dictionary is a resolution
fact (x + x reaches Add only through [Add A] HAdd A A A) that no
syntactic scan can see. The Rust reference applies the same rule
(elaborate_constrained_type, core_check_module.rs).
The exemptions are the shapes a dictionary cannot be threaded into: a
body-less #[native]/#[extern] declaration has a fixed native
arity, and a TYPE-level def (Lens [Functor F] ... : Type) is
expanded where it is used, as a type, not called.
pub def dict_param_name (cls : NamePath) : StringThe bound NAME a dict parameter gets in the term (distinct from its TYPE placeholder above, though built from the same class name) -- Phase 4's own D5 (genuine-polymorphism) resolution reads this same name back out of its threaded environment to forward an already- bound dict to a nested call, so the naming scheme here is load- bearing for that phase, not just cosmetic.
pub def add_constraint_dict_params_decls (decl_list : List Decl) : List DeclApplies add_constraint_dict_params to every Decl.def_d in a flat
decl list -- other decl kinds pass through unchanged (an instance's
own promoted methods, from Phase 2, are ordinary concrete defs with
no constraints of their own to add a param for -- except the one
real corpus case, instance [Add A] HAdd A A A's own add method,
which DOES carry the instance's own [Add A] constraint through to
its promoted Def -- promote_methods, Phase 2, copies constraints
from the original method Def unchanged, so this pass reaches it the
same as any other constrained def).
pub def add_constraint_dict_params_decl_groups (groups : List DeclGroup) : List DeclGroupadd_constraint_dict_params_decls over each group. Like the infix
pass, this rewrites one declaration at a time (add_constraint_dict_ params takes a Def and nothing else), so the owner travelling
alongside is irrelevant to the result.
pub type LocalTypeBinding {
mk (var_id : Identifier) (declared_type : Term),
}One local variable's own declared type, as literally written at its
binding site (a Term.lam's own typ field) -- threaded down
through the walk so a later reference to that variable can recover
its type for carrier inference.
pub type DictBinding {
mk (cls : NamePath) (dict_id : Identifier),
}One already-bound dictionary parameter currently in scope, keyed by
its own class -- threaded down the same way, extended whenever the
walk descends into one of Phase 3's own dict-binding Term.lams
(recognized by dict_param_name's own naming scheme).
pub type CtorOwner {
mk (ctor_name : Identifier) (owner : NamePath),
}One 0-arg constructor's own owning inductive type -- e.g. true/
false both owned by Bool -- needed for carrier inference on a
bare constructor reference like true in true == false.
pub type DefTypeEntry {
mk (name : NamePath) (typ : Term),
}One top-level def's own declared .typ, verbatim -- lets
infer_carrier_type's Term.app arm (below) recover a carrier from
the DECLARED return type of a called function, when the operand is
itself a computed call (I64.to_string x) rather than a literal/
bare-var/constructor -- exactly the shape the self-hosted test
driver's own synthesized summary line produces
(codegen/test_driver.mo's synthesize_test_driver_source),
and the root cause of the Append_append self-compile bug this
table exists to close. Deliberately reads Def.typ directly from the
decl list rather than going through scope_resolve_name: ScopeData
registers every def's own ScopeDef.sig as Term.hole
unconditionally (build_scope_def's own doc comment -- a load-
bearing sentinel for dozens of other call sites, not something to
change) -- confirmed via direct debugging that this is genuinely why
lang.typecheck.infer's own type-checker-based dictionary resolution
(Stage 2 of bootstrapping/unify-check-compile-test-elaboration.md)
can't recover a real return type for an ordinary function call in
pure-infer mode. This syntactic pass, unlike the type checker, reads
straight from the parsed decl list and isn't affected by that gap.
pub type CtorFieldTypes {
mk (ctor_name : Identifier) (owner : NamePath) (owner_params : List Identifier) (field_types : List Term),
}One constructor's own declared field types, positionally -- lets a
match p { Ctor a b => ... } arm recover a/b's real types from
Ctor's own declared params, the same way Term.lam already
registers a lambda param's declared type into env (see
resolve_class_call_term's Literal.match_ case below). ctor_name
is the constructor's bare name (last_segment), matching
CtorOwner's own convention -- MatchCase.mk's own name field is
bare too, with no type-qualification available structurally at this
syntactic pass.
owner -- the owning inductive's own name path -- is what makes the
table usable at all: EVERY struct's own constructor is named mk,
so a whole-program table holds one mk entry per struct in the
corpus, and a name-only lookup hands a match arm whichever struct was
declared first. See lookup_ctor_field_types_owned.
owner_params -- the OWNING inductive's own declared type-param
identifiers (e.g. [A, B] for type Pair A B { pair (fst:A) (snd:B) })
-- in the same order field_types references them. Needed because a
generic constructor's own declared field types are the ABSTRACT type
params, not any particular use site's concrete instantiation (Pair String Json's fst/snd are declared A/B in Pair's own decl,
not String/Json) -- match_arm_env below substitutes using the
scrutinee's own concrete type args once it has both pieces.
pub def identifier_tail (id : Identifier) : StringA name's last dotted/colon-separated component (Json.Number ->
Number, json::Number -> Number), through the same splitting
last_segment_of already does for a decl's own name-path, plus a
:: strip -- without it, refine_instance_wildcards compares a
bare instance arg (I64) against qualified declared types
(prelude::I64) and classes every concrete arg as a wildcard.
Also read by lang.typecheck.infer's inductive_bare_name, which
faces the same bare-vs-qualified split for type heads it
synthesizes.
pub type CallSpine {
mk (head : Term) (args : List Term),
}A flat call spine (f a b c -> head f, args [a, b, c]) -- local
to this pass (emit.mo's own AppSpine isn't reachable from here
without a circular module dependency, since emit.mo itself already
uses this module).
pub def scope_find_class_def_for_ref (id : Identifier) (bare_id : Identifier) (s : Scope) : Result ScopeError ScopeClassDefThe class-method entry a reference names. A QUALIFIED reference
(Monad.bind) is decided by its qualifier -- the bare-name scan
answers with the last-declared class that has a method of that name
(IndexedMonad.bind, for Monad.bind), which no instance of the named
class ever matches.
pub type ClassMethodRef {
mk (cls : Class) (method_name : Identifier),
}pub def dict_hint_name (t : Term) : Option StringIs this term one lowered #Named.Instance marker? Answers the
instance name it carries.
pub def strip_dict_hint_args (args : List Term) : Pair (List String) (List Term)Peel a call spine's LEADING # markers: the hint grammar
(dict_hint_term, lang/parser.mo) only ever parses one directly
after the callee, so every marker sits at the spine's head. Later
markers cannot occur, and a marker found mid-spine is left in place
for the checker's catch-all (type_check_app's marker guard) to
reject loudly rather than silently dropping a hint the writer
expected to take effect.
pub def dict_hint_marker_terms (hints : List String) : List TermRe-synthesize the marker terms for a hint list -- the checker peels markers before checking a call and re-attaches them to its rebuilt term, so the hint still reaches the codegen dict pass.
pub def scope_find_instance_by_name (s : Scope) (hint : String) : Option InstanceThe instance named hint anywhere in the scope's globals, as seen from
the scope's own module (a hidden instance is not a candidate).
pub def validate_dict_hints (callee : Identifier) (resolved : Option NamePath) (hints : List String) (s : Scope) : Option TypeErrorValidate a call's #Named.Instance hints: each must name a declared
instance, and the callee must be able to use it (its class's method,
or one of its own constraints). Answers the first failure as a
TypeError.custom naming the hint; Option.none accepts.
pub def method_result_headed_by_carrier (cls : Class) (method_name : Identifier) : BoolIs the method's result headed by the class's first parameter (get : M S, modify_get : (S -> Pair S A) -> M A)? Then method_carrier_hint
reads exactly that parameter off an expected result type, whatever the
class's arity: MonadState (M) (S) resolves on M alone, while
HAdd.add : A -> B -> C (result C, not the first parameter) does not
qualify.
pub def class_default_carrier (cls : Class) : Option TermA class's own first declared type param's default value, if any
(e.g. L in class FromListLiteral (L : Type -> Type := List),
Param.default). Only ever consulted as the LAST-resort fallback
above.
pub def validate_no_unresolved_class_calls (classes : List Class) (decl_list : List Decl) : Result String (List Decl)resolve_class_call_term's own resolution chain has a SILENT give-up
built in by design (rebuild_call orig_head resolved_args, used
throughout resolve_class_method_call_with_carrier/_with_dict_args/
_d4_default_carrier/resolve_ordinary_constrained_call whenever no
matching instance/carrier is found) -- it just leaves the ORIGINAL
ClassName.method reference in the term tree untouched, no error. That
silent survivor then gets dot-to-underscore-mangled by codegen into an
@ClassName_method global reference that was never compiled, caught
only by llc's own "undefined value" check many pipeline stages (and,
in a real self-compile, minutes) later -- this is what the
Append_append/Show_show bug family (6cf8da7, a47856c, 855be99)
all turned out to be, each requiring its own manual archaeology session
to even FIND which call was unresolved.
Fail fast instead -- but deliberately NOT inside resolve_class_calls_ decls itself: that pass runs on the FULL loaded decl graph, before
reachability filtering, so validating its own output directly would
fail a compile over a bug in dead code the program never actually
uses (confirmed via a direct repro: std/list.mo's own unreachable
test_length def blocked bootstrap compile cli/src/main.mo monad,
exactly the "any codegen bug anywhere in the whole standard library,
reached or not, blocked compiling any program at all" problem
filter_reachable_decls's own doc comment says THAT pass exists to
avoid). Callers that filter reachability should validate the
REACHABLE decls, after filter_reachable_decls, not the full ones --
see compile_loaded_modules_to_ir's own use of this for the pattern.
Walk decl_list for any surviving Term.var that still matches
class_method_ref classes -- by construction, a successful resolution
always REWRITES such a reference to a concrete mangled name (no longer
matching class_method_ref), so any survivor found here is
unambiguously a real "no instance available" failure, reported with
the class/method/enclosing-def named directly instead of discovered
via a cryptic downstream llc error.
classes is taken as its own explicit param, NOT recomputed via
collect_classes decl_list -- filter_reachable_decls's own output
(the intended decl_list here, see this def's own doc comment above)
contains ONLY Decl.def_d/Decl.inductive_d entries; Decl.class_d
is unconditionally dropped (never reachability-filtered at all, since
nothing downstream of resolve_class_calls_decls needs it), so
collect_classes on THAT decl_list always finds zero classes,
silently turning this whole check into a no-op. Callers must compute
classes from the PRE-filter decls (collect_classes dispatched_decls
-- confirmed via a direct repro, the same one that found the dead-code
false-positive above).
pub def find_unresolved_class_calls_decls (classes : List Class) (decl_list : List Decl) : List StringWalks every top-level def's own term looking for a Term.var
reference that still matches class_method_ref classes -- see
resolve_class_calls_decls's own doc comment for why any such
survivor is unambiguously a real unresolved-instance failure.
pub type DefConstraintEntry {
mk (name : NamePath) (constraints : List TypeConstraint),
}One ordinary (non-class-method) def's own constraints -- needed so a
CALL SITE to a constrained def (e.g. show_twice 5, where
show_twice itself carries [Show A]) can also gain the dict
argument(s) Phase 3 added a matching PARAMETER for on its
definition -- Phase 3 only ever rewrites the definition side; this
is the call-site half of the same mechanism, needed for genuine
polymorphism (D5) to have anything to actually supply at a call
site in the first place.
pub def strip_all_leading_binders (typ : Term) : TermStrip EVERY leading Term.pi binder, all three flavours included
(unlike return_type_after_n_args, which strips a fixed n and stops at
a quantifier) -- used to find a top-level def's own ULTIMATE codomain
regardless of arity, for full_return_carrier's do-notation fallback
(see resolve_class_call_term's doc comment).
pub def owned_instance_visible (consumer : ModulePath) (o : OwnedInstance) : BoolMay a module whose path is consumer use this instance?
The same rule a declaration's visibility gets: pub everywhere, priv
only in the module that declares it, the default (package-private) in
its own mote, and an empty consumer path (codegen and the unit harness
build whole-program scopes with one) sees everything. A hidden instance
is not a candidate at all, which is how the boundary is enforced:
Copy fails closed to affine, and dispatch reports instance_not_found.
pub def scope_instance_candidates_in (scope : Scope) (cls_name : NamePath) : List InstanceCandidates for cls_name as seen from scope's own module.
pub def scope_instance_candidates (sd : ScopeData) (cls_name : NamePath) : List InstanceCandidates with NO consumer: every instance, hidden or not. For callers
that have only a ScopeData (tests, the harness). The type checker uses
scope_instance_candidates_in.
pub def scope_all_instances (sd : ScopeData) : List InstanceEvery instance in scope, whatever its class -- what a CONSTRAINT of a
different class than the matched instance's own ([Add A] HAdd A A A) is resolved against.
pub def scope_all_instances_in (scope : Scope) : List InstanceThe same list as seen from scope's module.