Indexed references: postings replace the per-request refactor walk
textDocument/references now reads declaration-to-occurrence postings merged in WorkspaceIndex from compact per-file reference facts, with open buffers overlaying live semantics — 0.062 ms/request over 820 files vs 21.7 ms for the old Workspace::sources() walk (~350x). The walk stays as rename's engine and the equivalence oracle in tests. FACTS_FORMAT 1->2 discards v1 caches whole. Cursor lookups (symbol_at/reference_at/token_at) and macro-define lookup move to binary-searched sorted tables; include definition inspects only the cursor's line. Ambiguity refusals preserved throughout. External dev: codex. Lead-reviewed, gates re-run, probe reproduced. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
27fc216df3
commit
b2d778eb8d
13 files changed
+768
-81
No files matched your search
@@ -29,22 +29,24 @@ predicate, and three handlers.
|
||||
edited but not saved, when the file is new) is answered in-file until the
|
||||
next rebuild. That is the same staleness window every other cross-file
|
||||
answer already has, documented in `docs/features/lucisv-server/README.md`.
|
||||
- **A references answer costs what a rename costs.** The cross-file path calls
|
||||
`Workspace::sources()`, which re-reads every in-scope file, and then
|
||||
re-analyzes the files that spell the name. Measured at 218 ms over the
|
||||
860-file corpus (below); the gate above is what keeps a local signal at
|
||||
1 ms rather than paying that on every request.
|
||||
- **A references answer is an indexed lookup.** Each `FileFacts` record stores
|
||||
compact facts for references to externally reachable declarations. The
|
||||
finished `WorkspaceIndex` resolves those facts once into declaration-to-use
|
||||
postings, and a request reads only that posting list. Open documents replace
|
||||
their saved postings with live `Semantics`, preserving unsaved additions and
|
||||
deletions. The old `Workspace::sources()` + refactor walk remains rename's
|
||||
correctness engine but is no longer on the references request path.
|
||||
- **A refusal degrades to the in-file answer, it is not an error.** The shared
|
||||
engine refuses an ambiguous name (declared in two indexed files) exactly as
|
||||
a rename does. `textDocument/references` is a read-only convenience, so the
|
||||
handler sends the file's own occurrences rather than a `RequestFailed`: a
|
||||
highlight the editor can draw beats a shrug, and the refusal the user
|
||||
actually needs to see is the one on the rename they then attempt.
|
||||
- **Reference spans are trusted the way rename trusts them**, minus the edit
|
||||
safety check: `find_references` still drops any span that does not slice
|
||||
back to the name it claims, but it does not run the re-parse verification
|
||||
pass, because it produces no edits and CLAUDE.md invariant #1 is about
|
||||
output, not about a list of places.
|
||||
- **Reference spans are produced by the semantic analysis and versioned with
|
||||
the file facts.** A cache entry is content-addressed, so a saved span cannot
|
||||
be paired with different bytes; an open file contributes live spans instead.
|
||||
Location conversion fetches and line-indexes each touched file once, however
|
||||
many occurrences it contains.
|
||||
- **Read/write is not distinguished** in `documentHighlight`. LSP permits a
|
||||
plain `Text` kind, and telling a read from a write in Verilog means
|
||||
classifying continuous vs. procedural assignment, port direction and
|
||||
@@ -56,7 +58,8 @@ predicate, and three handlers.
|
||||
|
||||
## Handshakes
|
||||
|
||||
**New public API in `vlog_refactor`** — the one handshake this round changes:
|
||||
**The original public API in `vlog_refactor`**, retained for rename and as the
|
||||
equivalence oracle in tests:
|
||||
|
||||
```rust
|
||||
pub fn find_references(
|
||||
@@ -72,7 +75,7 @@ current text, open buffers already overlaying disk). The result is sorted by
|
||||
path then by position; an `Err` is the sentence a rename at that position
|
||||
would refuse with.
|
||||
|
||||
**Where the sharing lives, and why there.** The collection walk is
|
||||
**Where the original sharing lives.** The collection walk is
|
||||
`Scope::collect_occurrences` in `crates/vlog_refactor/src/rename.rs` — lifted
|
||||
out of `collect_edits`, which now calls it and turns the spans into edits.
|
||||
`find_references` (`crates/vlog_refactor/src/references.rs`) calls the same
|
||||
@@ -81,15 +84,24 @@ spans. The alternative considered was lifting the walk into `vlog_semantic`;
|
||||
it was rejected because the walk is not a semantic query — it needs the
|
||||
`Scope` cache, the workspace overlay *per file*, and the ambiguity policy,
|
||||
all of which are refactor-crate concerns, and `lucisv_server` already depends
|
||||
on `vlog_refactor`. Copy-pasting the walk into the server was never on the
|
||||
table: a references list that disagreed with what a rename would touch is a
|
||||
lie about what lucisv is going to do.
|
||||
on `vlog_refactor`. The indexed implementation is compared directly with this
|
||||
walk in the server tests, so moving the hot path does not create a second
|
||||
semantic answer.
|
||||
|
||||
**Consumed from `vlog_semantic`** (all pre-existing, nothing requested):
|
||||
**New public API in `vlog_semantic`:** `WorkspaceIndex::{file_id,
|
||||
references_to, references_are_ambiguous}`, plus `DefinitionKey` and
|
||||
`ReferenceSite`. `FileFacts`' encoded shape now includes local and unresolved
|
||||
external reference facts, and `FACTS_FORMAT` is **2**. A changed file rebuilds
|
||||
the merged postings from compact in-memory facts; it does not reread or parse
|
||||
the other files. `Semantics::{symbol_at, reference_at, reference_id_at}` and
|
||||
`Document::token_at` now use start-sorted position tables and binary search.
|
||||
|
||||
**Consumed from `vlog_semantic`:**
|
||||
`Semantics::{reference_at, reference_id_at, references_of, symbol, symbol_at,
|
||||
scope}`, `Scope::owner`, `Symbol::{name, scope, name_span}`,
|
||||
`ExternalResolutions::get`, `ExternalTarget::best`,
|
||||
`WorkspaceIndex::{units, member}`.
|
||||
`WorkspaceIndex::{units, member, file_id, references_to,
|
||||
references_are_ambiguous}`.
|
||||
|
||||
**Consumed from `vlog_parser`**: `token::Comment { span }` trivia and
|
||||
`LineIndex::line_col` for folding.
|
||||
@@ -108,11 +120,22 @@ and none was made.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] **Indexed navigation performance (2026-08-27):** persist each file's
|
||||
externally reachable reference facts beside its declarations, merge them
|
||||
into declaration-to-occurrence postings in `WorkspaceIndex`, and route
|
||||
hover/definition/references through indexed cursor and location lookups.
|
||||
Preserve ambiguity refusals and unsaved open-buffer overlays; prove the
|
||||
indexed answer equals the existing refactor walk before removing that
|
||||
walk from the request path. Release probe: **0.064 ms/request** over 820
|
||||
synthetic files and five returned locations, versus **23.431 ms** for
|
||||
the old walk on the same workspace.
|
||||
|
||||
- [x] `Scope::collect_occurrences` factored out of `collect_edits`, with
|
||||
`collect_edits` rewritten on top of it (no behaviour change; the rename
|
||||
suite is the regression test).
|
||||
- [x] `vlog_refactor::find_references`, new module `references.rs`, 7 tests.
|
||||
- [x] `nav::references` routes through it when the symbol can leave the file.
|
||||
- [x] `nav::references` routes through `WorkspaceIndex` postings when the
|
||||
symbol can leave the file; the refactor walk remains its tested oracle.
|
||||
- [x] `nav::leaves_this_file` — the index-only gate that keeps a local signal
|
||||
off the workspace walk.
|
||||
- [x] `nav::document_highlights` — symbol occurrences in this file.
|
||||
@@ -142,6 +165,42 @@ and none was made.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-27 — indexed navigation performance
|
||||
|
||||
- Began replacing the per-request `Workspace::sources()` +
|
||||
`vlog_refactor::find_references` rebuild with reference facts stored in the
|
||||
existing semantic index. The chosen shape is deliberately not a second
|
||||
project model: `FileFacts` remains the per-file persistence and incremental
|
||||
update unit, while `WorkspaceIndex` gains the merged inverted postings.
|
||||
`FACTS_FORMAT` will bump because the persistent record gains fields; the
|
||||
cache's version handshake therefore drops old records rather than reading a
|
||||
partial shape.
|
||||
- Scope remains the scope ladder's decision (filelist exactly when configured,
|
||||
otherwise the folder/workspace setting already in force). This round changes
|
||||
the cost of navigation inside that scope, not which files the user asked the
|
||||
server to index.
|
||||
- Completed the inverted index in the existing `FileFacts` /
|
||||
`WorkspaceIndex` lifecycle. `FACTS_FORMAT` moved from 1 to 2, so an old cache
|
||||
is discarded safely. Incremental save updates rebuild the postings from
|
||||
compact facts already in memory; adding/removing files still follows the
|
||||
index's path-sorted `FileId` contract.
|
||||
- `nav::references` now resolves the live cursor to one indexed declaration,
|
||||
reads its posting list, overlays every open buffer's current semantics, and
|
||||
batches byte-span-to-LSP conversion per touched file. Duplicate declarations
|
||||
and ambiguous uses still fall back to the in-file answer. Permanent tests
|
||||
cover module, package-member and port references, cache round trips,
|
||||
incremental equivalence, ambiguity, unsaved deletions/additions, moved live
|
||||
declarations, and direct equality with `vlog_refactor::find_references`.
|
||||
- Cursor hot paths no longer sweep the whole open file: semantic declaration
|
||||
and reference lookup, plus macro-token hover, use binary-searched position
|
||||
tables. Include definition inspects only the cursor's line.
|
||||
- The ignored release latency probe builds 820 files and returns five
|
||||
locations: **0.064 ms/request** averaged over 200 indexed requests; the old
|
||||
source collection + refactor walk took **23.431 ms** once on the same files
|
||||
(about **366×** slower). Command:
|
||||
`cargo test --release -p lucisv_server
|
||||
qa_indexed_references_latency_over_a_large_workspace -- --ignored --nocapture`.
|
||||
|
||||
### 2026-08-24 — dev agent (M7)
|
||||
|
||||
- **Read first**: `CLAUDE.md`, `docs/features/refactor/README.md`'s triage,
|
||||
@@ -463,6 +522,27 @@ correctness or safety issue in the shipped feature.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-08-27 — lead, indexed-navigation performance round (external dev:
|
||||
codex).** Reviewed the full diff line-by-line and ran all three gates
|
||||
independently (fmt clean, clippy silent, 1155 server tests + workspace
|
||||
suite green). The design keeps the one-project-model rule: reference
|
||||
facts live in `FileFacts` (the existing persistence and incremental
|
||||
unit), postings are merged in `WorkspaceIndex`, and `FACTS_FORMAT` 1→2
|
||||
plus the cache header's format handshake discards every v1 store whole —
|
||||
verified in `index_cache.rs:324`. `macro_definitions` filters
|
||||
`DefineKind::Define`, byte-identical semantics with the
|
||||
`DefineTable::all` it replaces. Ambiguity is preserved everywhere it
|
||||
mattered: ambiguous postings are marked, an ambiguous live overlay use
|
||||
aborts to the in-file answer mid-collection, and the rename refusal
|
||||
contract survives. The equivalence test pins the indexed answer to the
|
||||
old `vlog_refactor::find_references` walk, which stays as rename's
|
||||
engine and the oracle. Lead re-ran the ignored release probe:
|
||||
0.062 ms/request over 820 files vs 21.7 ms for the old walk (~350×),
|
||||
consistent with the work log's numbers. No QA-agent pass this round;
|
||||
the lead review substituted, and the incremental-fingerprint,
|
||||
unsaved-buffer and ambiguity tests cover the paths a QA attack would
|
||||
have targeted. Accepted.
|
||||
|
||||
**2026-08-24 — lead.** Reviewed after QA's ship verdict (clean first
|
||||
pass); gates run independently (1330 tests, 0 failures, clippy silent).
|
||||
The factoring is the right move — `collect_occurrences` peeled out of
|
||||
|
||||
Reference in new issue
Block a user