Expand description
Name resolution (spec §5.1, v0.1 §4.1, v0.2 §4.1).
Builds symbol tables for the commons and validates that:
- No two top-level items share a name (types, fns, methods are all named).
- Every
TypeRef::Namedresolves to a declared type. - Every free function call resolves to a function declaration.
- Every identifier in expression position resolves to a parameter, a
letbinding, orself(inside a method). - Constructor / static calls (
TypeName.method(args)) resolve either to the built-inT.ofof a refined type, a static method onT, or a variant constructor whenTis a sum type. - Record construction targets a declared record type and uses only declared fields.
- Method calls resolve via the receiver’s nominal type (the actual type check happens in the type checker).
On success returns a ResolvedCommons — the original AST plus
symbol tables the type checker consumes.
Structs§
- Cross
Context Capability - Snapshot of one exported capability in a consumed context, as needed for
v0.15 cross-context capability resolution. Operation signatures are
expressed in the consumed context’s own namespace (resolved against
consumed_typesat the call site, mirroringCrossContextService). - Cross
Context Capability Op - Cross
Context Info - Static information about the consuming context: the set of contexts it
consumes, and any aliases introduced viaas Aliasclauses. Used by the resolver to recognise cross-context service calls and by the checker to type them (v0.6 §4.2). - Cross
Context Service - Snapshot of one service in a consumed context, as needed for v0.6 cross-context type checking. The params and return type are expressed in the consumed context’s own namespace.
- File
Consumes - #3536: where a file’s
consumesclauses stand, forcheck_unselected_type_names: what the unit consumes, what this file’s own clauses list, and where a clause the file lacks would go. - Method
Table - Per-type method table built during resolution: keyed by method name,
values are clones of the
FnDeclfor that method. - Private
Import - #2618: a
privatedeclaration of a commons this unituses, which the unit cannot see. Keyed (inprivate_imports_in) by the subject an unknown-name diagnostic names it by:f,T, or a method asT.m. - Resolved
Commons - Output of resolution: the AST plus the symbol tables the checker needs.
- Shadowed
Import - #1925: a
uses-imported function or asset that the unit hides behind its own declaration of the same name and another kind. A local declaration wins, as it does in the emitted module, so the import is out of scope; a reference the local declaration cannot answer (a call to a type, a bare service name) is reported as this conflict, not as an unknown name.
Functions§
- check_
hidden_ type_ names - #1807: the naming gate for hidden types. A hidden type is one this unit’s
composed table carries only because an imported declaration reaches it
(
crate::project_model::close_reachable_types): resolvable here, never nameable, sinceusesis one level (ADR 0278). Every place the unit’s source writes a type name is walked: type references in declarations, signatures,letannotations, lambda parameters and type arguments; a record, constructor or spread’s type; a type used as a receiver (Repo.of(…),Status.Pending); a method declared on a type; a pattern’s qualifier; and a refinement test (s is Repo). Bodies are walked, and so are an agent’s invariants, transitions andstoreinitialisers, and aneventfield’s default. A hidden name in any of them isbynk.resolve.unknown_type, the error the name gave before the closure existed, with a note naming the commons touses. - check_
hidden_ type_ names_ in_ suite - #1814: the naming gate for a test suite’s view. A suite resolves names in
its target’s privileged view (a unit suite) or its harness table (a
systemsuite), each closed over the types its imported declarations reach (crate::project_model::close_view_types). A hidden type is resolvable there, so a case can build and read a reached field, but a suite may no more name it than its target may. Walks everystubclause’s argument patterns and values, every case body, and every property’sfor allbindings,wherefilter and predicate, ascheck_hidden_type_nameswalks a unit’s items.targetis the unit whoseuseswould admit a hidden name: the target of a unit suite, or the suite itself (None) for asystemsuite, which declares its ownuses. - check_
shadowed_ type_ names - #1927: the naming gate for a
uses-imported type the unit hides behind its own declaration of another kind (a function, asset, service, agent or provider:crate::project_model::shadowed_imports). The type stays in the unit’s table, so an imported declaration that uses it still checks, and a value of it still flows through the unit’s code. But the emitted module binds the name to the local declaration, so the unit may not write it: every positioncheck_hidden_type_namesgates isbynk.uses.name_conflicthere, and so is constructing one of the sum’s variants bare (Done), which emits the type’s name too. Matching a variant does not. - check_
shadowed_ type_ names_ in_ suite - #1927:
check_shadowed_type_namesfor a unit suite: a case may no more write a type its target hides than the target may. - check_
unconsumed_ unit_ calls - #3536:
bynk.consumes.unit_not_consumed, the same rule for a cross-context call (pay.charge(…)): the file that writes it must itselfconsumesthe unit, in any form.prefixesmaps each prefix a call may write (the unit’s name, or the alias of aconsumes U as A) to the unit. The fix addsconsumes Uto this file. - check_
unconsumed_ unit_ calls_ in_ suite check_unconsumed_unit_callsfor a unit suite.- check_
unselected_ capabilities - #3536:
bynk.consumes.capability_not_selected, the same rule for the capabilities a bracedconsumes U { Cap }flattens into the unit’s namespace: naming one (agivenclause, a call,provides, a derived capability’s base) in a file whose ownconsumesdoes not list it.flattenedis the unit’s capabilities, each with its owner. - check_
unselected_ capabilities_ in_ suite - #3536:
check_unselected_capabilitiesfor a unit suite, whosestubclauses and cases name its target’s flattened capabilities. - check_
unselected_ type_ names - #3536:
bynk.consumes.type_not_selected, for each place a file’s source writes the name of a type (or a bare variant of a sum) that a unit it consumes exports and that this file’s ownconsumesdoes not bring in: either it lists other names, or only another file of the unit consumes the unit. Imports are per file, so naming anything else is an error, and carries a fix that edits this file’sconsumes: extend the clause it has, or add one. - check_
unselected_ type_ names_ in_ suite - #3536:
check_unselected_type_namesfor a unit suite.ownersmaps each type a unit the suite’s target consumes exports, except those the target or the suite declares itself, to that unit;typesis the suite’s view. - compute_
is_ uses_ commons_ type - Is
namea type imported viausesof a commons specifically — the exact predicateResolvedCommons::is_uses_commons_typecaches asuses_commons_type_names, andbynk-emitneeds at two real call sites that must never disagree:emit_context_rebrands’s own two steps, “alias the import” and “rebrand the type” (its own doc comment, step 1 “Done in imports”, step 2 the rebrand itself, both inbynk-emit/src/emitter.rs) — an import narrower than the rebrand leaves an undefined name in the generated module; a rebrand narrower than the import leaves an alias imported and never used. - cross_
context_ service_ for - Project one local
on callhandler into theCrossContextServiceshape both sides of a cross-context contract check need — a caller resolving a consumed service (crate::symbols::build_cross_context_info) and a callee stamping its ownX-Bynk-Contractconstant (crate::contract::own_contract_hashes). Sharing this one projection is the whole correctness argument for that symmetry: if the two sides ever diverged, a working deployment would 409 on every call instead of only on real skew.Nonewhensdeclhas noon callhandler (e.g. an events-only or queue-only service). - new_
consumes_ position - #3536: where a
consumesline a file lacks is inserted, with the line break (and indent) that precedes it. After the file’s lastusesorconsumesclause (the parser wants them ahead of every declaration); else after its header, which is the text up toheader_end, then the{of a braced file.Nonewhen a braced file’s{is not where it should be. - private_
imports_ in - #2618: the
privatedeclarations of the commonslocaluses that a reference inlocalcould be reaching for. A namelocaldeclares itself is left out, since a reference to it is the unit’s own; so is a method of a typelocaldeclares. The firstusestarget to declare a subject wins. - resolve
- Resolve names in a single-file (or already-merged) commons. Use this
entry point only for self-contained Bynk programs. For multi-file
projects and
uses-resolving commons, useresolve_fileagainst a pre-built combined symbol table. - resolve_
file - Validate name references inside a single file’s items against an
already-built symbol table (
resolved.types,resolved.fns,resolved.methods). Used by the project-level driver after combining declarations from every file in a multi-file commons and from every commons brought in byuses. - resolve_
file_ record resolve_file, recording binding edges intorefsas the walk resolves them (v0.25). The project pass sets the sink’s per-file context; a fresh sink records nothing.- resolve_
recovering resolve, returning the symbol table with every resolve error rather than instead of it (#1663, Decision A). A resolve error is local to the declaration it is in, so the checker can still check every declaration — an unknown name inbno longer hides a type error ina. The table is complete apart from what the errors name (a duplicate keeps its first declaration). A caller that emits must still refuse on any error.- rewrite_
private_ references - #2618: report a reference to a used commons’
privatedeclaration asbynk.visibility.private_itemrather than as the unknown name it resolves as. An importer does not see private declarations at all (they are left out of its composed tables, so its own declaration of the same name is no conflict), so the reference first fails asunknown_*; this names the real reason instead. The subject is read from the message exactly assplit_broken_decl_echoesreads it. - split_
broken_ decl_ echoes - #1663 (Decision B): split resolve errors into those to report and those that only echo a declaration the parser had to skip.
- without_
resolve_ echoes - #1663 (Decision A): the checker’s diagnostics after a resolve that reported errors, keeping only those in declarations the resolver found clean.