TODO section 29; closes docs/topo.md 2.9-18 (server half) and 2.9-5; the second half of coverage_gaps M12. FileFacts::macro_words - the identifier-shaped words seen inside macro invocations, directive lines and attributes (words::harvest_raw, which shares its raw-token match with harvest so the two cannot drift) - tag MW, FACTS_FORMAT 16 -> 17 (+3.1 percent corpus / +1.7 percent opentitan store, measured). WorkspaceIndex::files_naming_in_macros is files_mentioning's twin, and lucisv_server::rename appends one warning per such file that lies outside the set rename_sources built: no new rung, nothing read, 58 files in 186 microseconds for clk on opentitan. Pinned by a three-file case and its no-double-warning control, run by QA against the real server; QA also found an organic instance in opentitan (cipher_crypt inside a DV_CHECK_FATAL) that 0.33.0 never mentioned. vlog_refactor's Scope moves to the crate root (pure move, counts identical). lucisv check --rules-doc prints rules_markdown(), takes no files, is lint-only; the example binary is gone. 3 226 tests / 48 binaries, corpus 814/820, opentitan check byte- identical to 0.33.0. docs/features/macro-word-census/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
refactor-rename
Milestone M2 of docs/features/refactor/README.md.
Goal
Give lucisv the refactoring every Verilog user misses: rename a symbol and have
every reference to it change, across files, or have the request refused with
a sentence explaining why. The engine lives in a new crate,
crates/vlog_refactor, so the CLI and every editor get identical behavior;
lucisv_server only maps the protocol (textDocument/prepareRename,
textDocument/rename → WorkspaceEdit). Every edit comes from a span the
semantic layer resolved — there is no textual search-and-replace anywhere in
this feature — and the whole edit is verified in memory before it is returned:
re-tokenize every touched file and re-resolve it, and refuse the entire
rename if anything but the renamed name moved. That is the formatter's
never-corrupt contract, applied to refactoring, without touching
vlog_formatter or verify.rs.
API as built
// crates/vlog_refactor/src/lib.rs
pub struct TextEdit { pub range: TextRange, pub new_text: String }
pub struct RefactorEdit { pub edits: Vec<(PathBuf, Vec<TextEdit>)>, pub warnings: Vec<String> }
pub struct RenameTarget { pub range: TextRange, pub name: String }
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 —
exactly what WorkspaceIndex::build already takes, and exactly what
lucisv_server's scope resolution (M1's filelist ⊃ walk ⊃ siblings ladder, open
buffers overlaying disk) already produces. No trait, no borrow of server
state, no I/O inside the crate.
Err(String) is a user-facing sentence: the server returns it verbatim as
the LSP request error, which is what VS Code puts in the rename box.
Deviations from the milestone sketch, and why:
offset: u32, notusize. Everything below the protocol —TextRange,Semantics::symbol_at,Def.name_span— counts bytes inu32. Ausizeparameter would be cast at both ends of every call.prepare_renamereturns aRenameTarget, not a bare range: the editor wants the placeholder too, and it is the identifier's own text.prepare_rename_heretakes 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_renamestays as the whole-workspace oracle the parity tests measure it against. See "The file set a rename reads" below.rename_name_atdecides 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 withrename, which is the call that has the files; a second opinion here could only disagree with it.
What can be renamed
Every kind vlog_semantic resolves, because the engine never looks at
SymbolKind at all — it renames "the symbol the cursor resolves to", whatever
that is: nets and variables (wire/reg/logic/int), module ports (ANSI
and non-ANSI, where the redeclaration is a reference to the header port),
parameters and localparams, genvars, typedefs, enum variants, struct members,
functions, tasks, task/function arguments, block labels, module names,
instance names, packages, classes and class members.
Renaming from a reference works exactly like renaming from the declaration: the cursor is resolved to a declaration first (in this file, or through the workspace overlay into another file), and everything after that is the same code path.
End labels move with their declaration. endmodule : m,
endinterface/endpackage/endfunction/endtask/endclass : name, and
end : label / join : label on a named block or generate block are all
edited, because vlog_semantic records each of them as a use of the
declaration it closes (round 2 of this milestone; see Handshakes). No text
matching is involved: the label is bound to its own construct by the binder,
so a label can never attach to a same-named declaration somewhere else. Two
cases still record nothing and are warned about instead — a label that does
not spell the declared name (already illegal SystemVerilog) and a label whose
declaration was a redeclaration that bound no symbol of its own.
Cross-file comes from the same overlay textDocument/definition uses: every
in-scope file is analyzed, its external candidates are resolved against the
WorkspaceIndex, and a reference whose answer is this declaration
(same FileId, same name_span) is an edit. That covers module names in
instantiations, package members at import p::* / import p::x / p::x
sites, .port(...) connection names, and #(.PARAM(...)) overrides.
The refusal list — exact
rename returns Err and produces no edits at all when:
new_nameis empty, does not lex, lexes to more than one token, lexes to something that is not an identifier, or is a keyword.new_nameis the name it already has.- The file the request names is not one of the in-scope files.
- The cursor is on no identifier the semantic layer recorded (whitespace,
punctuation, a keyword, a
`definedirective, a system task). - The identifier is a reference the layer left
NotFound. - The identifier is a reference the layer left
InheritedCandidate— a name that could only come through a class'sextends, which nothing resolves. - The identifier is an external candidate the workspace index cannot answer
(
StillUnresolved): the declaration is outside the indexed files, so the rename would be half a rename. - The identifier is an external candidate the index answers ambiguously
(
ExternalTarget::Ambiguous) — the name is declared in more than one file and picking one would be a coin flip. - The declaration is a file-scope unit (module, package, class, file-scope typedef) whose name the index holds more than once — the same ambiguity, caught when the rename starts from the declaration and so never reaches rule 8.
- Some other in-scope reference to the name resolves ambiguously onto this declaration — a use lucisv would have to edit but cannot attribute.
- The declaration's
name_spanis empty (the layer could not find the name literally in the source), or an edit span does not slice back to the name. - Collision / capture. After applying the edits in memory and
re-analyzing every watched file — every file the edits touch, plus
every file whose text spells the old or the new name — any reference or
declaration resolves differently than it did before (modulo the rename
itself), or the reference/declaration sets differ in size. This is the
check that refuses
x→ywhen ayalready exists in a scope the rename reaches, in both directions: the renamed uses being captured by an existingy, and an existing use ofybeing captured by the renamed declaration — including in a third file the rename never edits, whose existingyreference the rename would make ambiguous. - Token verification. A touched file no longer lexes, or its token stream is not identical to the original's except that the edited identifier tokens spell the new name — same count, same kinds, same texts, same attached comments, same spans after shifting.
Rules 12 and 13 are checked over the whole edit; either one fails the entire
rename, never part of it (RefactorEdit is all-or-nothing, hard invariant 1's
shape for refactorings).
prepare_rename applies rules 3–7 (and 9), which is exactly what an editor
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}:
- every file declaring
N—WorkspaceIndex::workspace_symbols(N)filtered to the exact name, which covers units and members (ports, parameters, package and class members); - 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; - every file instantiating
N—instantiations_of(N); - every file whose
`definetable namesNor spells it in a macro body — a walk over theDefineTables the index already holds (no file is read), asking the samevlog_refactor::contains_wordthatScope::define_sitesdecides with, so the fan-out and the warning cannot disagree about which files carry one; - the units that export
Nas a member, and every file declaring, referring to or instantiating one of them — how a third file's.N(...)connection oru::Nis reached.
and, for the new name only, a sixth:
- 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_occurrencesemits 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, byevery_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::xand ap::x/q::xreference would fall through toq::xand be renamed — which is why rung 1 isworkspace_symbolsand notunits. - The verifier keeps its reach.
check::watched_fileswatches 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_elsewherebuilds 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_toof 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_onelooks the name up inunits(old)andmember(u, old); the rename only takes entries out of those, and a lookup cannot start succeeding because a candidate was taken away.Anchor::Unresolvedbefore,Anchor::Unresolvedafter — 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::warningsproduces three sentences. Two are read off a file's`definetable ("xis also a macro defined at …" and "xappears in the body of macroM…") 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` invocationsThose 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.svmentionsaesonly 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 atokenizeof every file spelling the name, which is most of the win this round is for. The right answer is a macro-invocation census inFileFacts, which would make this rung an index lookup like the other five; that is avlog_semanticchange, 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 anything is returned.
1. Token-stream identity. Every touched file is re-tokenized. The new
stream must have the same length as the old one, and token i must have the
same kind, the same attached comments (leading list and trailing, by text),
the same blank_before, the span it gets by shifting the original's, and the
same text — except for tokens whose span is exactly an edit, which must be
Ident tokens spelling the new name. A rename that merged two tokens, split
one, ate a comment, changed a number's spelling or wandered into a string or a
directive cannot survive this. It is the analog of the formatter's verify
pass, and it lives in this crate rather than borrowing verify.rs — hard
invariant 4 says the formatter's safety net does not widen, and nothing here
touches it.
2. Resolution identity. For every watched file, before and after, the
engine builds a print of every declaration (name_span, name, kind) and
every reference (name_span, name, what it resolves to), where "what it
resolves to" is a workspace-wide anchor: Local(span) for an in-file
resolution, External(path, span) for one the overlay answered, None for
anything unresolved. The before print has its spans and anchors shifted
through the edit map, and the names of the edited occurrences replaced with
the new name. The two prints must be equal. So: every edited occurrence
still resolves to the renamed declaration, the renamed declaration still has
exactly the same reference set, and no other name in those files changed
meaning. The post-edit side re-builds the workspace index over the edited
texts, so a cross-file capture is caught the same way an in-file one is.
The watch list. Watched = every file that receives an edit, plus every
file whose text spells the old name or the new name as a whole word. That is
sound: an edit only adds and removes declarations of those two names, and a
lookup of any other name cannot see them, so a file mentioning neither
cannot change meaning. The whole-word text search is a deliberate
superset of "has a token spelling the name" — a token always spells its name
literally — so it errs by watching a file whose only mention is in a comment,
which costs one analysis and never causes a refusal (its print is identical
either way; there is a test). This is what closes QA's third-file case:
top.sv instantiating a pre-existing child never spells sub, receives no
edit, and would previously have been accepted while its instantiation
silently became ambiguous.
Why the whole print and not just the names involved: only lookups of the old and the new name can change, so a narrower check would be sound — but it would need its own argument for why, and the wide one costs a few hundred microseconds on a Verilog file and needs no argument at all. Simplicity first.
Preprocessor honesty
lucisv does not preprocess (TODO.md §7). What that means here, exactly as implemented:
`definebodies and macro names are never edited. A`defineis oneDirectivetoken, so the semantic layer records no reference inside it and no edit can be produced there in the first place. When the workspace'sDefineTables show the name as a macro name (`define a/`undef a) or inside a macro body, a warning names the file and line.- Macro invocations are never edited, and their arguments are warned
about.
`BUMP(a)lexes as a single opaqueIdenttoken, name and argument list together, soainside it is invisible to the semantic layer — there is nothing to resolve and nothing to edit. The engine scans every in-scope file's macro-invocation tokens for the name as a whole word and warns per occurrence: "aappears in the arguments of the macro invocation`BUMPat m.sv:4 …". This scan covers files the rename never edits, since a macro call in an untouched file still expands to the old name. - A reference the workspace could not finish is left alone and warned
about too. Added 2026-09-02 (
docs/features/comment-slots/README.md,docs/topo.md§2.9-20). The stray-token scan below cannot see these: it skips any span the semantic layer recorded a reference for, and a hierarchical tail likeu_x.sigdoes carry one — anExternalCandidate { paths: ["unknown_mod::sig"] }the overlay leavesExternalTarget::StillUnresolvedbecause nothing in the indexed workspace answers it. Before this the tail had no reference at all and the stray scan warned about it; gaining a reference is what silenced it.Scope::unresolved_candidate_warningsasks theResolutionfirst (anInheritedCandidatethat missed stores nothing in the overlay, soExternalResolutions::getanswersNonefor it and for a plain local miss alike), then checks forStillUnresolved, and emits one line per (file, unit): "sigat top.sv line(s) 4 could not be resolved — nothing in the indexed workspace answersunknown_mod::sig, so lucisv records no reference there and it was left unchanged." Like the macro-invocation scan it runs over every file that spells the name, not only the edited ones, and it costs nothing extra becausecollect_occurrenceshas already analysed each of them. `ifdefarms are ordinary tokens to lucisv, so a resolved reference inside one is renamed — in every arm. That is the honest behavior: the tokens are there, they bound to the declaration, and editing only one arm would break the build for the other. No warning; there is nothing left unaccounted for.- Occurrences the layer records nothing for are left alone and warned
about, grouped by why — the warning names the actual construct rather
than guessing at a template:
a hierarchical or member tail, which lucisv does not resolve—u_inst.sig,a.b.c, anddefparam u1.Ppaths. This is the honest limitation: resolving a tail needs instance elaboration, which is a non-goal ofvlog_semantic. Adefparamnaming a renamed parameter is therefore left pointing at the old name, and said so.an end label lucisv could not attach to its declaration— a mismatched label, or one whose declaration was a redeclaration.a label lucisv records no declaration for, andan occurrence lucisv cannot attribute to any declarationfor the rest.
Assumptions
- The caller hands over the same file set the workspace index was built from, with open buffers already overlaying disk. The crate does no I/O and does not walk anything.
- A file whose text does not contain the old name as a substring cannot
contain a reference to it, so it is never analyzed. Sound because the
semantic layer promises
src[reference.name_span] == reference.name— a reference always spells its name literally. This prefilter is what keeps a rename over an 860-file workspace to a handful of analyses. - Duplicate paths in
filesare deduplicated exactly asWorkspaceIndex::builddoes it (sort by path, first copy wins), so the engine's file indices and the index'sFileIds 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. 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.
Handshakes
Consumed from vlog_parser (no change required):
tokenize,parse_source_tolerant,LineIndex,TextRange.token::{Token, TokenKind, is_keyword}— the new-name validity check and the token-stream verification.defines::{DefineTable, DefineKind}via the index — the macro warnings.
Consumed from vlog_semantic (no change required, nothing patched):
analyze,Semantics::{symbol, symbol_at, reference_at, reference_id_at, references, references_of, file_scope, scope}.Resolution::{Resolved, ExternalCandidate, InheritedCandidate, NotFound}— the last three are three of the refusal rules.WorkspaceIndex::{build, files, path, units, defines},resolve_external,ExternalTarget::{Resolved, Ambiguous, StillUnresolved},Def.- The promise that
Symbol.name_span/Reference.name_spanare exact byte 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 spellingname, resolved or not. New query, no new state, no format change: it reads theFileFacts::referencesrecords the index already keeps, andFACTS_FORMATis untouched. Logged indocs/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 spelledNthat 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_tois keyed by the declaration a use landed on, so a use that landed on nothing is in no posting.files_spellingis the same records asked by spelling instead, which is what makes it answer for the unresolved ones. Iffacts_from_analysisever stops recording an unresolved external candidate — today it records everyExternalCandidate/InheritedCandidatewith 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):
renamenever panics and never returns a partial edit:Okmeans every edit in it verified together,Errmeans nothing at all is to be applied.prepare_rename_hererefuses in the same sentencesprepare_renamedoes, or defers torename; it never invents a refusalprepare_renamewould not have made. The parity table above is the contract, and the byte-by-byte parity tests are the enforcement.rename_name_atnames the identifierprepare_rename'sRenameTargetwould name, at every offset whereprepare_renameanswers 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.editsis sorted by path; each file's edits are sorted by start offset, non-overlapping and non-empty.warningsare informational only — anOkresult with warnings is still safe to apply.
Changed in vlog_semantic (lead-authorized 2026-08-24 after QA round 1;
strictly additive, and the only cross-module change this milestone makes):
bind::TargetgainsDeclaration(SymbolId)— "this exact declaration, no lookup".resolve.rsanswers it withResolution::Resolved(id).Binder::use_end_labelrecords an end label as a use of the declaration it closes, called from the module/interface, package, class, function, task, generate-block and statement-block/fork-join arms.- Nothing was renamed, removed or re-spanned;
vlog_parserneeded no change at all, becauseend_label/end_label_spanwere already on every one of those AST nodes. Logged indocs/features/vlog-semantic/README.md's work log, and its "end labels record nothing" simplification is struck there.
The reason this could not stay inside vlog_refactor: a rename that leaves
endmodule : old_name behind produces non-compiling SystemVerilog, and
the only alternative — matching the label textually — would have broken this
feature's one structural rule, that every edit comes from a resolved
reference.
Requested of nobody else. Hierarchical tails and defparam paths remain
unresolved by design (vlog_semantic non-goal: "resolving a tail needs
instance elaboration"), so they stay warned-not-edited; making them edits is
a much larger change than an end label and is not part of M2.
Status / TODO
- New crate
crates/vlog_refactor(workspace member; depends onvlog_parser+vlog_semanticonly — no formatter, no LSP types) TextEdit/RefactorEdit/RenameTargetmodel- Target location: from a declaration, from an in-file reference, from a cross-file reference through the overlay
- Cross-file edit collection through
resolve_external - New-name validity (single identifier token, not a keyword)
- Refusals: unresolved, inherited, still-unresolved, ambiguous (both directions), empty name span, same name, unknown file
- Collision safety by re-analysis (resolution print equality) over every watched file, edited or not (QA round 1, HIGH #1)
- Token-stream verification per touched file
`definewarnings, macro-invocation-argument warnings (QA round 1, HIGH #2), and unaccounted-occurrence warnings grouped by reason- End labels renamed with their declaration, through a lead-authorized
vlog_semanticchange (QA round 1, priority finding) lucisv_server:rename.rs,prepareRename+rename, capabilities- Tests: 64 in
vlog_refactor(14 unit incl. 8 masked-corruption attacks, 48 behavior, 2 corpus), 3 new invlog_semantic, 8 inlucisv_server(7 inrename.rs, 1 capability), 1 e2e session prepareRenameanswered from the open buffer and the index rather than fromsources()(2026-08-28):prepare_rename_herein the engine, the refusal-by-refusal parity table above, and six byte-by-byte parity suites againstprepare_renameas the oraclerenamecomputed over the symbol's fan-out rather than the whole scope (2026-08-28):Workspace::rename_sourcesin the server,rename_name_atin the engine, the sufficiency argument above, the ambiguity escape hatch, and equivalence tests over hostile workspaces- The dangling-use rung (2026-08-28, QA-driven rework):
WorkspaceIndex::files_spellingand 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
(
workspace/willRenameFiles) — umbrella backlog - Deferred (honest limitation, documented in Preprocessor honesty):
hierarchical tails (
u_inst.sig) anddefparampaths stay warned-not-edited; resolving them needs instance elaboration, avlog_semanticnon-goal
Corpus acceptance
cargo test -p vlog_refactor --test corpus -- --nocapture, over the 860
.v/.sv/.svh files in corpus/ (Ibex, OpenTitan, PULP common_cells,
picorv32), 2026-08-24:
corpus rename over 860 files: Ok((6, 18)) in 0.38s (release; 1.7s debug)
Renaming prim_fifo_sync — a module OpenTitan instantiates all over — edits
6 files, 18 occurrences: the declaration, the instantiations, and the
.port/#(.PARAM) names that reach into it. Every edit slices back to
prim_fifo_sync in the file it names (asserted), and the whole thing takes
0.38 s in release over the full corpus, index rebuild and verification pass
included. The substring prefilter is what buys that: 860 files are indexed
twice, but only the handful that spell the name are analyzed.
The second test asks prepare_rename at 300 offsets spread over a real file —
whitespace, punctuation, mid-token, mid-comment, mid-directive — and requires
an answer at every one and a panic at none.
The tests assert the properties, not the numbers: no panic, every edit covers the name, more than one file touched, under 30 s, and a refusal (which is a correct answer — the corpus really does declare some names twice) reads as a sentence.
Work log
2026-08-24 — dev agent. Built the crate and the server wiring.
Key decisions, all argued above:
(PathBuf, String)slice as the file view, not a trait. The server already materializes exactly this list forWorkspaceIndex::build; a trait would have one implementor and would have to answer "what is the file set?" as well as "what is this file's text?", which the caller knows better.- Everything canonicalizes to a declaration before any edit is computed. Renaming from a reference is not a second code path; it is one extra overlay lookup at the front.
- Verification is two checks, not one. The token check catches lexical damage (an edit landing inside a string, a comment lost, two tokens merged); the resolution check catches semantic damage (capture, shadowing, a cross-file use silently rebinding). Neither implies the other: a capture leaves the token stream perfect, and a botched span leaves resolution plausible.
- The whole-file resolution print, rather than only the references spelling the old or the new name. The narrow check is sound, but the wide one is obviously sound, and a Verilog file's reference list is a few thousand entries at most.
- The substring prefilter is the one performance concession, and it rests
on a promise the semantic layer's corpus test already asserts (every
name_spanslices back to its name). - Unaccounted occurrences are warned about, not edited.
endmodule : mis the motivating case. Editing it would mean textual replacement, which this feature does not do anywhere; warning is the honest half-measure until the parser/semantic layer records the label. (Superseded 2026-08-24 by the rework entry below: end labels are references now and are edited.) - Server errors use LSP's
RequestFailed(-32803), which is what the protocol reserves for "the request was well-formed and the server declined"; VS Code shows the message in the rename box.prepareRenameuses the same code, which is how the editor is stopped from offering a rename that would later fail. Workspace::rebuild_indexand the newWorkspace::sourcesshare one helper (collect_sources), so a rename sees byte-for-byte the file set the index was built from, including the open-buffer overlay, without keeping a second copy of the workspace in memory.
Two things worth flagging for review:
endmodule : mlabels are warned about, not renamed. This is the one place a user could be surprised. The alternative needs a reference fromvlog_semanticfor the end label ("endmodule : mand other end labels record nothing",docs/features/vlog-semantic/README.md), which is a handshake for a later round rather than a textual patch here. (The lead authorized exactly that handshake; see the rework entry below.)- A
#[allow(clippy::mutable_key_type)]oncrates/lucisv_server/src/rename.rs, with the reason in a comment:WorkspaceEdit.changesis keyed bylsp_types::Uri, whose interior mutability is its own parse cache and takes no part inHash/Eq. The map's shape is the protocol's, not ours.
Checks at the end: cargo fmt --all -- --check clean,
cargo clippy --all-targets silent (zero warnings, workspace-wide),
cargo test --workspace green — 55 in vlog_refactor, 212 in lucisv_server's
unit suite, 12 e2e sessions, nothing else moved. No unwrap/expect/panic!
and no unsafe in any library path of either crate (test modules only).
2026-08-24 (later) — dev agent, rework after QA round 1 and the lead's three rulings. All three items closed; nothing else in the design moved.
1. End labels are renamed, not warned (priority finding). Taking the
lead's authorization, the change went into vlog_semantic and not into
vlog_parser: every node that can carry a label — Module (module and
interface), ItemKind::Package, ClassDecl, FunctionDecl, TaskDecl,
GenBlock, StmtKind::Block, StmtKind::ForkJoin — already carried
end_label and end_label_span, so there was nothing to add to the AST and
the spans suite never moved. bind.rs gains one target variant,
Target::Declaration(SymbolId), and one 20-line helper, use_end_label;
resolve.rs answers the variant with Resolution::Resolved(id).
The decision that matters is binding, not lookup: the label is recorded
as a use of the symbol the binder just created for that construct, so
end : inner inside a module cannot attach to a different inner declared
elsewhere, and no text matching is involved anywhere. Two cases deliberately
record nothing rather than guess — a label that does not spell the declared
name (endmodule : wrong, already illegal), and a label whose declaration was
a redeclaration that bound no symbol of its own (wire m; then begin : m).
Both then fall through to the warning path, which now names them precisely.
endclocking is untouched: a clocking block is opaque to vlog_semantic and
declares no symbol. Three tests added in vlog_semantic, five in
vlog_refactor — including the two masked-corruption attacks the lead asked
for: an end label belonging to a different construct of the same name must
not be edited, and // endmodule : m / "endmodule : m" in a comment and a
string must not be edited.
2. Third-file collision (HIGH #1). check::verify no longer iterates the
edited files; it iterates the watched files —
check.rs::watched_files — which is the edited set plus every in-scope file
whose text spells the old or the new name as a whole word. The soundness
argument is one sentence and is now in the Verification story: an edit only
adds and removes declarations of those two names, so a file mentioning
neither cannot change meaning. Whole-word text search rather than a token
scan, deliberately: it is a superset (a token always spells its name
literally), it needs no parse to decide, and over-inclusion costs one analysis
and never a refusal. QA's exact 3-file reproduction is now
a_collision_with_a_third_file_that_never_spells_the_old_name_is_refused,
and its mirror —
a_third_file_that_merely_mentions_the_new_name_in_a_comment_is_not_a_collision
— pins the no-false-refusal half. Corpus rename is unchanged at 0.35 s.
3. Macro-invocation arguments (HIGH #2). The README's promise was true of
`define bodies and false of macro calls, because a call is one opaque
token and unaccounted_warning compared whole token texts. New
Scope::macro_use_warnings scans macro-invocation tokens (Token::is_macro)
for the name as a whole word inside the argument list, in every in-scope
file that spells it — not only edited ones, since a call in an untouched file
still expands to the old name. They are warnings, never edits: opaque is
opaque. The Preprocessor honesty section was rewritten to describe exactly
this, and to state the hierarchical-tail/defparam limitation as the
limitation it is rather than burying it.
Bonus defect, fixed. The fixed `endmodule : X` warning template is
gone. unaccounted_warnings now groups strays by reason, read off the
token stream's neighbours (stray_reason): a . before the name means a
hierarchical or member tail; a : preceded by an end* keyword means an end
label that could not be attached; the rest say so plainly. One warning per
reason per file, naming the lines.
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_heretakes an analysis, not a file set. The server already holds the buffer'sSemantics, itsExternalResolutionsoverlay and the index, and the overlay isresolve_externalagainst that same index — which is the exact callScope::declaration_across_filesmakes. 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_renamestays, 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, notunits. This is the rung the whole equality argument turns on and the one that was easy to get wrong:follow_pathslooks a reference's own name up, inunits(N)ormember(u, N), and both tables are contributed only by files that declare the nameN. Drop the file declaringp::xfrom the set and a reference with paths[p::, q::]falls through toq::xand 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_sourceshands backsources()when the index reports one. Slow and correct beats fast and silent. willRenameFilesgot the same treatment through the include graph — written up indocs/features/file-operations/README.md, including the four-lineIncludeGraph::includersaccessor, 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-authorizedvlog_semanticquery: every file holding an external reference fact spelling the name, resolved or not. No new state, no new field,FACTS_FORMATuntouched; it reads theFileFacts::referencesrecords the index already keeps, which is the only reason the answer is available at all without reading files. Logged indocs/features/vlog-semantic/README.md's work log as M2'sTarget::Declarationwas, 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 bya_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.
Gates
cargo fmt --all -- --check— clean.cargo clippy --all-targets— clean, zero warnings, workspace-wide (verified with a forced re-check aftertouching the new files, since the first run was a no-op cache hit).cargo test --workspace— green, 0 failures across every crate. Counts match the Work log's claims:vlog_refactor55 (14 unit incl. 8 masked-corruption attacks incheck.rs, 39 behavior intests/rename.rs, 2 corpus),lucisv_serverunit suite 212,lucisv_servere2e 12 sessions (the_binary_serves_a_whole_session_over_stdioand friends).- Spot-checked the "no
unwrap/expect/panic!/unsafein library paths" claim: the onlyexpect()calls incrates/vlog_refactor/src/check.rsare inside#[cfg(test)] mod tests(lines 302-303, 380). None incrates/lucisv_server/src/rename.rsoutside its test module. The single#![allow(clippy::mutable_key_type)]inlucisv_server/src/rename.rs:13carries the required explanatory comment (lines 8-12). All confirmed. - All three gates: pass, claims confirmed.
Priority finding — stale end labels (assessed, not fixed)
Reproduced with the crate's public API for every construct that carries an
end label. Given module m; ... endmodule : m, renaming m produces
module top; ... endmodule : m — the label is untouched, and a warning is
attached ("1 occurrence(s) of m ... are not resolved references ... and
were left unchanged."). This is IEEE 1800 non-compiling output (the end
label must match) but the dev's own test
(crates/vlog_refactor/tests/rename.rs:561 an_end_label_is_left_alone_and_reported)
asserts exactly this as intended behavior, and the Work log already flags it
for lead review.
I reproduced the same pattern for every other end-labeled construct, which the milestone spec didn't enumerate individually — all of them are affected, all of them only warned:
function ... endfunction : f→ label staysfafter rename tog.task ... endtask : t→ label staystafter rename tou.class ... endclass : c→ label stayscafter rename tod.package ... endpackage : p→ label stayspafter rename toq.begin : blk ... end : blk(named block) → label staysblkafter rename tonewblk.
Bonus defect while reproducing this: the warning text is a fixed
template that always says `endmodule : X` — literally, regardless of
which construct produced the stray occurrence
(crates/vlog_refactor/src/rename.rs:497). For the function/task/class/
package/block cases above, the warning shown to the user names the wrong
keyword (e.g. renaming a task still says an `endmodule : t` label,
never endtask). Small, but it actively misleads whoever reads the
warning while trying to find and fix the stale label by hand.
Verdict on severity: this is a real, reproducible non-compiling-output
defect, but it is a known, deliberate, tested, and disclosed tradeoff — the
dev flagged it explicitly for review and the Status/TODO says why
(vlog_semantic records no reference for end labels yet). I'm not treating
it as a blocking QA finding on its own; it needs the lead's call on whether
M2 ships with this caveat or waits for the vlog_semantic handshake. I am
flagging the warning-text bug above as new information the lead should have.
New finding (HIGH) — a rename can be accepted while silently making an
untouched third file's existing reference ambiguous
The README's rule 12 / "verification story" claims collision safety is
checked "in both directions ... an existing use of y being captured by
the renamed declaration," over the whole workspace. In the implementation
this is only true for files that themselves received an edit
(crates/vlog_refactor/src/check.rs:47-78 iterates edits/edited, which
only contains files collect_edits touched — i.e. files that spell
old_name). A file that spells only new_name, and never old_name, is
outside the substring prefilter (rename.rs:351) and is never re-analyzed
before/after, even though rebuilt_index (check.rs:86-95) does include
its real, unedited text — so the ambiguity really exists in the rebuilt
index, it's just never diffed against anything.
Reproduction (workspace of 3 files, using the public API directly):
sub.sv: module sub;\nendmodule\n // rename target; nothing else in scope mentions "sub"
child.sv: module child;\nendmodule\n // pre-existing, unrelated module named "child"
top.sv: module top;\n child u1();\nendmodule\n // instantiates child.sv's child; never spells "sub"
rename(&files, &path("sub.sv"), <offset of "sub">, "child") returns Ok
with one edit (sub.sv only) and warnings: []. After applying it, the
workspace has two modules named child (the renamed one in sub.sv, and the
pre-existing one in child.sv), and top.sv's child u1(); — which used to
resolve unambiguously — is now ambiguous. top.sv's bytes are untouched, so
there's no textual corruption, but its meaning silently broke and nothing
in the response says so. This is the same shape as the milestone's own
a_collision_in_another_file_is_refused_too test
(crates/vlog_refactor/tests/rename.rs:474) — except that test's top.sv
already instantiates both sub and child, so top.sv is itself in the
edited set and the existing check catches it. Drop the sub instantiation
from top.sv (nothing else needs to reference the rename target for the
collision to be real) and the refusal silently disappears.
This is not the end-label case: there is no warning, no partial edit, no
indication anything is wrong — rename reports full success. It directly
contradicts the "both directions" claim in the Verification story section
and, I'd argue, the umbrella's "refuses rather than guesses" principle. I
did not fix it (would need check.rs's resolution-identity pass to run over
every in-scope file with a nonempty diff against rebuilt_index, not just
edited — a real design change, not a small fix). Verified reproducible on
a second run. The probe test itself was scratch (not committed); the repro
above is exact enough to rebuild in under a minute.
New finding (HIGH) — macro-invocation arguments are silently never
renamed, with no warning, contradicting the "Preprocessor honesty" section
The README states plainly: "text inside a macro invocation's arguments ... are left alone and warned about." Reproduced the opposite: given
`define BUMP(x) x = x + 1
module m;
int a;
initial `BUMP(a);
endmodule
renaming a → b (from the int a; declaration) returns Ok with the
declaration and no other edits, and warnings: [] — the a inside
`BUMP(a) is left as literal text a, and nothing tells the user.
Root cause: vlog_parser::tokenize lexes an entire macro invocation
(name and its parenthesized arguments) as one opaque Ident token
(confirmed by direct tokenization: `BUMP(a) tokenizes to a single
Ident token with text "`BUMP(a)", span covering the whole thing —
consistent with vlog_semantic's own scan::tests::a_macro_invocation_is_one_opaque_token).
unaccounted_warning (crates/vlog_refactor/src/rename.rs:470-501) looks
for stray Ident tokens whose text equals the target name
(t.kind == TokenKind::Ident && t.text == name, line 488). Since the
argument's text is buried inside a bigger token ("`BUMP(a)" ≠ "a"),
it can never match, so this class of occurrence can never produce the
warning the README promises for it. This is different from the endmodule : m case: there, a warning is correctly produced (the label is its own
plain Ident token). Here, the mechanism that would normally catch "text
the layer records nothing for" structurally cannot see inside an opaque
macro-invocation token, so the specific promise in the README is simply
false as implemented.
This one is worse than the end-label case for the same reason as the
collision finding above: complete silence. A user renaming a variable that
happens to be passed through a function-like macro gets an Ok, zero
warnings, and a file that no longer behaves as documented (the macro
expansion still uses the old name, the declaration doesn't exist under that
name anymore). Whether the right fix is "warn, like macro bodies" or
"refuse when a macro invocation argument spells the name" is a design call
for the dev/lead — the README already committed to "warn," so at minimum the
implementation doesn't match its own contract.
Other attack attempts — passed, no corruption found
- Port name vs. connection signal name,
.p(p). Renaming the port declaration only rewrites the connection-name side (.p(...)→.port_new(...)), leaving the connected signal alone. Renaming the signal only rewrites the expression side (.p(sig_new)), leaving the port name alone. Both directions correct. - Genvar used inside a
generate/forloop. Declaration and every use inside the loop header and body renamed correctly. - Two symbols with the same name in sibling scopes (
begin : b1 int n; end/begin : b2 int n; end). Renamingb1'snleavesb2'snuntouched — matches the dev's owna_name_that_only_shadows_somewhere_the_rename_never_reaches_is_allowedtest, reproduced independently with a different shape. - Module instantiated via
bind.bind top leaf b_leaf ();— renamingleafcorrectly updates thebindstatement's target type along with the declaration. - Hierarchical reference tail,
u_inst.siganddefparam u1.P. Both left unedited and both correctly warned about as "a hierarchical or member tail" — consistent with the README. (Note: likeendmodule : m, this means adefparamtargeting a renamed parameter is left referencing the old parameter name — also non-compiling output, also warned-not- fixed, same class of issue as the priority finding. Didn't reproduce every variant given the time budget; flagging so the lead's end-label decision coversdefparampaths too, not justendmodule/endlabels.) - New name requiring escaping (leading digit, e.g.
1bad) — refused with "not a valid Verilog identifier," as expected. - Rename inside a file with error nodes (tolerant parse, garbage statement present) — renamed the valid declaration/use correctly, no panic, garbage left untouched.
new_name == old_name, comments/strings, ambiguous declarations, unresolved/inherited candidates — all covered by the existing suite; read and spot-re-ran, all still refuse/behave as documented.
Real server binary over stdio
Built target/debug/lucisv-server and drove it directly with a hand-rolled
LSP/stdio client (initialize → initialized → didOpen →
textDocument/rename → shutdown → exit), not just the crate's Rust
tests:
- Multibyte-position case. File with
/* é 🎉 */ wire a;as one line — "é" (1 UTF-16 unit, 2 UTF-8 bytes) and "🎉" (2 UTF-16 units/surrogate pair, 4 UTF-8 bytes) sit before the target identifier on the same line, so byte offset (21), UTF-16 offset (18), and char count (17) all disagree. SenttextDocument/renameat{line: 1, character: 18}(UTF-16, per the server's advertised"positionEncoding": "utf-16"). Got back aWorkspaceEditwith the edit range exactly{18, 19}on that line — the "a" and nothing else. Correct. - Refusal case. Same file, rename to
module(a keyword). Got back a JSON-RPC error,code: -32803(RequestFailed),message: "lucisv: \module` is a Verilog keyword."— matches the documented-32803` refusal convention exactly.
No issues found in the LSP-layer UTF-16 handling or the refusal wiring.
Summary
| Claim | Verdict |
|---|---|
cargo fmt / cargo clippy / cargo test --workspace clean |
Pass |
| Test counts (55 / 212 / 12) | Pass, confirmed |
| No unwrap/expect/panic/unsafe in library paths | Pass, confirmed |
Stale end labels (endmodule/endfunction/endtask/endclass/endpackage/named end) |
Confirmed, all affected, all warned-not-fixed — known/disclosed, lead's call |
| Collision safety "both directions" over the whole workspace | Fails — silent, only checked for files that were themselves edited |
| Macro-invocation-argument occurrences "warned about" | Fails — silently never renamed, never warned, contradicts README |
Everything else attempted (port/signal, genvar, sibling shadowing, bind, hierarchical tails, defparam, escaped names, tolerant parse, UTF-16 offsets, keyword refusal over real stdio) |
Pass |
No fixes applied — none of the findings were small/unambiguous; each needs a
design decision (collision-check scope, macro-argument policy, or the
vlog_semantic end-label handshake) that's the dev's/lead's call, not
QA's. No temporary probe files were left in the tree (added, exercised, then
removed).
2026-08-24 (round 2) — QA agent. Re-verification after the dev's rework of all three round-1 findings, per the lead's rulings.
Gates
cargo fmt --all -- --check— clean.cargo clippy --all-targets— clean, zero warnings, workspace-wide (forced re-check aftertouching every changed file, not a cache hit).cargo test --workspace— green, 1085 tests, 0 failures — matches the Work log's number exactly (was 1072 in round 1).vlog_refactoris now 64 (14 unit, 48 behavior intests/rename.rs, 2 corpus);vlog_semantic'ssemantics.rsgained new tests too (see the count note below).- Corpus rename re-timed in release: still 0.35 s over the 860-file
corpus,
Ok((6, 18))— matches the dev's claim, confirming thewatched_fileswhole-word scan added for the collision fix did not regress the thing round 1's corpus number was checking. - One small count discrepancy, not worth blocking on: the Work log/Handshakes
say "3 new tests" in
vlog_semantic;git diffshows 4 newfns incrates/vlog_semantic/tests/semantics.rs(an_end_label_is_a_use_of_the_declaration_it_closes,an_end_label_never_attaches_to_a_same_named_declaration_elsewhere,a_label_whose_name_is_already_bound_in_the_scope_records_nothing,a_mismatched_end_label_records_nothing_rather_than_guessing), and the test-run total (23, was 19) agrees with 4, not 3. Cosmetic — the count in prose just undercounts what's actually there. - All three gates: pass, claims confirmed (with the harmless count note above).
Round-1 finding #1 (priority) — end labels: verified fixed
Re-ran the exact round-1 reproductions (module/function/task/class/package/
named-begin) plus fork/join and interface, which round 1 didn't try:
module,function,task,class,package, namedbegin/end,fork : f/join : f, andinterface/endinterfaceall now rename their end label along with the declaration. Confirmed for every construct in the dev's list, not just the ones the milestone spec named.- The masked-corruption case (a different construct's end label happens to
spell the renamed name): built independently of the dev's own test —
module m; endmodule module other; endmodule : m(the: monotheris already-illegal SV, since it doesn't matchother) — renamingmleavesother'sendmodule : muntouched, with a warning naming it as "an end label lucisv could not attach to its declaration." Correct: it must never attach by name. -
- The "redeclaration binds no symbol" case: `wire m; initial begin : m ... end
- m
(a block label colliding with an existing net name — pre-existingvlog_semanticcollision-handling, not part of this round's diff). Renaming the wire correctly leaves the block's *end* label unedited and warned; nothing panicked or silently misattached. (The block's own *begin* label did move with the wire, because the pre-existing, untoucheddeclare_with_scope` collision logic treats it as a reference to the wire rather than a fresh declaration — that's inherited behavior from before M2, not a round-2 regression, and it's not this milestone's to fix.)
One dead end worth recording so it isn't retried: I initially wrote a
"nested same-named begin blocks" attack (begin : x inside another
begin : x) nested inside two initial statements — initial begin : x initial begin : x ... end : x end : x. That is not legal SystemVerilog (a
bare statement list cannot contain a second initial), and under that
malformed input the wrong end label moved. I re-ran it with the legal form (a
bare begin nested directly inside the outer block's statement list, no
second initial) and it was correct in both directions — renaming the
outer x moves only the outer begin/end, renaming the inner x moves
only the inner pair, confirmed with the AST (vlog_parser::parse_source_tolerant)
and the Semantics reference table directly: the inner end label
(Reference[0], span 67..68) resolves to SymbolId(2) (inner), the outer
end label (Reference[1], span 77..78) resolves to SymbolId(1) (outer) —
exactly the "binding not lookup" design working as claimed. So: nested
same-named begin blocks are fine; the earlier scare was my own invalid test
input, not a defect. Flagging it in case another QA pass reaches for the same
attack shape and hits the same red herring.
Verdict: fixed. Every construct renames its end label with the declaration; the two documented can't-attach cases (mismatched label, redeclaration) fall through cleanly to a warning with no corruption or misattachment in either.
Round-1 finding #2 — third-file collision: verified fixed
Re-ran the exact round-1 repro (sub.sv/child.sv/top.sv, renaming sub
to the name of a module top.sv already instantiates, where top.sv itself
never spells sub): now correctly refused —
renaming subtochildwould change whatchild means in top.sv; the rename was abandoned. Matches the dev's own new regression test
(a_collision_with_a_third_file_that_never_spells_the_old_name_is_refused).
New attack for round 2: the same 3-file shape, but sub.sv's only mention in
top.sv is inside an `ifdef NEVER_DEFINED-guarded arm (so the
"collision" instantiation of sub is never even active). Still refused, for
the right structural reason: watched_files is a whole-word text search,
which does not know or care about `ifdef, so top.sv is watched
regardless of whether the arm is compiled — the safe, over-inclusive
direction the README argues for. This is consistent, not a new bug: refusing
a rename that's arguably "fine" because the colliding text lives in a dead
`ifdef arm is the conservative failure mode, not a corruption risk.
Also checked the no-false-refusal mirror the dev added
(a_third_file_that_merely_mentions_the_new_name_in_a_comment_is_not_a_collision)
by reading it — it exercises exactly the "over-inclusion costs an analysis,
never a refusal" argument from the Verification story section.
Verdict: fixed, and the fix's stated soundness argument (whole-word
superset of "has a token spelling the name") holds up under an `ifdef
attack that specifically tries to exploit the gap between "spells the name"
and "the code path is actually reachable."
Round-1 finding #3 — macro-invocation arguments: verified fixed
Re-ran the round-1 repro ( `define BUMP(x) x = x + 1 /
`BUMP(a), renaming a): now warned —
"a appears in the arguments of the macro invocation BUMP at m.sv:4 and
was left unchanged; a macro invocation is one opaque token to lucisv, which
does not expand macros." Matches the dev's new test
(the_name_inside_a_macro_invocations_arguments_is_warned_about).
New attack for round 2: split the invocation across lines —
`BUMP(\n a\n );. Still warned, correctly, at the invocation's own
starting line (4). macro_use_warnings scans the whole opaque token's text
for the name as a whole word, so line-splitting inside the argument list
doesn't defeat it (the token itself spans all the lines; the warning names
where the invocation starts, which is reasonable — it's the only stable
anchor an opaque token has). Also spot-checked a_macro_invocation_in_an_ untouched_file_is_warned_about_too in the dev's own suite, which is exactly
the "warn even where nothing gets edited" half of the original finding.
Verdict: fixed.
Additional round-2 attacks — passed, no corruption found
- End label inside a
generate/forloop body (for (...) begin : g ... end : g): both the loop-body label and its end label rename correctly. (Note: this is a single source-level declaration —vlog_semanticdoes no elaboration, so there is no "genblk array" to worry about at this layer; the concern from the attack list doesn't apply to a static analyzer that never unrolls loops.) - Whole-word matching edge cases: target name
anext toa_b(no false match,a_buntouched); target nameainside a based literal8'ha(the literal's preceding bytehis alphanumeric, socontains_wordcorrectly does not treat it as a whole-word occurrence — confirmed the literal is byte-for-byte unchanged in the output). - Escaped identifier
\avs. plaina: renaming barealeft\acompletely untouched, no warning. Checked why:vlog_parser's lexer keeps the backslash in the token's text (lexer.rs:304-317), sovlog_semantictreats\aandaas two unrelated identifier spellings rather than the same identifier IEEE 1800 §5.6.2 says they denote. That is a pre-existingvlog_semantic/vlog_parsersimplification with no connection to this round's diff (nothing inbind.rs/resolve.rs's changes touches escaped identifiers), so I'm not filing it against M2 — noting it only so it's on record if the lead wants it filed againstvlog_semanticseparately. It is not a corruption risk either way: since the two are already unrelated symbols in this codebase's model, leaving\aalone is consistent with that model, not a violation of it. fork ... join : fandinterface ... endinterface : ifc: both rename correctly with their declarations (constructs the round-1 report didn't individually try).
Summary (round 2)
| Round-1 finding | Round-2 verdict |
|---|---|
| Stale end labels (priority finding) | Fixed — verified across every construct including fork/join and interface; masked-corruption case and the redeclaration edge case both still refuse cleanly |
| Third-file collision (silent) | Fixed — verified with the original repro and a new `ifdef-arm variant |
| Macro-invocation arguments (silent) | Fixed — verified with the original repro and a multi-line invocation variant |
| Gates (fmt/clippy/test) | Pass, 1085 tests, 0 failures, corpus rename still 0.35 s |
| New attacks this round (genblk-in-loop, nested same-name labels, whole-word edge cases, escaped identifiers, fork/join, interface) | Pass — no new corruption found; one pre-existing, out-of-scope vlog_semantic observation noted (escaped identifiers), one invalid-syntax red herring from my own probe recorded so it isn't retried |
No fixes applied this round — nothing found needed one. No probe files left
in the tree (crates/vlog_refactor/tests/qa_probe2.rs and the throwaway
/tmp AST/semantics probes were added, exercised, and removed).
Overall verdict: ship. All three round-1 findings are genuinely closed,
not just papered over — I attacked each fix's actual mechanism (whole-word
text search's blind spots, opaque-token scanning across line breaks, binding
vs. lookup under nesting) rather than re-running the original repro
unchanged, and the fixes held. The vlog_semantic change is scoped exactly
as narrow as the Handshakes section says (additive, one target variant, one
helper, no vlog_parser change), and the remaining warned-not-fixed
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 aftertouching 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:prepareRename238.29 ms → 179 ns;rename466.54 ms → 294.9 µs;willRenameFilesscope-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 becausecorpus/is not checked out here — pre-existing, unaffected by this diff, confirmed present inHEADbefore this round's changes.) - Real OpenTitan checkout (
/Users/guoliangchen/repo/opentitan@0098135264, 3979 files, matchingperformance.md's provenance), driven over real LSP/ stdio with a client pointed at this worktree's owntarget/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 repeatedrenames ofaesaveraged ~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.svtop-level instantiation sites); four repeatedprepareRenames on the same cursor averaged ~0.05 ms client-observed (the LSP round trip, not the dev's in-process 135 ns — consistent withperformance.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 tovlog_semanticthansub, 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
subvs. an unrelated wire also namedsubin 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-narrowwantedset 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 earlyreturn 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, incrates/lucisv_server/src/file_ops.rs: an include chaina.svh -> b.svhwith a third filec.sv -> a.svh(renamingb.svhnarrows toa.svhonly, correctly leavesc.svunedited since it never spellsb.svh,an_include_chain_narrows_to_the_direct_includer_of_the_moved_file), and a case-mismatched include spelling (`include "DEFS.svh"against a realdefs.svhon 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 classextends taken_basewheretaken_baseis declared nowhere; renaming a package totaken_baseis refused by both paths, and rung 6 pulls the file in via theTarget::Unitpath (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). Confirmedfiles_spellingdoes not pull the file in, and confirmed (viasame_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_spellingcorrectly excludes it (it is aReferenceFact::Local, which the function's ownmatcharm returnsfalsefor), and the rename succeeds with no edit to that file. This is also directly whatfiles_spelling_finds_the_uses_no_posting_can_be_keyed_byincrates/vlog_semantic/tests/workspace.rspins at the query's own level (quiet.sv's local wire namedabsent_pkgis excluded fromnamed("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 newa_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 renames 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 touching 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
and the watched-files superset argument is sound as written. The authorized
vlog_semantic end-label handshake came out smaller and better than
expected — Target::Declaration is binding-not-lookup, so a label can never
attach to the wrong construct, and the parser needed nothing. QA's round-1
HIGHs (third-file collision, macro-argument silence) are closed at the
mechanism level with regression tests from QA's own reproductions. Honest
limitations (hierarchical tails, defparam paths, mismatched end labels,
escaped-identifier equivalence) are documented, warned, and consistent with
the no-preprocessing boundary. Accepted; M2 checked off in the umbrella plan
and TODO.md §8. QA's escaped-identifier note (\a vs a, IEEE 1800
§5.6.2) is recorded as a pre-existing vlog_semantic simplification, not an
M2 defect.
2026-09-02 — amendment (docs/features/sva-bodies/README.md)
A fourth warning family: an assertion the SVA grammar could not structure.
Round §27 gave property/sequence bodies and concurrent-assertion
expressions a real AST, so the ordinary path now edits a signal named inside
one. What it cannot edit is a spec that did not fit the grammar and rewound to
the byte-exact verbatim capture — and silence about that is the same kind of
wrong as silence about a macro argument was, for the same reason: the region
still spells the old name.
Scope::sva_fallback_warnings runs over every in-scope file that spells
the name, not only the edited ones — macro_use_warnings' rule, for
macro_use_warnings' reason. Which byte ranges are assertions is a token scan
(sva_regions, assertion_paren, closing_paren), deliberately generous:
expect(word1[7:0]);, an ordinary task call, is claimed as a region. Which of
them actually fell back is not the scan's answer but the analysis's — a spec
the parser structured records a reference for every name in it, so a name
inside such a region is already covered and already edited, and a generous scan
therefore costs nothing. Both halves are pinned:
a_name_inside_an_assertion_the_grammar_could_not_structure_is_warned_about
and an_assertion_the_grammar_did_structure_is_not_warned_about.
docs/topo.md §2.9-18, restated after being half-closed. The engine has
always handled a file whose only relationship to the name is a macro
argument — a_file_whose_only_relationship_to_the_name_is_a_macro_argument_is_warned_about
pins it — provided that file reaches the engine. It is
Workspace::rename_sources that decides which files do, and fan_out_of
bounds the read set with the index's declaration, site and `define
tables; a macro argument is in none of the three. FileFacts::words /
WorkspaceIndex::files_mentioning does see it. The wiring is one rung and is
written out in the sva-bodies README's Handshakes, not applied: that rung
is unbounded in a way the other five are not — renaming a module's clk port
would pull in every file that writes the word clk, and rename_sources
reads every wanted path, which is the 2.5–3.0 s regression
prepare_rename_here exists to avoid. Accepting the cost, capping the extra
set, or answering it in the server from the index without reading anything are
three real options; the round has no evidence for choosing and does not.
§2.9-18 closed, 2026-09-02 (macro-word-census, TODO §29.2): the third
option. The lead ruled against the rung, for the reason above, and for a
second census instead — one the server can warn from without reading a byte.
vlog_semantic::words::harvest_raw harvests the words a file writes only
inside a macro invocation, a directive line or an attribute; they are stored
per file as FileFacts::macro_words (FACTS_FORMAT 16 → 17) and asked of
WorkspaceIndex::files_naming_in_macros, the twin of files_mentioning over
the shorter list. lucisv_server::rename::rename appends one sentence per file
that census names and rename_sources did not hand the engine:
`sig`also appears inside a macro invocation infar.svh, which this rename did not read; check it by hand — a macro argument cannot be edited.
No rung was added and Workspace gained no method: rename_sources already
returns the path set it built, so the server subtracts it directly — which also
excludes every open buffer, because that set contains them. The engine's own
macro_use_warnings is unchanged and still speaks for every file the engine
read, so a file that is a source is warned about exactly once, in the
engine's more precise words (pinned by the control test
a_macro_file_the_rename_does_read_is_warned_about_exactly_once). The pass
costs under 0.2 ms over all 3 979 OpenTitan files and reads nothing, so the
prepare_rename_here cost stays gone. Details and measurements:
docs/features/macro-word-census/README.md.