Merge performance-wave Lane A (prepareRename, rename, willRenameFiles)
ci / checks (push) Successful in 50s
ci / corpus (push) Successful in 20s

Co-Authored-By: Claude Fable 5 <[email protected]>

# Conflicts:
#	docs/perf/README.md
This commit is contained in:
lucio committed 2026-08-29 00:11:42 -07:00
commit ee1efe3fb1
14 files changed
+2744 -39

No files matched your search

+172
View File
@@ -145,6 +145,16 @@ invariant #4 is not in play. The formatter is not involved in this path at all.
have disagreed with the first in the corner cases nobody tests.
- **`IncludeGraph::incdirs()`** — a read-only accessor, so a candidate
spelling can be a suffix under a real include path rather than a guess.
- **`IncludeGraph::includers()`** (added 2026-08-28) — a read-only accessor
over the edge table's keys, which is what lets the sweep read the files
that write a resolving `` `include`` instead of every file in scope. The
property it stands on is `resolve`'s agreement with the `found` the edges
were built from; it is written out under "The sweep reads the includers,
not the workspace", and a change to either half must re-read it.
**Scope note for the lead:** `includes.rs` is outside the Lane A file
list this round was scoped to. The accessor is four lines, purely
additive, and there is no second way to ask the graph this question
without a second copy of the include scan — flagged rather than smuggled.
- **`includes::normalize` is now `pub`** (it was private). A renamed path and
a resolved include are compared, and they must be folded the same way; a
fourth private copy of that loop is the one thing that guarantees they
@@ -212,6 +222,47 @@ probe (`cargo test --release -p lucisv_server --bin lucisv-server
file_ops::tests::perf -- --ignored --nocapture`), the same shape as
`includes.rs`'s: it prints and asserts nothing but the corpus's presence.
### The sweep reads the includers, not the workspace (2026-08-28)
The prefilter above still cost a *read* of every file to run. On OpenTitan
(3 976 files) that is 249 ms of `sources()` per gesture, and the server
advertises `willRename` with a `**` folder filter, so **renaming any folder in
the explorer paid it**.
The include graph already holds the answer. `IncludeGraph`'s edge table is
built as `scan(text).filter_map(|include| self.found(Some(path), include))`
over every in-scope file, and `resolve` is exactly `found` followed by the
index's own spelling of the result — so `resolve` answers `Some` for an
include if and only if `found` did. Therefore:
> **A file with no entry in the edge table writes no `` `include`` this
> workspace can resolve, so every iteration of `will_rename`'s inner loop over
> it hits `let Some(old) = graph.resolve(…) else { continue }`.** It can
> produce neither an edit nor a warning, and reading it is reading the
> workspace to answer "nothing".
`Workspace::include_sources` is that set — `IncludeGraph::includers()` — plus
every **open buffer**, because the graph is rebuilt on save and an `` `include``
typed and not yet saved is in the buffer and in no edge
(`an_unsaved_include_is_still_rewritten`). The one-directional property is
asserted directly over a hostile tree rather than argued
(`nothing_skipped_has_an_include_to_rewrite`: every in-scope file the sweep
skips is checked to have no resolving include, and the tree is asserted to
actually exercise the skip).
Measured, `--release`:
| | before | after |
|---|---:|---:|
| synthetic 506 files, 1 of them including anything | reading the scope **16.1 ms** | reading the includers **18.9 µs**; whole answer **35.4 µs** |
| OpenTitan, 3 976 files, 331 of them includers | `sources()` **249 ms** | whole answer **14.1 ms** |
Same staleness premise the rename family adopted the same day
(`docs/features/refactor-rename/README.md`): the graph is the server's
authority on who includes what, a file changed on disk with nothing telling
this server is a file the sweep does not read, and open buffers are the
exemption.
The notifications cost one `reindex()` each, which is the cost a save has.
## Status / TODO
@@ -230,6 +281,10 @@ The notifications cost one `reindex()` each, which is the cost a save has.
is still one search order and one path folding.
- [x] `watch::watched` made public, so the notifications and the watcher share
one scope test.
- [x] The sweep reads the include graph's includers plus the open buffers
rather than `sources()` (2026-08-28): `IncludeGraph::includers`,
`Workspace::include_sources`, the one-directional property asserted over
a hostile tree, and a before/after probe.
- [x] Tests: 24 in `file_ops.rs`, 7 in `server.rs` (dispatch, warning volume,
reindex, watcher-double, unopened file, `null`), 1 in `main.rs` (the
capability on the wire), 1 e2e session (real binary, edit decoded,
@@ -327,6 +382,45 @@ target/debug/lucisv-server` → OK, 9 messages, unchanged from `bf17ddd`
JSON and adds no message). Perf measured as above. No new dependency, no
version bump, no other crate touched.
**2026-08-28 — dev agent (performance wave, Lane A).** The sweep stops reading
the workspace. `performance.md` §6e flagged `file_ops.rs:120`'s `ws.sources()`
as the same shape as the rename family's, unmeasured; it is 249 ms of file
reading per gesture on OpenTitan, and the server advertises `willRename` with
a `**` folder filter, so **renaming any folder in the explorer paid it** to
learn that 3 645 of 3 976 files write no `` `include`` that resolves.
The include graph already holds that fact. `IncludeGraph::includers()` — four
lines, the edge table's keys — is the new accessor, `Workspace::include_sources`
is the set (includers plus every open buffer, because the graph is rebuilt on
save and an unsaved `` `include`` is in neither `raw` nor `edges`), and
`will_rename`'s loop is otherwise untouched. The argument is one sentence long
and is written up under "The sweep reads the includers, not the workspace":
`resolve` is `found` plus a re-spelling, and `raw` is built from `found`, so a
file with no edge has no include `resolve` answers — every iteration of the
inner loop over it hits its first `continue`.
Rather than argue that by inspection alone it is asserted over a hostile tree:
`nothing_skipped_has_an_include_to_rewrite` walks every in-scope file the sweep
skips and checks each of its `` `include``s resolves to nothing, and asserts
the tree exercises the skip at all. Two behaviour tests beside it —
`the_narrowed_sweep_reads_the_includers_and_answers_the_same` (24 files, 1
includer, 2 with dangling includes) and `an_unsaved_include_is_still_rewritten`.
Measured, `--release`: synthetic 506 files, reading the scope **16.1 ms** →
reading the includers **18.9 µs**, whole answer **35.4 µs**
(`perf::a_will_rename_before_and_after`). OpenTitan, 3 976 files with 331
includers: `sources()` **249 ms** → whole answer **14.1 ms** (throwaway probe
against the local checkout, deleted; no test depends on it).
**One scope deviation, flagged not smuggled:** `includes.rs` is outside the
file list this lane was scoped to, and the accessor was added there anyway.
The alternative was a second copy of the include scan inside `state.rs`, which
is the one thing this module's Handshakes section already says must not
happen. Recorded in Handshakes above and in the round's report.
Gates: `cargo fmt --all -- --check` clean, `cargo clippy --all-targets` clean,
`cargo test --workspace` green, `node editors/vscode/smoke.js` OK.
## QA log
### 2026-08-27 — QA agent, file operations (TODO.md §9c)
@@ -514,8 +608,86 @@ nested-batch ordering is a documentation/robustness suggestion for the dev,
not a blocker — no corruption path exists even in that shape, thanks to the
safety net doing its job independently of what `Moves` models.
**2026-08-28 — QA agent (performance wave, Lane A).** Verified the round that
moves `will_rename`'s sweep off `ws.sources()` onto
`Workspace::include_sources()` (the include graph's `includers()`, plus open
buffers). Worked alongside the rename-family QA pass in the same worktree;
see `docs/features/refactor-rename/README.md`'s QA log for the shared gate
run.
### Gates
`cargo fmt`, `cargo clippy --all-targets`, `cargo test --workspace` (0
failures workspace-wide) and `node editors/vscode/smoke.js` all pass — see the
refactor-rename QA entry for the exact run, which covered this round's diff
in the same pass. `file_ops::tests::perf::one_rename_sweeps_the_whole_corpus_in_milliseconds`
and `includes::tests::perf::building_the_graph_over_the_whole_corpus_is_milliseconds`
fail in this worktree because `corpus/` is not checked out here; confirmed
pre-existing (unchanged by this diff, present at `HEAD` before it) and
unrelated.
### Attacks
The safety-net argument this narrowing rests on ("a file with no entry in the
edge table writes no `` `include`` this workspace can resolve") is
mechanical and did not need attacking on its own terms — `nothing_skipped_
has_an_include_to_rewrite` already asserts it directly over whatever tree a
test builds. What was worth attacking is whether `includers()` narrows in
**every** file that matters, not just the ones the dev's own tree happened to
build:
- **An include chain, `a.svh -> b.svh`, with a third file `c.sv -> a.svh`
never spelling `b.svh` at all.** Renaming `b.svh` must narrow to `a.svh`
(its direct includer) and rewrite only it; `c.sv` must not be mistaken for a
candidate even though it transitively depends on the moved file through
`a.svh`. Added `an_include_chain_narrows_to_the_direct_includer_of_the_moved_file`
— passes: `will_rename` only ever rewrites a *direct* include of the moved
file, which is exactly what `includers()` (a flat key set, not a
reachability walk) bounds.
- **A case-mismatched include spelling** — `` `include "DEFS.svh"`` written
against a real `defs.svh` on disk, which macOS's default case-insensitive
filesystem (confirmed case-insensitive on this machine) resolves silently.
`IncludeGraph::found`/`found_as_if` key `raw` by the **includer's own path**,
not the target's spelling, so the case mismatch does not stop the includer
from landing in `includers()`. Added
`a_case_mismatched_include_spelling_still_narrows_in_and_rewrites` — passes,
narrows in and rewrites correctly.
- **Unsaved includer, and the property test's own coverage** — re-read
`an_unsaved_include_is_still_rewritten` and
`nothing_skipped_has_an_include_to_rewrite`; both hold and both are
exercised (`assert!(skipped > 0, ...)` in the property test actually forces
the tree to have skippable files, so the property is not vacuously true).
No divergence found: every file `will_rename` would have read under the old
`ws.sources()` sweep and actually needed (an includer of something that
resolves) is still read under `include_sources()`, and no file that used to
be read-and-skipped is now silently mis-included either. The `includes.rs`
scope deviation the dev flagged (a four-line, purely additive accessor,
outside Lane A's stated file list) is accepted as argued — the only
alternative was a second copy of the include scan, which the feature's own
Handshakes section already forbids.
### Summary
| Claim | Verdict |
|---|---|
| Gates | **Pass** |
| `includers()` narrows in every file that can produce an edit or a warning | **Holds** under an include-chain attack and a case-mismatched-spelling attack, beyond the dev's own tree |
| Scope deviation (`includes.rs::includers`) | Accepted, correctly flagged, minimal |
**Verdict: ship.** No findings against this round's diff. (The rename family's
own residue finding, which needs the lead's ruling, is filed in
`docs/features/refactor-rename/README.md` and does not touch this feature.)
## Review
**2026-08-29 — lead, performance-wave Lane A (willRenameFiles).** The
includers() narrowing is the same discipline as the rename fan-out
applied to the include graph, QA's chain/case-spelling/unsaved attacks
all pinned, and the property test ("nothing skipped has an include to
rewrite") is the right shape of guarantee. Accepted; merged by the
lead.
### 2026-08-27 — lead
Reviewed the diff, the work log and the QA log; re-ran all gates myself
+868 -1
View File
@@ -29,6 +29,12 @@ pub fn prepare_rename(files: &[(PathBuf, String)], file: &Path, offset: u32)
-> Result<RenameTarget, String>;
pub fn rename(files: &[(PathBuf, String)], file: &Path, offset: u32, new_name: &str)
-> Result<RefactorEdit, String>;
// Added 2026-08-28 (the performance wave). Same question, no file set.
pub fn prepare_rename_here(semantics: &Semantics, external: &ExternalResolutions,
index: &WorkspaceIndex, offset: u32)
-> Result<RenameTarget, String>;
pub fn rename_name_at(semantics: &Semantics, offset: u32) -> Option<String>;
```
`files` is **the boring option**: the in-scope files as `(path, text)` pairs —
@@ -47,6 +53,15 @@ Deviations from the milestone sketch, and why:
parameter would be cast at both ends of every call.
- **`prepare_rename` returns a `RenameTarget`**, not a bare range: the editor
wants the placeholder too, and it is the identifier's own text.
- **`prepare_rename_here` takes an analysis rather than a file set** (added
2026-08-28). The server already holds every argument it needs for the open
buffer, so this asks nothing of the filesystem; `prepare_rename` stays as
the whole-workspace oracle the parity tests measure it against. See "The
file set a rename reads" below.
- **`rename_name_at` decides nothing.** It answers only "which identifier is
under this cursor", which is what the server needs to ask the index for the
fan-out. Every refusal stays with `rename`, which is the call that has the
files; a second opinion here could only disagree with it.
## What can be renamed
@@ -131,6 +146,300 @@ shape for refactorings).
needs to decide whether to open the rename box at all: everything else needs a
new name to judge.
## The file set a rename reads (2026-08-28)
Until this round both entry points were handed `Workspace::sources()` — every
in-scope file, read from disk — and built a whole `WorkspaceIndex` over it
before answering anything. On OpenTitan (3 976 files) that cost **1.7–3.0 s
for `prepareRename`** and **3.2–8.7 s for `rename`**, on a single-threaded
server where everything the editor sent next waited behind it. `prepareRename`
is what the rename key sends *before the box opens*, so those seconds were a
frozen editor on a keypress that had committed to nothing.
Two different fixes, because they are two different questions.
### `prepareRename`: the buffer already holds the answer
The question is "is this a renameable symbol, and what are its range and
placeholder". `prepare_rename_here` answers it from the open buffer's own
`Semantics`, the `ExternalResolutions` overlay the server keeps beside it, and
the index — **no file is read and nothing is parsed**. Measured: 238 ms →
**200 ns** on the synthetic 504-file workspace, 1.604 s → **135 ns** on
OpenTitan.
#### Refusal-by-refusal parity
Every refusal `prepare_rename` can produce, and what the cheap path does with
it. Deferring a refusal to `rename` is allowed — LSP explicitly permits an
optimistic `prepareRename` — and losing one is not: a deferred refusal is
still delivered, in the same words, by the `rename` that follows.
| # | Refusal (its own sentence) | Where it comes from | Cheap path |
|---|---|---|---|
| 3 | *"… is not one of the files lucisv indexes …"* | the request's file absent from `files` | **unreachable either way.** `sources()` contains every open buffer with a path, and this handler is only reached for one; a fast-path (large) buffer is refused by `server.rs` before it gets here. |
| — | *"the file could not be analyzed."* | `Scope::analysis` of an in-range index | **dead code in both**: the index came from `index_of`, so the lookup cannot miss. |
| 4 | *"there is no symbol to rename at this position."* | no reference and no symbol at the offset | **reproduced** — `reference_id_at` / `symbol_at` on the buffer. |
| 5 | *"… is not resolved to any declaration …"* | `Resolution::NotFound` | **reproduced** — single-file resolution, in the buffer. |
| 6 | *"… could only come from the base class `B` …"* | `Resolution::InheritedCandidate` | **reproduced** — same. |
| 7 | *"… is declared outside the files lucisv indexes …"* | `ExternalTarget::StillUnresolved` / absent | **reproduced** — the overlay is `resolve_external` against this same index, which is the call `Scope::declaration_across_files` makes. |
| 8 | *"… is declared in more than one indexed file …"* (from a cross-file use) | `ExternalTarget::Ambiguous` | **reproduced** — same overlay. |
| 9 | *"… is declared in more than one indexed file …"* (from the declaration) | `declaration.scope == file_scope && index.units(name).len() > 1` | **reproduced** — the buffer knows the scope, the index knows the count. |
| 11a | *"lucisv cannot find where `x` is spelled in its declaration …"*, declaration **in this buffer** | empty `name_span` | **reproduced.** |
| 11b | the same sentence, declaration in **another** file | that file's fresh `name_span` | **deferred.** The index only ever records a non-empty span, so this can only fire on a file whose analysis disagrees with the index — which means reading it. |
| — | *"`x`'s declaring file is not in scope."* | `index_of` on the declaring path | **deferred** (and unreachable in practice: `sources()` is a superset of the index's files). |
| — | *"the declaring file could not be analyzed."* / *"lucisv cannot locate the declaration of `x`."* | the declaring file's own analysis | **deferred**, same reason. |
| 1, 2, 10, 12, 13 | new-name validity, same name, ambiguous use onto this declaration, capture, token drift | — | **not `prepare_rename`'s at all**; they always were `rename`'s. |
Pinned by `rename::tests::the_buffer_answers_a_prepare_exactly_as_the_workspace_does`
and its five siblings, which ask both entry points the same question at **every
byte** of hostile buffers — packages and qualified names, a name declared
twice, nothing resolving, generate blocks and macros, a file that does not
parse — and fail on any reworded refusal, any different answer, and any
refusal the cheap path *invents*. Deferrals are counted, never asserted away.
**The one divergence, stated exactly.** Rule 9's count comes from the index,
and the index is rebuilt on save, not on keystroke (`state.rs`), so an unsaved
edit that adds or removes a file-scope declaration of the name is not in it.
`prepare_rename` counts the same declarations over the *current* texts. Both
directions are possible in principle; both are the ordinary index-staleness
window every other index-backed answer in this server lives in, and the
sentence itself says "indexed file". `rename` re-derives the count from the
current texts and is the authority.
### `rename`: the symbol's fan-out, and why it is enough
`Workspace::rename_sources` (state.rs) builds the file set from what the index
already holds. Its rungs, for the request's file, every open buffer, and each
spelling `N` in `{old_name, new_name}`:
1. **every file declaring `N`** — `WorkspaceIndex::workspace_symbols(N)`
filtered to the exact name, which covers units *and* members (ports,
parameters, package and class members);
2. **every file the index recorded a use of one of those declarations in** —
`references_to(def)`, for **every** such declaration, not only the target's;
3. **every file instantiating `N`** — `instantiations_of(N)`;
4. **every file whose `` `define`` table names `N` or spells it in a macro
body** — a walk over the `DefineTable`s the index already holds (no file is
read), asking the same `vlog_refactor::contains_word` that
`Scope::define_sites` decides with, so the fan-out and the warning cannot
disagree about which files carry one;
5. **the units that export `N` as a member**, and every file declaring,
referring to or instantiating one of them — how a third file's `.N(...)`
connection or `u::N` is reached.
and, for the **new name only**, a sixth:
6. **every file that spells the new name in a use this workspace had to look
outside that file to answer — including the uses it could not answer at
all** — `WorkspaceIndex::files_spelling(N)`, a walk over the per-file
records (no file is read, nothing is parsed). Rungs 1–5 are all keyed by a
*declaration*, and a use that resolved to nothing has no declaration to be
keyed by; this is the rung that finds it. Why only the new name needs it is
argued under "The dangling-use case" below.
Rung 6 is the only one whose cost grows with the workspace rather than with
the symbol, so it is measured on its own: **852 µs on OpenTitan's 3 976 files
in the worst case** — a name nothing spells, where the walk cannot
short-circuit — and 402 µs for `clk_i`, which 681 files spell. Building the
whole file set is 4.75 ms, most of it the other five rungs'
`workspace_symbols` scan and `` `define`` walk. Against a rename that costs
105 ms and used to cost 3.5 s, a sub-millisecond linear scan is the boring
implementation and stays one; a name-keyed side map is the fallback if a
workspace ever makes it visible, and nothing measured here comes close.
#### The sufficiency argument
**Lemma (name-locality of resolution).** A reference spelling `N` is resolved
by `vlog_semantic::follow_paths`, which tries the reference's recorded paths in
order and, for each, calls `follow_one` — and `follow_one` returns either
`index.units(N)` or `index.member(u, N)` for some unit name `u`. **Both are
keyed by `N`, and both are contributed only by files that declare the name
`N`** (as a unit, or as a member of some unit). Rung 1 puts every one of those
files in the set. Therefore, for every path list and every unit name,
`follow_one(subset, N, ·) == follow_one(whole, N, ·)`, so
`follow_paths(subset, N, ·) == follow_paths(whole, N, ·)`: **every reference
spelling `N` resolves in the subset exactly as it resolves in the whole
workspace.** ∎
Three consequences, which are the three things that could have gone wrong:
- **No missed edit.** `Scope::collect_occurrences` emits a span in file *i*
only when *i* is the declaring file, or when a reference in *i* spelling the
old name resolves to the target declaration. The declaring file is rung 1.
A file with such a reference resolves the same way in the whole workspace
(Lemma), so the index recorded a posting for it — rung 2. Hence every file
the whole-workspace rename would edit is in the set. This is the
invariant-1 claim, and it is asserted directly, not only through an
equality, by `every_file_the_workspace_rename_edits_is_in_the_fan_out`.
- **No extra edit.** The converse of the same Lemma: a file in the subset
cannot resolve a reference *onto* the target that the whole workspace
resolves elsewhere. Without rung 1 this was a live corruption route — drop
the file declaring `p::x` and a `p::x`/`q::x` reference would fall through
to `q::x` and be renamed — which is why rung 1 is `workspace_symbols` and
not `units`.
- **The verifier keeps its reach.** `check::watched_files` watches every file
spelling the old *or the new* name. In the subset it can only watch what it
was given, so the new name gets rungs 1–6 of its own — which is what keeps
refusal 12 (capture) alive: `the_fan_out_still_refuses_a_rename_that_would_capture_a_name_elsewhere`
builds exactly the third file whose existing reference the rename would make
ambiguous, and the subset holds it because it is in the *new* name's
postings.
#### The dangling-use case, and why the sixth rung is the new name's alone
The Lemma settles what a name *resolves to*. It does not by itself settle
which files hold a use of that name, and rungs 1–5 answer that question only
through declarations: a file is in the set because it declares the name,
because a posting keys it to a declaration of the name, because it
instantiates the name, because a macro table mentions it, or because it names
the unit that exports it. **A use that resolved to nothing is keyed by
nothing.** `merge_references` drops a `StillUnresolved` result rather than
posting it, which is correct for `references_to` — there is no declaration to
post it against — and is exactly the hole.
That hole is real and it costs a *refusal*, not a warning. Take
`import taken_pkg::*` in a file with no other tie to the rename: today it
resolves to nothing, and `check::print` records `Anchor::Unresolved`. Rename a
package to `taken_pkg` and the same use resolves — `Anchor::External` — which
is a changed meaning in a file the rename never edits, and refusal 12 exists
to refuse exactly that. QA found this on 2026-08-28 and reproduced it; the
lead ruled it not shippable, and rung 6 is the fix.
**The old name has no analogous case, and this is why.** A rename only ever
*removes* declarations of the old name — it renames them away — and never adds
one. So for a use spelling the old name:
- if it **resolves**, its declaration is one of the declarations of the old
name, so the file is in `references_to` of that declaration — and rung 2
walks *every* declaration of the name, not only the target's. Already in the
set.
- if it **resolves to nothing**, it still resolves to nothing afterwards.
`follow_one` looks the name up in `units(old)` and `member(u, old)`; the
rename only takes entries out of those, and a lookup cannot start succeeding
because a candidate was taken away. `Anchor::Unresolved` before,
`Anchor::Unresolved` after — nothing for the verifier to see, so nothing
lost by not reading the file.
- if it **resolves ambiguously**, the escape hatch below fires and the whole
scope is handed over anyway.
Pinned from both ends: `a_dangling_import_of_the_new_name_is_refused_by_both_paths`
(the new name's case, now parity rather than a disclosed gap) and
`a_dangling_use_of_the_old_name_needs_no_rung_of_its_own` (the old name's,
which asserts both that the new-name rung fires when the dangling spelling is
the *destination* and that nothing is pulled in when it is merely a bystander).
#### The escape hatch
Refusal 10 — *some other reference resolves ambiguously onto this
declaration* — is the one the postings cannot locate: an ambiguous use is
recorded against the declarations it could name (`references_are_ambiguous`)
and **not** against the file that writes it. Rather than lose that refusal,
`rename_sources` hands back the whole `sources()` the moment the index says
**any** declaration of either spelling is ambiguously referenced. Correct and
slow beats fast and silent. Pinned by
`an_ambiguously_referenced_declaration_falls_back_to_the_whole_scope`.
**How often it fires, measured.** On OpenTitan the `aes` and `clk_rst_if`
cursors narrow to 7 and 114 files of 3 976; a cursor on a `.clk_i` port
connection falls back to all 3 976 — some declaration named `clk_i` somewhere
in the checkout is ambiguously referenced, and the hatch is deliberately
asked about *every* declaration of the name rather than about the target
alone. The answer is still right there (edits identical, all 652 warnings
identical); it is simply not faster. **The obvious narrowing — ask only about
the declaration the cursor resolves to, which is the only one refusal 10
tests — is left for a later round on purpose**: it needs the target `Def`
identified server-side, which reintroduces the buffer-staleness question the
rest of this design keeps on one side of a line. Filed, not guessed at.
#### The staleness premise, stated exactly
> The index is the server's authority on which files declare a name and which
> files use it. A file changed on disk with nothing telling this server — no
> save, no watcher event, no rescan — or a file a startup scan has not reached
> yet, is a file a rename does not read. **Open buffers are the one exemption:
> every open buffer is in the set whatever the index holds, and the engine
> re-analyzes it from its current text, so unsaved edits are seen in full.**
This is the same rule definition, hover, references, the code lens and the
call hierarchy already live by, and the file watcher is what keeps it true. It
is what the port refactorings adopted on 2026-08-28, one round earlier. What
it costs a rename specifically: a reference living only in a file whose disk
copy moved unseen is a reference the rename does not rewrite **and cannot
refuse over** — `check::verify` re-analyzes the subset, so a file outside it
is not compared before and after. Before this round `rename` was, with
`prepareRename` and the port actions, one of the few answers in this server
that could see *further* than the index; it no longer is.
#### The residue — what the subset cannot see
Written out rather than argued away. Each of these is a file whose only
mention of a name is something the index records no declaration, posting,
instantiation edge, macro definition or external-reference fact for. **After
the 2026-08-28 rework there is exactly one, and it costs a warning — no edit
and no refusal:**
- **One warning flavour, and it is the loudest item on this page — measured,
not hypothetical.** `Scope::warnings` produces three sentences. Two are read
off a file's `` `define`` table (*"`x` is also a macro defined at …"* and
*"`x` appears in the body of macro `M` …"*) and **both survive**: the index
holds every file's table, and rung 4 walks it
(`the_fan_out_keeps_the_define_warnings_of_files_it_would_not_otherwise_read`).
The third comes from a **macro invocation whose arguments spell the name**,
and that one needs the file's token stream. A file outside the fan-out no
longer produces it.
On the real OpenTitan checkout, at two cursors, with **no edit lost at
either**:
```
aes -> aes_core_top edits identical (7 files, 7 edits)
warnings 7 -> 0, every one of them a
macro-invocation sentence:
`aes` in the arguments of `CONNECT_TL_DEVICE_IF`
at tb__xbar_connect.sv:30 and :47 (twice),
`DRIVE_CHIP_TL_DEVICE_IF` at :97, :140, :161,
`uvm_error` at keymgr_dpe_scoreboard.sv:644
clk_rst_if -> clk_rst_thing edits identical (114 files, 275 edits)
warnings 64 -> 61, the three lost being
`uvm_fatal` invocations
```
Those macro invocations really do still spell the old name after the
rename, and saying so is the whole point of the warning.
`tb__xbar_connect.sv` mentions `aes` **only** inside macro-invocation
tokens, and the index models those in no table at all: a macro invocation is
one opaque token, contributing no declaration, no reference, no
instantiation edge and no define entry, so nothing short of reading and
lexing the file can find it.
**This is a lead decision, and it is stated here rather than buried.** The
narrowing costs no edit and no refusal — the same runs assert the edit sets
byte-identical — but it costs the user a real piece of news. Recovering it
as things stand means running the warning pass over `sources()` while the
edits and the verification run over the fan-out: at least the 200–241 ms
workspace read plus a `tokenize` of every file spelling the name, which is
most of the win this round is for. The right answer is a
**macro-invocation census in `FileFacts`**, which would make this rung an
index lookup like the other five; that is a `vlog_semantic` change, and it
is filed as a request below rather than guessed at here.
- **No lost refusal.** The first draft of this round had one — a file whose
only mention of the new name was a use that resolved to nothing — and it is
**closed**, by rung 6. See "The dangling-use case" above for the argument
and the two tests. It is recorded here rather than deleted because the
shape is worth remembering: every rung keyed by a *declaration* is blind to
a use that has none, and a rename's whole job is to change which
declarations exist.
- **Nothing else.** A file whose occurrences of either name are strays — a
comment, a string, a local declaration inside a module, a hierarchical tail
— resolves identically before and after the edit, so the whole-workspace
verifier had nothing to say about it either.
The alternative considered and not taken: hand the engine the whole file list
but a *prebuilt* index, which narrows nothing and would still cost the
`sources()` read (200–241 ms on OpenTitan) plus an index clone. It is recorded
here so the choice is visible rather than implied.
## The verification story
Two independent checks, both run in memory on the edited text, before
@@ -230,7 +539,18 @@ implemented:
the index's `FileId`s describe the same texts.
- A rename is a rare, user-initiated request, so re-analyzing candidate files
twice (once before the edit, once after) is affordable. No caching, no
incrementality.
incrementality. **Amended 2026-08-28**: a *prepareRename* is not rare — it
is what the rename key sends before the box opens — and "the candidate
files" is now the symbol's fan-out through the index rather than the whole
scope. See "The file set a rename reads".
- **The index is the server's authority on where a name is declared and
used** (2026-08-28). The fan-out is read from it, so a rename sees the
workspace as far as the index describes it: a file changed on disk with
nothing telling this server, or one a startup scan has not reached, is a
file the rename does not read. Open buffers are exempt — every one of them
is in the set whatever the index holds. The exact premise, what it costs and
what it does not, is written out under "The staleness premise, stated
exactly".
- Refactored output is *edited source*, not reformatted source (umbrella
Handshakes): the edits are minimal, and the user runs the formatter
separately.
@@ -256,10 +576,64 @@ implemented:
ranges that slice back to the name — every edit span is one of these, and
the engine re-checks the slice before emitting it.
**Consumed from `vlog_semantic`, added 2026-08-28** (no change required):
`WorkspaceIndex::{workspace_symbols, references_to, references_are_ambiguous,
instantiations_of, defines}` — the posting, edge and macro tables — are what make
the rename's file set a lookup instead of a workspace read. The sufficiency
argument leans on one published property of theirs, and it is worth naming so
it moves under supervision: **`references_to`'s postings are built by
`merge_references`, which resolves each recorded reference with the same
`follow_paths` `resolve_external` uses.** If those two ever stop being the one
function, the postings stop being a superset of the files a rename must edit.
The same goes for `workspace_symbols` covering both the `units` and the
`members` tables: rung 1 of the fan-out *is* that coverage.
**Changed in `vlog_semantic`** (lead-authorized 2026-08-28 after QA, strictly
additive — the second such change this feature has made, the first being M2's
`Target::Declaration`):
- **`WorkspaceIndex::files_spelling(name) -> impl Iterator<Item = FileId>`** —
every file holding an external reference *fact* spelling `name`, resolved or
not. New query, no new state, no format change: it reads the
`FileFacts::references` records the index already keeps, and
`FACTS_FORMAT` is untouched. Logged in `docs/features/vlog-semantic/README.md`'s
work log, as M2's change was.
- **Why it had to live there.** The records are `pub(crate)`, and the question
— "which files hold a use spelled `N` that this index had to look outside
that file to answer" — is a question about the index's own tables. The
alternative was for the server to re-derive it by reading and analyzing
files, which is the workspace read this whole round removes.
- **The contract it carries:** `references_to` is keyed by the declaration a
use *landed on*, so a use that landed on nothing is in no posting.
`files_spelling` is the same records asked by spelling instead, which is
what makes it answer for the unresolved ones. If `facts_from_analysis` ever
stops recording an unresolved external candidate — today it records every
`ExternalCandidate`/`InheritedCandidate` with a non-empty path list — rung 6
stops closing the dangling-use case and this section must be re-read.
**Promised to `lucisv_server`** (and to any future CLI):
- `rename` never panics and never returns a partial edit: `Ok` means every
edit in it verified together, `Err` means nothing at all is to be applied.
- `prepare_rename_here` refuses in the *same sentences* `prepare_rename` does,
or defers to `rename`; it never invents a refusal `prepare_rename` would
not have made. The parity table above is the contract, and the byte-by-byte
parity tests are the enforcement.
- `rename_name_at` names the identifier `prepare_rename`'s `RenameTarget`
would name, at every offset where `prepare_rename` answers at all
(`the_name_a_fan_out_is_built_from_is_the_name_the_engine_acts_on`).
**Requested of `vlog_semantic` (filed 2026-08-28, not taken):** a
**macro-invocation census in `FileFacts`** — per file, the macro invocations
it writes and the identifier-shaped words in their arguments. It is the one
piece of the rename's warning set the index cannot answer, and its absence is
the measured residue above: on OpenTitan, renaming `aes` loses seven
"`aes` appears in the arguments of the macro invocation …" warnings because
the files holding them contribute nothing else about `aes`. The census would
be one more `Vec` on a record `FACTS_FORMAT` already versions, read off the
token stream the parse already produced, and it would turn
`Scope::macro_use_warnings` from a workspace lex into a lookup — for the port
refactorings' identical scan as much as for this one.
- `RefactorEdit.edits` is sorted by path; each file's edits are sorted by
start offset, non-overlapping and non-empty.
- `warnings` are informational only — an `Ok` result with warnings is still
@@ -312,6 +686,19 @@ a much larger change than an end label and is not part of M2.
- [x] Tests: 64 in `vlog_refactor` (14 unit incl. 8 masked-corruption attacks,
48 behavior, 2 corpus), 3 new in `vlog_semantic`, 8 in `lucisv_server`
(7 in `rename.rs`, 1 capability), 1 e2e session
- [x] `prepareRename` answered from the open buffer and the index rather than
from `sources()` (2026-08-28): `prepare_rename_here` in the engine, the
refusal-by-refusal parity table above, and six byte-by-byte parity
suites against `prepare_rename` as the oracle
- [x] `rename` computed over the symbol's fan-out rather than the whole scope
(2026-08-28): `Workspace::rename_sources` in the server,
`rename_name_at` in the engine, the sufficiency argument above, the
ambiguity escape hatch, and equivalence tests over hostile workspaces
- [x] The dangling-use rung (2026-08-28, QA-driven rework):
`WorkspaceIndex::files_spelling` and rung 6 of the fan-out, applied to
the new name, which closes the one refusal the first draft lost. The
old name's exemption is argued under "The dangling-use case" and pinned
by its own test
- [ ] Deferred: rename in comments and strings (rope's `docs=True`) — the
umbrella lists it as an option, off by default, "until asked for"
- [ ] Deferred: renaming a module together with its file
@@ -473,6 +860,158 @@ Checks after the rework: `cargo fmt --all -- --check` clean,
`cargo clippy --all-targets` zero warnings workspace-wide,
`cargo test --workspace` green at 1085 tests (was 1072).
**2026-08-28 — dev agent (performance wave, Lane A).** The rename family stops
reading the workspace. `performance.md`'s two worst rows were
`textDocument/rename` (3.6–8.7 s) and `textDocument/prepareRename`
(2.5–3.0 s), both of them `ws.sources()` followed by a whole `WorkspaceIndex`
build; the measurer's own push-back — that `prepareRename` is what the rename
key sends *before the box opens*, not a rare user gesture — is the framing
this round took.
Everything argued under "The file set a rename reads" above. The decisions
worth repeating here:
- **`prepare_rename_here` takes an analysis, not a file set.** The server
already holds the buffer's `Semantics`, its `ExternalResolutions` overlay
and the index, and the overlay is `resolve_external` against that same
index — which is the exact call `Scope::declaration_across_files` makes. So
every refusal that depends on *which* declaration a use names is reproduced
rather than approximated, and only the four that need the declaring file's
own text are deferred. `prepare_rename` stays, as the oracle the parity
tests measure against; the refusal sentences were factored into five
functions so the two paths cannot word one situation two ways.
- **The fan-out's first rung is `workspace_symbols`, not `units`.** This is
the rung the whole equality argument turns on and the one that was easy to
get wrong: `follow_paths` looks a reference's *own* name up, in `units(N)`
or `member(u, N)`, and both tables are contributed only by files that
declare the name `N`. Drop the file declaring `p::x` from the set and a
reference with paths `[p::, q::]` falls through to `q::x` and is renamed —
an *over*-edit, corruption in the direction nobody looks. With rung 1 in
place the Lemma makes the subset's resolution of every reference spelling
either name identical to the workspace's, which is what buys "no missed
edit" and "no extra edit" at once.
- **The new name gets the whole fan-out too**, or refusal 12 (capture) dies:
the file whose existing reference a rename would make ambiguous is in the
*new* name's postings and in nothing of the old name's.
- **The ambiguity escape hatch.** An ambiguous use is recorded against the
declarations it could name, never against the file that writes it, so
refusal 10 cannot be reached from a subset. `rename_sources` hands back
`sources()` when the index reports one. Slow and correct beats fast and
silent.
- **`willRenameFiles`** got the same treatment through the include graph —
written up in `docs/features/file-operations/README.md`, including the
four-line `IncludeGraph::includers` accessor, which is the one file this
round touched outside its stated scope and is flagged there for the lead.
Measured, `--release`, and the equality checked as well as the clock:
| | before | after |
|---|---:|---:|
| OpenTitan (3 976 files), `prepareRename` on the `aes` instantiation | 1.663 s | **139 ns** |
| OpenTitan, `rename` of `aes` (7 files edited) | 3.467 s | **105.5 ms** (7-file fan-out) |
| synthetic 504 files, `prepareRename` on a module name | 251 ms | **212 ns** |
| synthetic 504 files, `rename` (4 files edited) | 486 ms | **370 µs** |
(All four re-taken after the 2026-08-28 rework below, so the table describes
the shipped code. The earlier round measured 1.604 s → 135 ns, 3.284 s →
103.6 ms, 238 ms → 200 ns and 465 ms → 294 µs on the same corpus: the sixth
rung is inside the noise, which is what the separate rung measurement above
says directly.)
The OpenTitan numbers were taken with throwaway probes against the local
checkout and deleted — no test may depend on it. The reproducible probe is
`perf::a_rename_before_and_after`. The throwaway also swept **every 7th byte
of `tb.sv`** comparing `prepare_rename_here` against `prepare_rename`: **564
offsets, all identical, zero deferrals** — the parity table's contract holding
over real code, not only over the six synthetic buffers in the suite.
**What the OpenTitan sweep found, and it is not nothing.** At the `aes` cursor
the two edit sets are byte-identical (7 files) and the *warnings* are 7 → 0:
`tb__xbar_connect.sv` and `keymgr_dpe_scoreboard.sv` spell `aes` only inside
macro-invocation tokens, which the index does not model in any table. Written
up in full under "The residue", with the cost of recovering it and a filed
request for the `FileFacts` macro-invocation census that would make it a
lookup. **It is a lost warning, never a lost edit or a lost refusal, and it is
the lead's call at review** — the honesty gate the brief asked for.
Deliberately not done: `check::watched_files` still sweeps the file list it is
given with `contains_word`, which is now the fan-out rather than the
workspace; no attempt was made to narrow it further, because it is O(files in
the set) over text already in memory.
Gates: `cargo fmt --all -- --check` clean, `cargo clippy --all-targets` clean
workspace-wide, `cargo test --workspace` green, `node editors/vscode/smoke.js`
OK against the release binary.
**2026-08-28 — dev agent (QA-driven rework: the lost refusal is closed).** The
lead ruled the round's "one lost refusal" residue not shippable — *a silently
weaker refusal is not a residue we ship* — and directed the fix. QA had found
it, reproduced it and pinned it as
`known_residue_a_dangling_import_of_the_new_name_is_a_lost_refusal`; that test
is now `a_dangling_import_of_the_new_name_is_refused_by_both_paths` and
asserts parity through `same_answer` instead of pinning the divergence.
The diagnosis, which is what makes the fix a rung rather than a patch: **rungs
1–5 are every one of them keyed by a declaration.** A file is in the set
because it declares the name, because a posting keys it to a declaration of
it, because it instantiates it, because a macro table mentions it, or because
it names the unit exporting it. A use that resolved to *nothing* has no
declaration to be keyed by — `merge_references` drops a `StillUnresolved`
result rather than posting it, correctly, since there is nothing to post it
against — and a rename's whole job is to change which declarations exist. So
`import taken_pkg::*` of a package nobody declares yet was invisible to the
fan-out and became meaningful the moment the rename landed, which is exactly
what capture rule 12 refuses over.
What changed:
- **`WorkspaceIndex::files_spelling(name)`** — one additive, lead-authorized
`vlog_semantic` query: every file holding an external reference *fact*
spelling the name, resolved or not. No new state, no new field,
`FACTS_FORMAT` untouched; it reads the `FileFacts::references` records the
index already keeps, which is the only reason the answer is available at all
without reading files. Logged in `docs/features/vlog-semantic/README.md`'s
work log as M2's `Target::Declaration` was, and the recording rule it rests
on is written into both Handshakes sections so it moves under supervision.
- **Rung 6 of `Workspace::rename_sources`**, `want_spellers`, applied to the
**new name only**. The old name provably needs nothing: a rename only ever
*removes* declarations of it, a resolving use of it is already in rung 2
(which walks every declaration of the name, not only the target's), and a
non-resolving one cannot start resolving because a candidate was taken away.
That argument is written out under "The dangling-use case" and pinned from
the other side by `a_dangling_use_of_the_old_name_needs_no_rung_of_its_own`,
which checks both that the new-name rung fires when the dangling spelling is
the destination and that nothing is pulled in when it is a bystander.
- The Lemma is unchanged — it was always about what a name *resolves to*, and
it was always sound. What it never claimed, and what the sufficiency
argument now says out loud, is which files *hold* a use. Rung 6 is that
second question's answer.
**The rung's cost, measured** (the lead asked for the number, and for a
name-keyed side map as the fallback if it were large — it is not). On
OpenTitan's 3 976 files: **852 µs** for a name nothing spells, which is the
worst case because `any()` cannot short-circuit, and **402 µs** for `clk_i`,
which 681 files spell. The whole file-set build is 4.75 ms, most of it the
other rungs. `rename` itself went 103.6 ms → 105.5 ms, i.e. unchanged against
a 3.5 s baseline. On the synthetic 504-file corpus the rung is 49.8 µs of a
128.7 µs set build; both are printed by `perf::a_rename_before_and_after`,
which grew two lines for them.
Re-verified after the rework, against the real OpenTitan checkout: all four
cursors still byte-identical (`aes` 7 files, `clk_rst_if` 114 files, `.clk_i`
4 files), the capture refusal on `aes` → `prim_fifo_sync` still verbatim, the
warning counts unmoved. The refusal parity table is unaffected — it is
`prepareRename`'s, and neither entry point's refusal set changed; what changed
is which files `rename` reads before producing rule 12's.
**The macro-invocation warning residue stands as documented** — the lead
accepted it on the record, and the `FileFacts` macro-invocation census remains
filed as the real fix.
Gates after the rework: `cargo fmt --all -- --check` clean,
`cargo clippy --all-targets` clean workspace-wide, `cargo test --workspace`
green, `node editors/vscode/smoke.js` OK against the release binary.
## QA log
**2026-08-24 — QA agent.**
@@ -883,8 +1422,336 @@ surface (hierarchical tails, `defparam` paths, mismatched/redeclared end
labels) is honestly disclosed and consistent with the "lucisv does not
preprocess / does not elaborate" boundary the umbrella already draws.
**2026-08-28 — QA agent (performance wave, Lane A).** Verified the round that
moves `prepareRename` and `rename` off `ws.sources()`. Adversarial charter:
find a rename that edits, warns or refuses differently than the
whole-workspace path would, or a `prepareRename` that lies. Worked in
`.claude/worktrees/agent-a2cccf825469bf247`.
### Gates
- `cargo fmt --all -- --check` — clean, after fixing formatting in QA's own
additions (`cargo fmt --all`; the dev's diff itself was already clean).
- `cargo clippy --all-targets` — clean, zero warnings, forced re-check after
`touch`ing every file this round changed.
- `cargo test --workspace` — green, 0 failures, across every crate (doc-tests
included).
- `node editors/vscode/smoke.js target/release/lucisv-server` — OK, 10
messages, against a freshly built release binary carrying this round's diff
plus QA's added tests.
- Numbers reproduced against the actual code under review (not trusted from
the Work log), `cargo test --release -p lucisv_server --bin lucisv-server
perf:: -- --ignored --nocapture --test-threads=1`: `prepareRename` 238.29 ms
→ **179 ns**; `rename` 466.54 ms → **294.9 µs**; `willRenameFiles` scope-read
11.39 ms → includers-read **15.1 µs**. All within noise of the Work log's
claims. (Two unrelated corpus-dependent perf tests failed in this worktree
because `corpus/` is not checked out here — pre-existing, unaffected by this
diff, confirmed present in `HEAD` before this round's changes.)
- Real OpenTitan checkout (`/Users/guoliangchen/repo/opentitan` @ `0098135264`,
3979 files, matching `performance.md`'s provenance), driven over real LSP/
stdio with a client pointed at this worktree's own `target/release/
lucisv-server` (not the dev's throwaway probes, and not the earlier
"instrumented" binary from the measurer's session): cold workspace scan
settled in 2 940.7 ms; six repeated `rename`s of `aes` averaged **~104 ms**
and all edited exactly the 7 files the Work log names (`tb.sv`, `aes.sv`,
`aes_wrap.sv`, `aes_tb.sv`, and the three `*_pd_main.sv` top-level
instantiation sites); four repeated `prepareRename`s on the same cursor
averaged **~0.05 ms** client-observed (the LSP round trip, not the dev's
in-process 135 ns — consistent with `performance.md`'s own 0.02–0.33 ms
transport floor: the request now costs essentially nothing but the pipe).
**All three gates and the numbers: pass, claims confirmed.**
### Confirmed finding (HIGH, disclosed by the dev, verified real and exactly
as bounded) — the residue's "one lost refusal"
The README's own "The residue" section names a case the fan-out cannot catch:
a file whose only mention of the **new** name is a bare reference that
resolves to nothing today (an `import new_name::*` of a package that does not
exist yet, or a type spelled `new_name`). The whole-workspace verifier refuses
such a rename (capture rule 12: the import would start meaning something);
the fan-out never reads that file, so it returns `Ok` instead — a materially
weaker answer, not merely a lost warning like the macro-invocation case below
it. I built the minimal repro and pinned it as a permanent regression test,
`crates/lucisv_server/src/rename.rs`,
`known_residue_a_dangling_import_of_the_new_name_is_a_lost_refusal`: package
`cfg_pkg` renamed to `taken_pkg`, with a third file `module strayer; import
taken_pkg::*; endmodule` that declares, references (under the old name) and
instantiates nothing. `vlog_refactor::rename` over the whole scope refuses
(`"...would change what taken_pkg means in stray.sv..."`); over
`Workspace::rename_sources`'s real output, it succeeds silently. Confirmed
this is exactly as narrow as documented — every attack in the next section
(new-name declared elsewhere, new-name instantiated elsewhere, new-name
reached via a member connection) is still caught by rungs 1/3/5, so the gap is
precisely "an unresolved bare reference to the new name, nothing else." This
is not a new defect: it is the dev's own disclosed residue, verified to
reproduce exactly as written and correctly bounded. Recorded per CLAUDE.md
invariant 4's spirit (a widened forgiveness needs attack tests proving the
boundary) even though this is a narrowing, not `verify.rs`, because the same
"guilty until proven innocent, with tests" discipline applies to any new gap
between the fast and slow paths. **This is the one item that needs the lead's
explicit ruling** before ship — the brief's own honesty gate.
### Attacks that held — no divergence found
All added as permanent regression tests in `crates/lucisv_server/src/rename.rs`
unless noted, run against the real `Workspace::rename_sources`/
`prepare_rename_here` production code paths, not reimplementations:
- **Escaped-identifier instantiation** (`\sub u_weird (...)`- a different
name to `vlog_semantic` than `sub`, a pre-existing simplification this round
did not touch): `an_escaped_identifier_instantiation_does_not_break_fan_out_parity`.
Both paths call the identical engine, so the escaped spelling is untouched
by both, byte-identical — the fan-out dropping the file (it posts nowhere)
changes nothing observable, since the whole-workspace run's own watch of it
is also a no-op.
- **Same spelling, different symbol kind** (a module named `sub` vs. an
unrelated wire also named `sub` in a different module):
`a_same_spelling_different_symbol_kind_is_not_captured_by_the_fan_out`. The
unrelated wire's file and declaration are never touched.
- **Escape hatch discovered on the second spelling, not the first** — the
ambiguity is on the *new* name only, so `fan_out_of`'s loop over `[name,
new_name]` must not leak a partially-built, too-narrow `wanted` set when it
bails on the second iteration:
`the_escape_hatch_fires_when_only_the_new_names_posting_is_ambiguous`. Falls
back to the whole scope correctly; `Workspace::rename_sources`'s early
`return self.sources()` on the first ambiguous hit (state.rs, `fan_out_of`)
discards the partial set rather than returning it, exactly as needed.
- **Prepare parity fuzz beyond the dev's six buffers**
(`crates/vlog_refactor/src/rename.rs`): a valid head followed by an
unparseable tail, CRLF line endings, multi-byte UTF-8 text ahead of the
probed identifiers, and a macro-heavy buffer (`` `ifdef``/`` `define``/
`` `BUMP(x)`` all in one file) — every offset of every buffer, no
divergence, no invented refusal.
- **Include-graph-adjacent attacks on `willRenameFiles`**, in
`crates/lucisv_server/src/file_ops.rs`: an include chain `a.svh -> b.svh`
with a third file `c.sv -> a.svh` (renaming `b.svh` narrows to `a.svh` only,
correctly leaves `c.sv` unedited since it never spells `b.svh`,
`an_include_chain_narrows_to_the_direct_includer_of_the_moved_file`), and a
case-mismatched include spelling (`` `include "DEFS.svh"`` against a real
`defs.svh` on this case-insensitive filesystem,
`a_case_mismatched_include_spelling_still_narrows_in_and_rewrites`) — both
narrow in correctly and rewrite correctly.
- **Deferred-refusal reachability (rule 11b).** Attempted to construct a case
where the declaring file (in another file from the buffer) has an empty
`name_span`, which is the one row the parity table marks "deferred" rather
than "reproduced." Could not construct one through the public parsing API:
the name-span contract (`vlog-semantic`'s Handshakes, and this feature's own
"every edit span originates in a parsed node") guarantees a non-empty span
on every declaring node the binder records, so this refusal looks
unreachable through any real workspace state today, in the same way the two
"—" rows in the parity table are marked unreachable. Not fixed or asserted
either way — flagging for the record rather than claiming coverage the
suite does not have.
### Not attempted / out of scope for this round
The end-label, hierarchical-tail, `defparam`, and escaped-identifier
*declaration* findings from the 2026-08-24 rounds above are pre-existing and
untouched by this diff — re-read, not re-attacked. The `willCreateFiles`/
`willDeleteFiles` non-goals in file-operations are unrelated to this round.
### Summary
| Claim | Verdict |
|---|---|
| Gates (fmt/clippy/test/smoke) | **Pass** |
| Numbers (synthetic probes + real OpenTitan, this worktree's own build) | **Pass, reproduced independently** |
| Sufficiency argument (name-locality lemma) | **Holds** under every attack tried: escaped identifiers, same-spelling different symbols, mid-walk ambiguity, prepare-parity fuzz, include-chain/case-mismatch narrowing |
| The residue — macro-invocation warning loss | Reproduces exactly as measured on OpenTitan (7→0, 64→61); no edit or refusal lost, only the one warning flavour; already the lead's disclosed call |
| The residue — "one lost refusal" (dangling import of the new name) | **Confirmed real, reproducible, and exactly as bounded** — a genuinely weaker answer than the whole-workspace path, not just a lost warning. **Needs the lead's explicit ruling before ship.** |
**Verdict: REWORK-gate, not ship-as-is** — not because anything is broken by
accident, but because the one item the brief calls "gate the subset path
behind that honesty (lead decides at review)" has not yet had that decision
made. Every other attack in the adversarial charter held. My recommendation,
for the lead: this is very likely acceptable to ship (it is a narrowing of a
*refusal*, not an edit — CLAUDE.md invariant 1 is about edits, and none is
lost or wrong here), especially since the parallel macro-invocation-warning
residue was already accepted; but "very likely acceptable" is not the same as
"decided," and the brief was explicit that this exact honesty gate needs a
lead ruling, not a QA one.
**2026-08-29 — QA agent (re-verification of the rework: rung 6,
`WorkspaceIndex::files_spelling`).** Focused pass, not a full re-run, on the
lead-authorized fix for the HIGH finding above: the flipped test
(`a_dangling_import_of_the_new_name_is_refused_by_both_paths`) and the new
`a_dangling_use_of_the_old_name_needs_no_rung_of_its_own`, plus "The
dangling-use case" section's argument (rung 6 is the new name's alone because
a rename only ever *removes* declarations of the old name). Charter: attack
rung 6's completeness, attack the old-name exemption with a shadowing/
"unmasking" hunt, verify the tests actually assert what they claim, spot-check
the rung's cost, run the gates. Worked in the same worktree.
### Rung 6 completeness — three new attacks, all pass
Read `WorkspaceIndex::files_spelling` (`crates/vlog_semantic/src/workspace.rs`)
and `resolve.rs`'s `Target::{Package,Unit,UnitMember}`/`miss` machinery to find
every way a real reference could spell the new name and end up with a
`Resolution` whose `paths` are empty (invisible to `files_spelling`, since
`facts_from_analysis` only records `ExternalCandidate`/`InheritedCandidate`
with a non-empty path list). The exhaustive case split: **every** miss on
`Target::Package`, `Target::Unit`, `Target::UnitMember` — including the head
of `p::x` and an `extends`/`implements` base — always pushes at least the bare
name onto its paths (`named_at_file_scope`'s `None` arm, `unit()`'s unconditional
`external.push(name.to_string())`, `unit_member`'s two unconditional
`ExternalCandidate` arms), so all of those are recorded regardless of whether
they resolve. The **only** empty-paths cases are `this_member`/`super_member`
(always `paths: Vec::new()`) and a plain `Target::Lexical` miss inside a class
with `extends` when no import in scope supplies anything
(`miss()`'s `InheritedCandidate { base, paths: external }` with `external`
empty) — and for exactly these, `resolve_external` can *never* produce an
overlay entry (`follow_paths` on an empty list is `StillUnresolved` by
construction, unconditionally, both before and after any rename, because the
paths are fixed by the file's own unedited text), so the reference's `Anchor`
is provably invariant and excluding the file costs nothing on either path.
Three permanent regression tests added to `crates/lucisv_server/src/rename.rs`
to check this empirically rather than trust the proof alone:
- `a_new_name_spelled_only_as_an_extends_base_is_still_caught_by_rung_6` — a
class `extends taken_base` where `taken_base` is declared nowhere; renaming
a package to `taken_base` is refused by both paths, and rung 6 pulls the
file in via the `Target::Unit` path (a genuinely different resolution
target than the import case rung 6 was built for). Passes.
- `an_unqualified_use_inside_an_extending_class_with_empty_paths_needs_no_rung`
— the one real empty-paths shape (a bare identifier inside a class that
extends an existing, unrelated base, no import in scope). Confirmed
`files_spelling` does **not** pull the file in, and confirmed (via
`same_answer`) that excluding it changes nothing — the rename still
succeeds identically on both paths. Passes, both assertions.
- `a_local_only_symbol_sharing_the_new_names_spelling_is_not_a_bogus_refusal`
— a wire declared and used only locally in a third file, sharing the new
name's spelling. `files_spelling` correctly excludes it (it is a
`ReferenceFact::Local`, which the function's own `match` arm returns
`false` for), and the rename succeeds with no edit to that file. This is
also directly what `files_spelling_finds_the_uses_no_posting_can_be_keyed_by`
in `crates/vlog_semantic/tests/workspace.rs` pins at the query's own level
(`quiet.sv`'s local wire named `absent_pkg` is excluded from
`named("absent_pkg")`) — read and re-run, still passes.
### Old-name exemption — shadowing/"unmasking" hunt, none found
Tried to construct exactly the counterexample the charter asked for: two
packages `p_pkg` and `q_pkg` both exporting a member spelled `shared_name`, a
third file importing both (`p_pkg` first, so "first-written import wins"
resolves `shared_name` to `p_pkg`'s declaration today), then renaming *away*
`p_pkg::shared_name` — the hypothesis being that the importer's reference
would silently fall through to `q_pkg`'s pre-existing, unrelated declaration
without the importer's file being in the fan-out.
It doesn't happen, and reading why is the actual finding: the importer's
`shared_name` reference currently *resolves to the rename target itself*, so
it is not a bystander a removal could silently redirect — it is an edit site.
`Scope::collect_occurrences` rewrites it to the new name along with the
declaration, so the text never says `shared_name` again for `follow_paths` to
re-resolve against `q_pkg`. Generalizing: any reference that could possibly
be affected by removing declarations of the old name must itself spell the
old name (the workspace tables are keyed by literal name string, so a
reference to an unrelated name cannot be touched by removing entries under a
different key), and by the Lemma such a reference either (a) resolves to the
target — edited away, not orphaned — or (b) resolves to a *different*
existing declaration of the same name — already in the set, because rung 1
(`workspace_symbols`, not `units`) walks *every* declarer of the name and rung
2 posts against each one, not only the target's — or (c) resolves to nothing
— stays resolving to nothing, since removing a candidate cannot manufacture a
new match. There is no fourth case, so there is no shadowing route the old
name needs a rung for. Verified empirically as well as by this argument:
`removing_the_old_names_winning_declaration_does_not_escape_the_fan_out`
(added to `crates/lucisv_server/src/rename.rs`) builds the exact scenario
above and confirms the fan-out includes both `q.sv` (rung 1, every declarer)
and `user.sv` (rung 2, posted against `p_pkg`'s declaration), that the rename
succeeds, edits exactly the declaration and the importer's reference, and
never touches `q_pkg`'s unrelated declaration. **The old-name exemption
argument held under attack — no counterexample found, and the reason none
exists is now written into the test itself, not just asserted.**
### Tests genuinely assert what they claim — sabotage-verified
Read every test named above plus the dev's flipped/new ones
(`a_dangling_import_of_the_new_name_is_refused_by_both_paths`,
`a_dangling_use_of_the_old_name_needs_no_rung_of_its_own`) end to end, then
sabotaged rung 6 out (`Workspace::rename_sources`, wrapped the
`want_spellers` call in `if false { … }`) and re-ran the whole
`rename::tests::` module:
- **Failed, as they must**: `a_dangling_import_of_the_new_name_is_refused_by_both_paths`,
`a_dangling_use_of_the_old_name_needs_no_rung_of_its_own` (the file "the
fan-out lost the refusal … and edited 1 files instead" — exactly the
pre-rework residue, reproduced on demand), and the new
`a_new_name_spelled_only_as_an_extends_base_is_still_caught_by_rung_6`.
- **Still passed, as they must** (they test cases that provably do not
depend on rung 6): the empty-paths test, the local-only-symbol test, the
shadowing/unmasking test, and every pre-existing fan-out test.
Reverted the sabotage (`git diff crates/lucisv_server/src/state.rs` after
reverting shows zero trace of it) and re-ran — all 26 tests in
`rename::tests::` pass again. This is the strongest confirmation available
short of formal proof: the tests that claim to depend on rung 6 actually do,
and the tests that claim not to actually don't.
### Numbers, spot-checked
Release probe (`cargo test --release -p lucisv_server --bin lucisv-server
perf::a_rename_before_and_after -- --ignored --nocapture --test-threads=1`),
against this worktree's own freshly rebuilt binary: file-set build **137.2
µs**, of which `files_spelling` **52.1 µs**; rename fan-out **396.1 µs**;
`prepareRename` whole-workspace **249.5 ms** → buffer+index **212 ns**. All
within noise of the Work log's 128.7/49.8/370/238/200 µs-and-ns figures.
Real OpenTitan checkout, over actual LSP/stdio with a client pointed at this
worktree's own rebuilt `target/release/lucisv-server` (not a throwaway
in-process probe): six repeated `rename`s of `aes` on a cold workspace scan
(3 015.7 ms settle) averaged **~118 ms** (107–134 ms), consistent with the
Work log's 105.5 ms and my own prior-round measurement of ~104 ms — the
spread is machine noise, not a regression from rung 6. Re-requested the same
`aes` → `aes_core_renamed_qa2` rename directly (not just repeated identical
renames) and got the **same 7 files, same edit counts** as my prior-round
spot check, confirming rung 6 changes nothing about the real edit set.
### Gates
`cargo fmt --all -- --check` clean. `cargo clippy --all-targets` clean (forced
re-check after `touch`ing every file this rework changed, zero warnings —
including in the three new tests, one `unused_must_use` warning caught and
fixed on the way, noted so it isn't mistaken for a dev-side issue). `cargo
test --workspace`: **0 failures**, no panics, workspace-wide (34 test binaries
including doc-tests). `node editors/vscode/smoke.js target/release/lucisv-server`
— OK, 10 messages.
### Verdict
**SHIP.** The rework closes the HIGH finding exactly as claimed: rung 6 is
complete under every completeness attack tried (including two shapes — the
extends-base case and the empty-paths InheritedCandidate case — the dev's own
writeup didn't walk through explicitly), the old-name exemption holds under a
genuine shadowing/unmasking attempt (with the reason now understood and
tested, not just asserted), the flipped and new tests are not vacuously
passing (sabotage-confirmed), and the rung's cost is sub-millisecond on
OpenTitan with no measurable end-to-end regression. No new findings. The
macro-invocation warning residue is unchanged and remains the lead's
already-accepted, separately-tracked call.
## Review
**2026-08-29 — lead, performance-wave Lane A.** Reviewed after QA's
initial REWORK-gate, the fix round, and QA's SHIP on re-verification;
gates re-run on the worktree (fmt clean, clippy silent, 2518 workspace
tests green). The round's spine is the name-locality lemma, and the
rework is what made it whole: rungs 1–5 are all keyed by declarations,
so the dangling-use capture case — a refusal, not a warning — needed
rung 6 (`files_spelling`, over the reference facts the index already
keeps, FACTS_FORMAT untouched), and the lead ruled the residue
unshippable rather than documentable. QA then enumerated resolve.rs's
full miss taxonomy to prove the rung's two blind spots workspace-
invariant, hunted a shadowing counterexample to the old-name exemption
and found the lemma held, and sabotage-verified the parity tests bite.
That is the loop working as designed. prepareRename 1.66 s → 139 ns,
rename 3.47 s → 105 ms with the rung costing 852 µs worst-case,
willRename 249 ms → 14 ms; byte-parity swept at four real cursors and
564 offsets. The accepted macro-invocation warning residue and the
FileFacts macro census stay filed; the includes.rs accessor deviation
was the correct refusal to copy a scan. Accepted; merged by the lead.
**2026-08-24 — lead.** Reviewed the full diff after QA round 2's ship
verdict; ran the three gates independently (1085 tests, 0 failures, clippy
silent). The two-layer verification in `check.rs` is the right safety story
+33
View File
@@ -443,6 +443,39 @@ Checks at the end: `cargo test -p vlog_semantic` 26 tests green (19 + 6 + 1),
`cargo clippy -p vlog_semantic --all-targets` silent, `cargo fmt` clean,
`cargo test --workspace` green.
**2026-08-28 — `WorkspaceIndex::files_spelling`, lead-authorized, additive.**
One new query, requested by refactor-rename's performance round after QA found
a lost refusal in it; the second authorized cross-module change that feature
has made (M2's `Target::Declaration` was the first).
```rust
pub fn files_spelling(&self, name: &str) -> impl Iterator<Item = FileId> + '_
```
Every file holding an **external reference fact** spelling `name`, whether or
not it resolved. Nothing was renamed, removed, re-spanned or re-ordered; no
new state, no new field, and **`FACTS_FORMAT` is untouched** — it reads the
`FileFacts::references` records the index already keeps, which is why it can
answer at all. A linear walk over those records in `FileId` order.
Why it belongs here rather than in the caller: `reference_sites` is keyed by
`DefinitionKey`, so a use that resolved to **nothing** is in no posting — the
right shape for "who refers to this declaration", the wrong one for "which
files would notice if this name started meaning something". The second
question is what a rename must ask about the name it renames *to*, and the
records that answer it are `pub(crate)`. The alternative was for the server to
re-derive it by reading and analyzing every file, which is the workspace read
that round exists to remove.
The property callers now depend on, stated so it moves under supervision:
`facts_from_analysis` records a `ReferenceFact::External` for every
`ExternalCandidate`/`InheritedCandidate` with a non-empty path list,
*including the ones the index cannot resolve*. `merge_references` then drops
the unresolvable ones when building postings — that drop is what
`files_spelling` exists to see past. If the recording rule narrows, say so in
`docs/features/refactor-rename/README.md`'s Handshakes, whose rung 6 rests on
it. Tested by `tests/workspace.rs::files_spelling_finds_the_uses_no_posting_can_be_keyed_by`.
## QA log
**2026-08-19 — QA agent.** Verified against `crates/vlog_semantic/src/{lib,model,bind,resolve,scan}.rs`
+129
View File
@@ -563,6 +563,88 @@ answer is empty. Depth 2 is the block the file belongs to — 21 files for 15 ms
of scan, once — and depth 3 is the whole of `hw/ip`, which is why the default
is 2 and not 3.
## Before / after — round 7, Lane A (2026-08-28)
`docs/features/refactor-rename/README.md` and
`docs/features/file-operations/README.md`: the three remaining `ws.sources()`
callers, and the two worst rows in `performance.md`'s table.
The framing round 6 inherited — "a rename is user-initiated, so it may be
slow" — was half wrong. **`prepareRename` is what the rename key sends before
the box opens**, and it was the second-worst number in the whole report: 2.5–
3.0 s of a wholly frozen single-threaded server on a keypress that had
committed to nothing, taking hover, definition and highlight down with it.
Its entire answer — the identifier's range and its placeholder — is in the
open buffer already.
Three fixes, three shapes:
- **`prepareRename`** is answered from the buffer's own `Semantics`, the
`ExternalResolutions` overlay beside it and the index. No file is read,
nothing is parsed. The refusal-by-refusal parity table is in the rename
README; four refusals that need the *declaring file's* own text are deferred
to `rename`, which is what LSP's optimistic `prepareRename` is for.
- **`rename`** is computed over the symbol's fan-out through the index — every
declarer of the old *and* the new name (units and members), every reference
posting, every instantiation edge, every macro definition, the containing
units and their fan-out, every file that *spells* the new name in a use the
index had to look outside that file to answer, plus every open buffer. The
sufficiency argument, the escape hatch for an ambiguously-referenced
declaration, and the named residue are in the rename README.
- **`willRenameFiles`** reads the include graph's includers instead of the
workspace: a file with no edge writes no `` `include`` this workspace can
resolve, so its turn in the sweep could only ever `continue`.
Measured over the real OpenTitan checkout (3 976 files indexed, `--release`,
same machine and corpus as `performance.md`):
| request | before | after |
|---|---:|---:|
| `textDocument/prepareRename` on the `aes` instantiation | 1.663 s | **139 ns** |
| `textDocument/rename` of `aes` (7 files edited) | 3.467 s | **105.5 ms** (7-file fan-out) |
| `workspace/willRenameFiles` for one header | 249 ms of `sources()` alone | **14.1 ms**, whole answer (331 includers of 3 976) |
The remaining 105.5 ms is the engine over 7 real files — index build, then an
analysis of each before and after the edit — not the workspace read:
`sources()` alone was 200–241 ms across runs, which is the row with the most
run-to-run spread on a machine that is not quiet. Building the fan-out itself
is **4.75 ms**, of which the one rung that scans the whole index rather than
looking a key up — `WorkspaceIndex::files_spelling`, the dangling-use rung
added in the QA-driven rework — is **852 µs at its worst** (a name nothing
spells, where the walk cannot short-circuit) and 402 µs for `clk_i`, which 681
files spell.
Every row was also checked for **equality** against the whole-workspace
computation, which is the point: this is a smaller input to the same engine,
not a cheaper approximation. Four real cursors in `tb.sv`:
| cursor | fan-out | result |
|---|---:|---|
| `aes` → `aes_core_top` | 7 of 3 976 | edits identical (7 files, 7 edits); **7 macro-invocation warnings lost** — the one accepted residue, see the rename README |
| `aes` → `prim_fifo_sync` | 7 | both refused, verbatim: *"renaming `aes` to `prim_fifo_sync` would change what `prim_fifo_sync` means in tb.sv"* |
| `clk_rst_if` → `clk_rst_thing` | 116 | edits identical (114 files, 275 edits); 64 → 61 warnings |
| `.clk_i` → `clock_in` | **3 976** | edits identical (4 files, 5 edits), all 652 warnings identical — the ambiguity escape hatch fired, so this cursor is correct but not faster |
and `prepare_rename_here` was swept against `prepare_rename` at every 7th byte
of the same file: **564 offsets, all identical, zero deferrals.**
Reproducible without that checkout, over 500 generated files of 200 lines plus
a module instantiated in three of them
(`perf::a_rename_before_and_after`, `perf::a_will_rename_before_and_after`):
| | before | after |
|---|---:|---:|
| `prepareRename` on the module name | 251 ms | **212 ns** |
| `rename` to a new name (4 files edited, 4-file fan-out) | 486 ms | **370 µs** |
| — building that file set | — | 128.7 µs, of which `files_spelling` 49.8 µs |
| `willRenameFiles`, reading the scope vs the includers | 16.1 ms | **18.9 µs** (whole answer 35.4 µs) |
Every OpenTitan and synthetic figure above was re-taken after the QA-driven
rework, so the tables describe the shipped code. The pre-rework round measured
1.604 s → 135 ns, 3.284 s → 103.6 ms, 238 ms → 200 ns and 465 ms → 294 µs on
the same corpora: the sixth rung is inside the run-to-run noise, which the
separate rung measurement says directly rather than by subtraction.
## What it would take to go faster
Ranked by what the measurements above say is there, with what each would
@@ -643,6 +725,12 @@ cost. None of these were attempted; each is a future round.
drain can break up (`perf::what_a_scan_does_before_its_first_file`).
The e2e probe above was flipped to
`a_hover_issued_during_the_initial_scan_is_answered_during_it`.
- [x] **Added in round 7, Lane A (2026-08-28):** the rename family's
before/after, over the same generated corpus round 6 uses
(`perf::a_rename_before_and_after`,
`perf::a_will_rename_before_and_after`), with the OpenTitan column and
the parity/equality sweeps taken by throwaway probes against the local
checkout and deleted.
- [ ] **Round 1's second open TODO, restated and still open:** memory.
Nothing in the repo measures resident size. Round 2 added no data
structure — two free functions and no state — so the figure it would
@@ -748,6 +836,47 @@ No figure in any earlier round was re-measured: nothing on those paths
changed. `completion.rs`'s tier 0 and `candidates.rs`'s tables are on no
earlier table.
**2026-08-28 — dev (round 7, Lane A).** Two probes added,
`a_rename_before_and_after` and `a_will_rename_before_and_after`, both over
the same 500-file generated corpus `a_code_action_at_an_instantiation_before_and_after`
uses — factored into `rename_corpus` so the three read against one another.
Each prints a before column computed the way the handler computed it until
this round (`vlog_refactor::rename` over `ws.sources()`) and an after column
that calls the real handler, so the comparison is one workspace, one cursor,
one run.
The OpenTitan column of round 7's table came from throwaway probes against
the owner's local checkout, run and deleted — no test may depend on a
checkout this repository does not carry. Three of them: the timings, a
**parity sweep** over every 7th byte of `tb.sv` comparing
`prepare_rename_here` against `prepare_rename` (564 offsets, all identical,
zero deferrals), and an **equality sweep** over four real cursors comparing
the fan-out rename against the whole-workspace one. The last is what earned
its keep: it showed the edit sets byte-identical everywhere (7 files at `aes`,
114 at `clk_rst_if`, 4 at `.clk_i`) and the capture refusal firing verbatim on
`aes` → `prim_fifo_sync`, **and** it found the one thing the synthetic suite
could not — the macro-invocation warnings the fan-out cannot see. That finding
is written up in `docs/features/refactor-rename/README.md`; it is also why the
`` `define`` rung of the fan-out is a walk over the index's tables rather than
a `find_define` lookup, which recovered two of the five warnings the
`clk_rst_if` cursor was losing.
Note on `a_rename_before_and_after`'s before column: it is ~480 ms rather than
the 249 ms `a_code_action_…` records for `prepare_rename` on the same corpus,
because a rename does the analysis twice — once to collect, once to verify —
where a prepare stops after locating the cursor. Both rows are printed by the
same run so neither has to be trusted from memory.
**2026-08-28 — dev (round 7 rework).** QA found a lost refusal in the fan-out
and the lead ruled it not shippable; the fix added a sixth rung
(`WorkspaceIndex::files_spelling`) whose cost, unlike the other five, grows
with the workspace rather than with the symbol. So `a_rename_before_and_after`
grew two lines — the whole file-set build, and that rung on its own — because
"the rung is free" is a claim, and a claim in this document needs a number
beside it. Every figure in round 7's tables was re-taken against the reworked
code rather than carried over; the pre-rework numbers are quoted underneath so
the rung's cost can be read as a difference as well as directly.
## QA log
**2026-08-28 — QA.** No findings — every number reproduces within reason.