Expand description
Name resolution for the Nova compiler.
Phase 1 scope: a single-file module. The resolver walks the top-level
items of a parsed nova_ast::File and produces a Definitions table
mapping every top-level name (functions, sum types, sum-type variants,
constants) to a stable DefId. Duplicate definitions are reported as
E0002 diagnostics.
Local (block-scoped) variable resolution happens during type checking,
where scoping interacts with inference; this crate owns the item-level
namespace and the shared DefId / Res vocabulary used by the rest
of the pipeline.
Re-exports§
pub use index::Index;pub use index::LocalFlags;pub use index::Occurrence;pub use index::Role;pub use index::Target;
Modules§
- index
- The index of name occurrences the language server reads (spec
docs/superpowers/specs/2026-10-10-phase-3-4a-navigation-design.md§3).
Structs§
- Def
- A single top-level definition.
- DefId
- A stable identifier for a top-level definition within a module.
- Definitions
- The item-level namespaces of a whole program (one or more modules).
- Exported
- What a module exports under one name, in each namespace (spec 3.4b §4.2).
- Module
Id - Index of a module within a compiled program.
- Module
Source - A source module: a parsed file, its label, and what its imports name.
- Program
Resolution - Output of
resolve_program: the merged file, its namespaces, any diagnostics, and the@testfunctions collected along the way. The merged file’sitem_indexes are whatDefinitionsrefers to, so downstream stages consume both together. - Resolve
Result - Output of
resolve: the namespace table, the merged file whoseitem_indexes the definitions refer to (the input plus the implicit std modules, seeSTD_MODULES), and any diagnostics. Downstream stages must type-check against thisfile, not the original input, sinceitem_indexes index into it. - TestFn
- A well-formed
@testfunction, collected by [collect_item] in the same orderresolve_program’s item walk visits it — source order (modules in registration order, items within a module in file order; seecollected_tests_are_in_source_order_with_should_panic_attachedinnova-typeckfor why that order must be exact and stable). Task 3 reads this to build a dispatchingmainthat runs one test per process, selected by index; Task 5 reads test names back out of the compiled binary, not from this struct directly — so an index and a name can never silently disagree between the two only if this order never does either. - Variant
Def - One variant of a sum type.
Enums§
- Builtin
- A compiler-provided builtin function.
- DefKind
- What kind of definition a
DefIdrefers to. - Import
Target - What an
importnames, by its first segment (spec 3.3a §4.5). - Method
Owner - Where a
DefKind::Methodlives. - Res
- What a name in expression position resolves to.
- Scope
Entry - What a name in a module’s scope is bound to: what completion offers
(spec
docs/superpowers/specs/2026-10-08-phase-3-2-lsp-core-design.md§4.3).
Constants§
- RESERVED_
TYPE_ NAMES - Type names the compiler owns, which a user type declaration may not take.
- STD_
MODULES - The embedded standard-library modules, compiled as implicit modules and
glob-imported into every user module. Order is significant only in that it
fixes module indices; user modules always come first, then these in the
order listed here —
std/corestays first so its module index is unchanged from when it was the only embedded module. The sources come from thenova-stdcrate, which embedsstd/at build time through paths inside its own package, so the compiler stays a single self-contained executable andcargo packagekeeps the files. Each name is$std.*, not a valid identifier, so it can never collide with a user module name or be named in animport. - STD_
TEST_ MODULE std/test, seeded only undernova test. Kept out ofSTD_MODULESso that array’s length does not depend on compilation mode: every consumer iterates it and the driver allocates oneFileIdper entry, so a conditional member would makeFileIdallocation depend on which subcommand is running.
Functions§
- name_
imports - Fill each module’s import table by module name, as a program without
packages has always resolved (ADR 0003):
import mnames the first module calledm. Every other module becomes importable by its name (spec 3.4b §4.6). - resolve
- Collect the item-level namespace of a single file.
- resolve_
program - Resolve a multi-module program: collect each module’s item namespace,
enforce
pubvisibility across modules, wire upimports, and merge all items into one file for whole-program compilation downstream.