Files
lucioandClaude Fable 5 651e58bfb3 The design-hierarchy sidebar: codex's feature, integrated
An instance-oriented hierarchy view in the Activity Bar —
lucisv/moduleHierarchy snapshots (schema 2: uri table, flat ranges,
derived ids; 11.6 MB -> 2.3 MB on opentitan) plus
lucisv/moduleHierarchyChanged invalidation, gated on the extension's
initializationOptions. Format 5 carries decl spans, instance
occurrences and client positions for file-scope declarations
(+1.7-1.9 % store), so a snapshot reads no files at all: handler
145-167 -> 17-20 ms settled, a save with the sidebar open 366 ->
141 ms. complete is !scanning && !must_wait, pinned. Owner UI rounds:
no hover preview, all levels collapsed by default with stable ids
across refreshes, and search over a resident flat model (freeze
diagnosed: materialized expanded tree x undebounced double
fuzzyScore x whole-tree clone per keystroke) — prebuilt lowercased
index, bitmask prefilter, top-K counting, 200-row cap with an honest
remainder, single-digit ms over a 120k-entry fixture.
LineIndex::utf16_position unifies the index's and the wire's position
math under a cross-crate agreement test.

Implementation: codex. Integration fixes + owner items: Opus dev.
QA: lead (measurement pass) + Sonnet (SHIP, independent oracles).

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-29 03:39:06 -07:00
..

workspace-index

Goal

vlog_semantic::analyze is deliberately single-file: a name only another file can supply comes back as Resolution::ExternalCandidate carrying the import paths that could finish it — 19.6 % of every use on cleanly-parsed corpus files (docs/features/vlog-semantic/README.md). This feature is the second layer that finishes them. WorkspaceIndex::build scans every file in the workspace once and records what each one declares — modules, packages, file-scope typedefs, each package's and module's exported members, and each file's `define table. Since 2026-08-27 it also records compact reference facts and merges them into declaration-to-occurrence postings. resolve_external walks one file's external candidates against that index and answers them in an overlay keyed by reference id. That is what turns import prim_pkg::* and prim_fifo_sync u_fifo (...) into a jump into the file that declares them — TODO.md §6's "cross-file resolution through header imports", the last piece textDocument/definition needs before lucisv_server can be written.

API as built

// The index
impl WorkspaceIndex {
    fn build<'a>(files: impl IntoIterator<Item = (PathBuf, &'a str)>) -> WorkspaceIndex;

    fn files(&self) -> &[PathBuf];              // indexed by FileId
    fn path(&self, FileId) -> Option<&Path>;
    fn file_id(&self, &Path) -> Option<FileId>;                         // 2026-08-27
    fn units(&self, name: &str) -> &[Def];      // module | package | file-scope typedef
    fn member(&self, unit: &str, member: &str) -> &[Def];
    fn members_of(&self, unit: &str) -> impl Iterator<Item = (&str, &[Def])>;
    fn defines(&self, FileId) -> Option<&DefineTable>;
    fn instantiations_of(&self, name: &str) -> &[InstantiationEdge];  // 2026-08-27
    fn subclasses_of(&self, name: &str) -> &[InheritanceEdge];        // 2026-08-27
    fn references_to(&self, def: &Def) -> &[ReferenceSite];           // 2026-08-27
    fn references_are_ambiguous(&self, def: &Def) -> bool;            // 2026-08-27
    fn update_file(&mut self, PathBuf, src: &str);                    // 2026-08-27
    fn remove_file(&mut self, &Path) -> bool;                         // 2026-08-27
    fn fingerprint(&self) -> String;                                  // 2026-08-27
    fn find_define(&self, name: &str) -> Vec<(FileId, &Define)>;
    fn workspace_symbols(&self, query: &str) -> Vec<WorkspaceSymbol<'_>>;
    fn units_of(&self, SymbolKind) -> impl Iterator<Item = (&str, &Def)>;  // 2026-08-29
    fn counts(&self) -> IndexCounts;
}

struct Def { file: FileId, name_span: TextRange, decl_span: TextRange, // 2026-08-29, hierarchy sidebar
             kind: SymbolKind,
             detail_span: Option<TextRange>,     // 2026-08-28, port-detail-spans
             lines: DeclLines }                  // 2026-08-28, hover-line-index
struct DeclLines { name: u32, detail: Option<u32>,    // 1-based source lines
                  positions: Option<DeclPositions> } // 2026-08-29, hierarchy sidebar
// Where a *file-scope* declaration sits as a client counts positions, so an
// editor can be pointed at a module in a closed file with no read at all.
// `None` for a member: members outnumber units by two orders of magnitude and
// nothing wants theirs, and the record's `U` and `M` groups are separate, so a
// member spends no field on the absence.
struct DeclPositions { name: Utf16Range, decl: Utf16Range }
struct Utf16Range { start: Utf16Pos, end: Utf16Pos }
struct Utf16Pos { line: u32, character: u32 }        // 0-based line, UTF-16 units
struct WorkspaceSymbol<'a> { name: &'a str, container: Option<&'a str>, def: &'a Def }
struct IndexCounts { files, modules, packages, typedefs, members, defines }

// The overlay
fn resolve_external(&Semantics, &WorkspaceIndex) -> ExternalResolutions;

enum ExternalTarget { Resolved(Def), Ambiguous(Vec<Def>), StillUnresolved }
impl ExternalTarget { fn defs(&self) -> &[Def]; fn best(&self) -> Option<&Def>; }
// StillUnresolved deliberately does not distinguish "package absent from the
// workspace" from "package found but member absent" (QA find, lead-ruled):
// both answer an LSP definition request the same way (no target), and the
// in-file analog of the second case is already Resolution::NotFound before
// the overlay is consulted. If a diagnostic ever wants the distinction, add
// a variant then — not speculatively now.

impl ExternalResolutions {
    fn get(&self, ReferenceId) -> Option<&ExternalTarget>;
    fn iter(&self) -> impl Iterator<Item = (ReferenceId, &ExternalTarget)>;  // reference order
    fn counts(&self) -> (usize, usize);                                      // (answered, total)
    fn definition_of(&self, &Semantics, offset: u32) -> Option<Definition<'_>>;
}

enum Definition<'a> { Local(&'a Symbol), External(&'a [Def]) }

Additive changes to vlog_semantic's existing API (nothing removed, nothing renamed): ReferenceId(pub u32), Semantics::reference(ReferenceId) and Semantics::reference_id_at(offset) — the overlay needs a stable key for a reference, and index-into-references() is the one that already exists implicitly.

The two layers, and why they are two

analyze gives a file's Semantics; resolve_external gives an ExternalResolutions beside it. Semantics is never mutated.

  • A file's own analysis is true regardless of what the rest of the workspace is doing. Folding workspace answers into it would make every Semantics stale the moment any other file is edited.
  • The two layers are invalidated by different events — editing this buffer invalidates the Semantics, editing any other file invalidates the index — so a server recomputes whichever one changed and recomposes cheaply.
  • Composition is one function: ExternalResolutions::definition_of asks the in-file layer first (a local declaration always wins over a workspace one), then the overlay, then falls back to "the cursor is on a declaration". Semantics::definition_of still works alone, for a server with no workspace open.

The overlay holds an entry for every reference the in-file layer left as ExternalCandidate, and — since 2026-08-26, docs/features/overlay-promotion/README.md — for an InheritedCandidate when one of its paths actually lands. A locally-resolved reference is absent from it entirely, and so is an inherited candidate nothing answered: the base class is the in-file layer's answer and this layer does not overrule it, it only adds a location when the unit table has one. So an entry still means "the workspace had something to say about this name".

Resolution rules

An external candidate carries paths — every import in the lexical chain that could supply the name, in the order they are written, or the single unit name for an instantiation. The paths are tried in that order and the first path with any hit wins:

  1. p::* and p::x both mean the name this use spells, inside unit p — looked up in the index's member table for p. (For p::x the tail always equals the use's own name, both for a p::x expression and for an import p::x that only offers itself for the name x; the use's name is what is looked up, so the two spellings need no separate handling.)
  2. A bare path is the unit itself when the use spells the unit's name — an instantiated module, the p head of p::x, the package of an import, and (since overlay-promotion) the last path of an unqualified miss written in a type position, which is how a cross-file interface or package-less class used as a type is answered. A miss in a value position never gets such a path, so this layer is never asked to match a bare expression identifier against a unit name.
  3. A bare path whose name differs from the use's is a member of that unit: the .port (or .PARAM override) of a connection to a module declared in another file.

Two paths that could both supply the name do not make an ambiguity: the first one written wins, which is exactly the rule the single-file layer already applies to two in-file wildcard imports ("imports are consulted in the order written"). Ambiguity means something else — see below.

What is indexed

  • Units (units(name)): every file-scope module, package, typedef and class. File-scope typedefs are indexed for workspace_symbols and for a future include-aware lookup; nothing resolves to them today, because a use of a type declared in another file with no import path is NotFound, not an external candidate, and so never reaches this layer. Since 2026-08-26 they do resolve, from a type position: such a use is an external (or inherited) candidate carrying the bare name, so a file-scope typedef, class or interface in another file is reachable from the declaration that names it as a type (docs/features/overlay-promotion/README.md). Only from a type position — the same name in an expression is not offered here.
  • Package members: everything declared at a package's top level — params, typedefs, enum variants, functions, tasks, nets and vars. This is what makes import p::* and p::x reach into the package's file.
  • Module members: ports and parameters only. That is exactly what a connection list or a #(.W(8)) override can name; an internal net of another module stays unreachable, which is correct and is a test.
  • `define tables: defines::collect_defines per file, keyed by FileId, read off the same token stream the parse used.
  • Reference postings: uses of the externally reachable declarations above. Each file persists local declaration/use span pairs and unresolved external candidates; after every build or incremental update, the merged declaration tables resolve those compact facts into DefinitionKey -> [ReferenceSite]. Ambiguous candidates are marked rather than assigned to a guessed target.

A declaration whose name_span is empty (the single-file layer's "I could not locate this name in the source") is not indexed: an editor must never be sent to a zero-width range.

Duplicates and ambiguity

Real workspaces collide: the corpus declares the same module name in several files (vendored copies, _reg_top variants, an .sv and a .v of the same block). Every declaration is kept.

  • units(name) / member(unit, name) return all of them, in disambiguation order: by file path (byte-wise PathBuf sort), then by position within the file. FileIds are assigned in that same sorted order, so FileId order is path order, and the order does not depend on the order the caller happened to hand the files over (asserted by a test).
  • One hit → ExternalTarget::Resolved. Several → ExternalTarget::Ambiguous holding all of them in that order. best() takes the first; Definition::External hands the whole slice to the caller, because LSP's textDocument/definition accepts several locations and showing all of them is more honest than silently picking one.
  • No kind filtering: a name declared as a module in one file and a package in another is ambiguous over both. Distinguishing them would need the reference to say which it wanted, which the recorded paths do not carry.
  • A path handed to build twice is one file; the first copy wins.

`define lookup has a home, not a policy

find_define(name) returns every definition in the workspace, in file order. Which one a given use actually sees depends on the `include graph and on `ifdef, neither of which this index models (and neither of which the define table models either — docs/features/define-table/README.md). Hover can show "defined as 8 in defs.svh:12, as 16 in other.svh:3"; picking one silently would be a guess. defines(file) is the exact per-file table when the caller does know which file it means.

Assumptions

  • The caller does the I/O, the file discovery and the encoding decisions, and hands over (PathBuf, &str). build does the tokenizing and parsing itself (with the tolerant parser) so that every file contributes the declarations that did parse — 42 % of corpus files still hit a parse error, and a workspace index that skipped them would be useless on real RTL.
  • Sources outlive the build call only; the index copies out the names and spans it needs and keeps no borrow. Slicing a Def.name_span is the caller's job, against the same text it passed in — the index does not retain file contents (860 corpus files are ~30 MB; keeping them would double the memory a server already spends on open buffers).
  • A file that does not lex (an unterminated string or block comment) still gets a FileId and an empty define table, and contributes no declarations. The lexer is all-or-nothing, so there is nothing to salvage.
  • The corner where a module's name equals one of its own port names (module foo (input foo);, and a connection .foo(x) on it) resolves the bare path to the module rather than the port, by rule 2 above. Nothing in the corpus does this.
  • build is O(files) and single-threaded. Measured at 860 files below; a workspace an order of magnitude larger would want the same rayon treatment lucisv already applies to formatting, which is a change of caller, not of this API.

Non-goals

  • No incrementality. build is a pure function of its inputs; a changed workspace means calling it again. TODO.md §6 defers salsa-style incrementality explicitly, and per-file recompute is fine at Verilog sizes. Superseded (incremental-index, 2026-08-27): one file at a time. WorkspaceIndex::update_file(path, src) and remove_file(path) replace one file's contribution, and what they produce is the index a whole build over the same files would have produced — same FileIds, same disambiguation order, same tables — because the merge they run is finish's own loop restricted to the keys that file could have moved. build is still a pure function of its inputs and is still what a caller with no reason to be clever should use. This is not salsa: there is no query graph and no dependency tracking, just one file's records replaced in a sorted list.
  • No `include following. The index does not build the include graph, so it cannot say which define or which typedef a given file actually sees.
  • No elaboration: no parameter binding, no instance hierarchy, no cross-file type checking.
  • No filesystem walking, no config discovery. The caller decides what the workspace is.
  • The index does not rewrite Semantics. By design, see the two layers above.

Handshakes

Consumed from vlog_parser:

  • tokenize, parse_tolerant, parse_source_tolerant — the tolerant path, never failing.
  • defines::collect_defines(&[Token]) -> DefineTable, Define, DefineTable::all/latest/entries.
  • span::TextRange.

The concurrent parser change adding name_span to AST nodes (the handshake docs/features/vlog-semantic/README.md filed) landed mid-run. This module was written against the AST as it stood and does not adopt the new fields: it consumes only Symbol.name_span from vlog_semantic, whose meaning is unchanged by where the span comes from. Nothing here needs revisiting when scan.rs is deleted.

Consumed from vlog_semantic (this crate):

  • analyze, Semantics::{scope, symbol, references, reference, file_scope, symbol_at, reference_id_at}, Symbol.{name, kind, name_span, child_scope}, Scope.symbols, Resolution::ExternalCandidate { paths }.
  • The paths contract in particular: "every import in the chain that could supply the name, in scope order" for a lexical use, "p::x" for a package member, the bare unit name for an instantiation or a .port. The three rules above are exactly a reading of that contract; if bind.rs/resolve.rs ever change the spelling of a path, follow_one in workspace.rs changes with it.

Promised to consumers (lucisv_server):

  • WorkspaceIndex::build never panics and never fails, on any input, including files that do not lex.
  • The index is deterministic: same (path, source) set → same FileIds, same order in every returned slice, regardless of iteration order.
  • Def.name_span is a non-empty byte range in Def.file that slices back to exactly the name that was looked up (asserted over the whole corpus).
  • Def.lines (2026-08-28, docs/features/hover-line-index/README.md) is the 1-based line each of those spans falls on, read off the same text the span was read from, in the same pass. It is what lets a consumer print file:line for an indexed declaration with no file access at all. A line is not text: the index still keeps no file contents, exactly as it keeps no contents for the spans it has always held. The field is a struct rather than a bare number so richer per-declaration position data extends it by gaining a field — members are Decls like units are, so a module's ports already carry their own lines here.
  • resolve_external does not mutate Semantics and holds no borrow of the index in its result.

Corpus acceptance

cargo test -p vlog_semantic --test workspace -- --nocapture, over the 860 .v/.sv/.svh files in corpus/ (Ibex, OpenTitan, PULP common_cells, picorv32), 2026-08-19:

workspace index: 860 files in 0.68s — 521 modules, 63 packages,
                 38 file-scope typedefs, 8044 exported members,
                 502 define directives

Build time is a debug build, single-threaded, sources already in memory (reading them costs the caller another ~0.1 s). Well inside the ~2 s budget; re-running the whole build on every workspace change is affordable , which is why there is no incrementality — but not on every save, which is why there is now update_file (incremental-index, 2026-08-27): one file costs 33 ms against the whole rebuild's 1.5 s.

The headline. For each file: analyze it, resolve its external candidates against the index, and count what happened.

population references external candidates workspace answers one target ambiguous still unresolved external rate after
every file 73 708 14 325 (19.4 %) 81.4 % 75.4 % 6.0 % 18.6 % 3.6 %
files that parse cleanly 46 408 9 101 (19.6 %) 87.0 % 78.9 % 8.1 % 13.0 % 2.6 %

Read against docs/features/vlog-semantic/README.md's baseline: on cleanly parsed files the single-file layer resolved 79.5 % of uses and left 19.6 % as external candidates. The workspace layer answers 87 % of those, so the unresolved-external rate over all references falls 19.6 % → 2.6 %, and ~96 % of every identifier in the corpus now has somewhere to jump to. "Ambiguous" counts as answered: it is a list of real locations, which is what LSP's definition request takes.

Re-measured 2026-08-26 (overlay-promotion), same command, same corpus. The table above had gone stale by several rounds, so the before column is a fresh measurement of 3bc61f9. The index itself did not change: 860 files in 0.78 s, 561 modules, 63 packages, 22 file-scope typedefs, 258 classes, 11 937 exported members, 507 define directives, before and after, determinism assertions green.

The middle column is the round's first cut, which promoted every unqualified lexical miss; the last is what shipped, promoting only misses written in a type position. QA found that the first cut let rename rewrite an unrelated file's declaration when an unbound expression identifier happened to match a workspace unit name, so the value half was given back (docs/features/overlay-promotion/README.md). Both are shown because the difference between them is the honest price of that fix.

metric (clean files, 853 of 860, 94 384 references) before promote everything type positions only (shipped)
handed to the workspace layer 16 133 (17.1 %) 17 877 (18.9 %) 16 689 (17.7 %)
…of which inherited candidates 0 520 403
answered 89.3 % 83.7 % 88.8 %
one target / ambiguous 83.9 % / 5.3 % 78.9 % / 4.8 % 83.6 % / 5.2 %
still unresolved (of those handed) 10.7 % 16.3 % 11.2 %
references with nowhere to jump, both layers 10 794 (11.4 %) 10 235 (10.8 %) 10 376 (11.0 %)

All files: nowhere to jump 10 992 (11.6 %) → 10 431 (11.0 %) → 10 572 (11.2 %).

What survived and what was given back. Against the 3bc61f9 baseline, 418 references on clean files gained somewhere to jump and none lost one (420 over all files). The first cut gained 559 on clean files (561 over all), so 141 gains were given back — identical on both populations. They split 117 inherited-candidate answers (520 → 403) and 24 external-bucket answers, and every one of them was a value-position identifier answered on nothing but a name collision. That is the trade, stated plainly: a quarter of the round's jump targets were coincidences, and a coincidence that rename can act on is worth less than nothing.

The answer rate moving is a denominator, not a result. This layer is now handed 556 more references than before (153 that were spelled NotFound and never offered, 403 inherited candidates), and some of them are names no workspace could hold. The number that cannot move by re-spelling is the last row, which is why the Tally in tests/workspace.rs prints it.

Where the ambiguity comes from — all of it real, none of it a defect. The top shapes are OpenTitan's technology libraries: prim_buf, prim_flop, prim_xor2 and their ports/params are declared once in ibex/vendor/lowrisc_ip/ip/prim_generic/rtl/ and again in .../prim_xilinx/rtl/. Which one a build uses is a build-system choice this index has no access to, so both are offered. 98 distinct ambiguous shapes in the whole corpus.

The honest gaps (top unresolved paths, clean-file population):

path uses what it is
picorv32 429 is in the corpus, but its module header contains a `ifdef inside the port list, so the declaration is swallowed by an error node and never indexes. Moves when the parser moves, not when this feature does.
sail_ibexspec 168 a formal-verification model not vendored into the corpus
picorv32_axi 141 same `ifdef-in-header problem as picorv32
SB_SPRAM256KA 44 an iCE40 vendor primitive — no source anywhere
PLLE2_ADV 32 a Xilinx vendor primitive — likewise

After the 2026-08-26 re-measurement the same list reads sail_ibexspec (168), ibex_pkg::* | uvm_pkg::* (83, e.g. id_stage_i), ibex_pkg::* (71, e.g. main_mode), clk_rst_gen (60) and SB_SPRAM256KA (44) — the picorv32 entries are gone, closed by the parser rounds since. Every remaining one is still a workspace that genuinely does not contain the definition.

Over all files the list also shows uvm_pkg::* (220) and uart_reg_pkg::* (214) — a verification library and a generated register package, neither checked into the corpus. Every one of these is a workspace that genuinely does not contain the definition; none is a lookup this layer got wrong.

Properties the test asserts (not the percentages): no panic anywhere; build twice over the same sources gives byte-identical file ids, counts and symbol fingerprint; every single answer's name_span slices back to exactly the name the reference spells, in the file the answer names; build under 5 s; and more than half of all external candidates answered on clean files.

Status / TODO

  • crates/vlog_semantic/src/workspace.rs: WorkspaceIndex::build over (PathBuf, &str) pairs, tolerant parse inside
  • Units indexed: modules, packages, file-scope typedefs — duplicates kept, path-sorted disambiguation order
  • Members indexed: package exports (params, typedefs, enum variants, functions, tasks, nets, vars) and module ports/params
  • Per-file `define tables + workspace-wide find_define
  • resolve_external → ExternalResolutions overlay keyed by ReferenceId, Semantics untouched
  • 2026-08-26 (overlay-promotion): the overlay also answers an InheritedCandidate from its paths, recording an entry only when one lands; Tally reports references with nowhere to jump
  • Composed definition_of, workspace_symbols, members_of
  • Unit tests: cross-file instantiation, cross-file port, wildcard and explicit import, package member, enum variant, duplicate → Ambiguous, broken file, empty workspace, rebuild after edit, path-order independence, define lookup
  • Corpus acceptance: build time, counts, resolution rate, determinism, every answer's span slices back to the name
  • TODO.md §6 workspace-index checkbox
  • 2026-08-27 (incremental-index): update_file/remove_file, exactly equal to a whole build; instantiation and inheritance edge tables (instantiations_of, subclasses_of); fingerprint as the equivalence witness
  • 2026-08-27 (references-nav performance): persisted reference facts, declaration-to-occurrence postings, ambiguity markers and indexed macro lookup; reference postings included in the incremental fingerprint
  • Deferred (non-goals above): `include graph, elaboration

Work log

2026-08-28 — declaration lines (docs/features/hover-line-index/README.md). Def and the per-file Decl gained lines: DeclLines { name, detail }, the 1-based source lines of name_span and of detail_span, computed in facts_from_analysis from a LineIndex over the file being indexed. FileFacts::from_analysis takes that index as a parameter (its one real caller already holds one); FileFacts::of builds its own. The record format grew two fields per declaration and FACTS_FORMAT went 3 → 4. WorkspaceIndex::fingerprint's sym line carries the lines, so the incremental-equals-fresh witness covers them — every existing equivalence test stayed green unmodified. Cost, measured over the corpus: the whole scan is unchanged inside its noise (one LineIndex::new per parsed file, under 1 % of that file's parse) and the persistent store grows 68 KB over 860 files, 2.9 %.

2026-08-27 — indexed navigation. FileFacts gained compact local and external reference records and its persisted format moved to version 2. WorkspaceIndex resolves them into reverse postings after declaration tables are merged, including on an incremental update, without rereading or reparsing other files. The public query is references_to; ambiguous external uses are tracked separately so navigation preserves the existing rename refusal. Three focused tests cover postings, incremental/full-build equivalence, and ambiguity, while the record round-trip and corpus acceptance cover persistence and real-source scale.

2026-08-26 — overlay-promotion dev agent (lead-authorized, cross-module). resolve_external gained one arm: an InheritedCandidate's paths are tried like an external candidate's, and an entry is recorded only when one lands, so a name this layer cannot answer stays exactly what the single-file layer made it. counts()'s doc says what it counts now. tests/workspace.rs's Tally reports references with nowhere to jump after both layers, because a re-spelled miss moves between the other columns without anything getting better or worse. Corpus tables above re-measured before, after the first cut, and after the fix round that narrowed the promotion to type positions. Rationale and the full audit: docs/features/overlay-promotion/README.md.

2026-08-19 — dev agent. Built workspace.rs and tests/workspace.rs. Key decisions, all argued above:

  • Overlay, not mutation. The task named this; the argument that made it obviously right is invalidation: the two layers go stale on different events.
  • Members are indexed for modules too, not only packages. The single-file layer emits an external candidate for every .port of every instantiation of an out-of-file module, and on this corpus those are a large share of all external candidates — indexing ports and params costs one matches! arm and converts them. Restricted to ports and params so an internal net of another module never becomes reachable.
  • First path wins; ambiguity is per-path. Consistent with the single-file rule for two competing in-file imports. Ambiguity is reserved for the thing it really means — the same name declared in more than one file.
  • FileId follows sorted paths, assigned after sorting inside build, so determinism does not depend on the caller and "disambiguation order" is simply ascending FileId.
  • Empty name_spans are dropped rather than indexed: the single-file layer documents an empty span as "the name is not literally spelled here", and an editor sent to a zero-width range is worse than no answer.
  • find_define returns all definitions. No include graph exists, so any single answer would be a guess; the table is a home for the lookup, not a policy.

Two additive items in the existing crate API (ReferenceId, Semantics::reference/reference_id_at) — an overlay needs a key, and reference_at returned only a &Reference, which cannot be used as one.

Checks at the end: cargo test -p vlog_semantic 46 tests green (6 scan unit + 19 behavior + 1 vlog-semantic corpus + 20 new), cargo clippy -p vlog_semantic --all-targets silent, cargo fmt -p vlog_semantic -- --check clean, cargo test --workspace green (19 test binaries, 0 failures).

Mid-run the parser agent's name_span change landed and briefly broke vlog_parser/bind.rs compilation. Per the task brief this module did not adopt the new AST fields; it depends only on vlog_semantic's own Symbol.name_span, so it needed no change once their work compiled again.

QA log

2026-08-19 — QA agent. Verified every claim in the review request. No BLOCKING findings (no silent corruption, no wrong definition target, no nondeterminism). Two minor, non-blocking findings below.

Gates (-p vlog_semantic).

  • cargo test -p vlog_semantic: 46/46 green — 6 scan unit + 1 corpus + 19 semantics + 20 workspace, matching the claim exactly.
  • cargo clippy -p vlog_semantic --all-targets: silent.
  • cargo fmt -p vlog_semantic -- --check: clean.
  • cargo test --workspace: green, 19 test binaries (16 with tests + 3 doc-test binaries at 0 tests each), 0 failures. Ran clean on the first try; no vlog_parser churn observed during this pass.
  • git diff -- crates/vlog_semantic/src/lib.rs crates/vlog_semantic/src/model.rs: confirmed additive-only — mod workspace;, the workspace::* re-export block, ReferenceId (new struct in model.rs), and Semantics::{reference, reference_id_at} are all new; nothing renamed or removed. (bind.rs also has unrelated non-additive edits adapting to the concurrent parser's name_span/ImportPath change — outside this feature's scope, not evaluated here, and not part of the workspace-index diff.)

Corpus numbers — reproduced exactly, 3 runs:

workspace index: 860 files in 0.70s / 0.70s / 0.69s — 521 modules, 63 packages,
                 38 file-scope typedefs, 8044 exported members, 502 define directives

Every count byte-identical across all 3 runs; times within the claimed 0.68–0.71 s band. Full headline table (every file / clean files) reproduced exactly: 73708/14325(19.4%)/81.4%(75.4%+6.0%)/18.6%/3.6% and 46408/9101(19.6%)/87.0%(78.9%+8.1%)/13.0%/2.6% — matches the README table and work-log figures to the decimal. Spot-checked the ambiguity claim independently: corpus/ibex/vendor/lowrisc_ip/ip/prim_generic/rtl/ and .../prim_xilinx/rtl/ do contain the same file basenames (prim_and2.sv, prim_buf.sv, prim_clock_buf.sv, prim_flop.sv, prim_pkg.sv, ...) — the OpenTitan ambiguity claim is real corpus structure, not asserted blind.

Attack probes (18 scratch tests, crates/vlog_semantic/tests/qa_probe.rs, written, run, and deleted — no trace left in the tree):

  • Same module name in 3 files, 4 permuted input orderings: all kept (units("dup").len() == 3), ascending FileId, FileId order == path order (a_first.sv < b_second.sv < c_third.sv) regardless of caller order, and the resulting Vec<Def> byte-identical across all 4 orderings.
  • Garbage-only file (@@@ !!! not verilog): 1 file id, 0 declarations, no panic. Unlexable file (unterminated string): still gets a file id and an empty define table, no panic.
  • Same path handed twice with different content (not just identical content, which is all the existing suite covers): one file in the index either way; content of the first entry in the caller's input order wins (verified both orderings — first-wins is consistent with build's sort_by being a stable sort over equal keys, then dedup_by keeping the first of each run). Matches the documented "first copy wins" rule. Not silent corruption — deterministic and exactly what the README promises.
  • Package member name shadowing a module name workspace-wide: units() and member() are confirmed separate namespaces — units("shadow") sees only the module, member("p", "shadow") sees only the package member, no cross-contamination.
  • Empty-string source: 1 file id, zero of everything, no panic. Zero-member package (package p; endpackage): unit indexed as Package, members_of empty, member("p", anything) empty — no panic on an empty child scope.
  • import p::absent_member where p is declared in another file but has no such member: 2 external candidates come out of this one import statement — the path head p itself (resolves fine to the package, since p really is in the workspace) and the tail absent_member (ExternalTarget::StillUnresolved, confirmed via overlay.get). Compared against the in-file equivalent (p declared in the same file, p::absent_member used): resolve.rs's Target::PackageMember arm returns Resolution::NotFound directly when the package is known locally and lacks the member — it never becomes an ExternalCandidate at all (overlay.counts() is (0, 0) for that reference). So the two layers are behaviorally consistent (both end in "no target" for a real absence) but representationally different: in-file collapses to NotFound before the overlay ever sees it, cross-file surfaces as StillUnresolved because ExternalTarget has no NotFound variant to distinguish "no such member" from "no such package in the workspace either." This asymmetry is not documented anywhere in the README's Resolution rules section. Minor, non-blocking — the observable behavior (no definition offered) is correct either way, but a future consumer inspecting ExternalTarget variants alone cannot tell "package exists, member doesn't" from "package doesn't exist in the workspace at all." Worth a one-line mention in Resolution rules or Assumptions if the lead wants it; not fixed here per the write-scope restriction on this pass (QA log only).
  • find_define("K") defined in 3 files with 3 different values: all 3 returned, in file-path order (a.svh < m.svh < z.svh), not value order and not any other ranking — confirms "no resolution order is implied" as documented.

Overlay correctness (3-file scratch workspace: A instantiates B, imports p::*, uses p::K and absent q::Z):

  • Instantiation of b in A resolves via definition_of to Definition::External pointing at B.sv, name_span slices to exactly "b".
  • K resolves to Definition::External pointing at P.sv, slices to "K".
  • q::Z (q not declared anywhere): definition_of returns None, and the underlying overlay entry is confirmed ExternalTarget::StillUnresolved (not just "None for some other reason").
  • A local symbol (localparam int SHARED inside the module) shadowing an imported package member of the same name: definition_of returns Definition::Local pointing at the in-file declaration — two-layer precedence (local always wins over the overlay) confirmed.
  • reference_id_at(offset) round-trips: any offset inside a reference's name span maps to the same ReferenceId, and sem.reference(id) gives back the right reference.

workspace_symbols probes:

  • True substring match (not prefix-only): "FIFO" matches my_fifo_thing (match in the middle of the name).
  • Case-insensitive both directions: "FIFO" and "fIfO" both match my_fifo_thing.
  • Empty query: matches both units and members (confirmed a package unit and one of its members both appear).
  • A query matching a unit and a member of the same spelled name ("shadow" module vs. p::shadow param, same fixture as the namespace probe): both appear, exactly 2 hits, one with container: None and one with container: Some("p") — no cross-contamination in workspace_symbols either.
  • "zzz" (no match): empty result, no panic.

Determinism stress: corpus index counts identical across 3 independent full 860-file builds (see corpus numbers above); a 3-file local workspace built 5× in a row gives byte-identical IndexCounts every time; the corpus test's own internal build-twice-and-fingerprint-workspace_symbols("") assertion also passed. No nondeterminism found anywhere probed.

CLAUDE.md compliance:

  • No unwrap()/expect()/panic! anywhere in workspace.rs (grepped, zero hits) — library code paths return Option/empty slices instead, as required.
  • README has all required sections (Goal, Assumptions, Handshakes, Status/TODO, Work log, QA log, Review) present and populated.
  • TODO.md §6 "Workspace index for cross-file navigation" checkbox: checked, and the summary line under it (87% of external candidates, 19.6%→2.6%, 0.7s/860 files) matches the reproduced corpus numbers exactly — honest.
  • The stale out-of-scope line noted in docs/features/vlog-semantic/README.md (line 223, "Requested of vlog_parser — not done here — out of scope for this...") was located but left untouched per instructions — lead's call, not this feature's file.
  • One doc-comment gap found: IndexCounts in workspace.rs (around line 238) has doc comments on files, typedefs, members, defines but not on pub modules: usize or pub packages: usize — the only two undocumented public fields found in the whole module. Minor, non-blocking, self-explanatory field names, not fixed here per the write-scope restriction (docs/features/workspace-index/README.md QA log only, no source edits this pass).

Verdict: PASS on all 6 claims. No blocking findings. Two minor, non-blocking documentation gaps noted above for the lead/dev to close: (1) IndexCounts::modules/IndexCounts::packages missing doc comments, (2) the cross-file-vs-in-file NotFound/StillUnresolved asymmetry for "package known, member absent" is real, consistent in effect, but undocumented.

Review

2026-08-19 — lead. Verdict: accepted; commits jointly with name-spans (round 10). The owner's cross-file requirement — import pkg::*; at the top of a file resolving anywhere in the workspace — is now met.

Points reviewed and accepted:

  1. The two-layer overlay design is the architectural decision of the round: Semantics stays a pure single-file fact, the overlay is keyed by ReferenceId, and the two invalidate on different events (this buffer vs. any other file). That's the shape an editor actually needs, and it kept the whole feature additive — QA confirmed nothing in the existing API was renamed or moved.
  2. FileIds assigned after path sort makes determinism a property of the data, not the caller — QA's permuted-input and same-path-different-content probes are exactly the attacks that design defeats.
  3. Ambiguity kept, not resolved: OpenTitan's prim_generic vs prim_xilinx duplicates are real, and handing all locations to the LSP (which supports several) is more honest than inventing a ranking. Same reasoning accepted for find_define being unranked without an `include graph.
  4. 87% of external candidates answered (19.6% → 2.6% on clean files), with the residue traced to named causes — the `ifdef-in-port-list parse gap (roadmap item 6) and genuinely absent sources. The acceptance metric was measured against the number the vlog-semantic review set, which is how these baselines are supposed to work.

Lead fixes on acceptance: the two missing IndexCounts doc comments, and QA's notable finding — StillUnresolved not distinguishing package-absent from member-absent — is now documented as a deliberate ruling in the API sketch above (both mean "no target" to an LSP; add a variant when a diagnostic needs it, not speculatively).

With this, TODO §6's foundations are all delivered: spans, tolerant parsing, define table, single-file semantics, workspace index. What remains is the server itself and editor packaging.