Files
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00
..

ansi-conversion

TODO §51 — the second of the §8 refactoring backlog to ship. One engine function, one code action, one command.

Goal

A Verilog-2001 header names its ports and the body declares them:

module m (a, b);
  input a;
  output [7:0] b;
  reg [7:0] b;
  ...
endmodule

Converting it to ANSI writes those declarations where a modern reader looks for them, and deletes them from the body:

module m (input a, output reg [7:0] b);
  ...
endmodule

That is the first thing an engineer does to a file inherited from 2001, and it is the one edit every other lucisv port refactoring is easier after: add_port writes one element into an ANSI list instead of an element and a body declaration, remove_port has one place to delete rather than two, and hover no longer has to point at a detail_span on another line to say what a port is. IEEE 1800 §23.2.2.2 says exactly how the two declarations merge, and this round implements that paragraph and nothing more.

The engine is vlog_refactor::convert_to_ansi, so Vim, VS Code and any future CLI get identical behaviour; lucisv_server maps the protocol and decides nothing. Whole-edit-or-nothing, through the ports engine's lexical splice and its "the file still parses" verifier: an Ok is safe to apply, an Err is a sentence for the user and no edits at all.

API as built

// crates/vlog_refactor/src/lib.rs
pub fn convert_to_ansi(files: &[(PathBuf, String)], file: &Path, offset: u32)
    -> Result<RefactorEdit, String>;

files, RefactorEdit, TextEdit and the Err(String)-is-a-sentence convention are M2's, unchanged. port_actions gained a fourth offer, so the code-action path needed no new entry point; port_action_modules gained one position (anywhere in a non-ANSI header) so that the offer reaches the cursor the plan asks for.

The edit's shape — insertions, never a rewrite of the list

Each header name keeps the bytes it already occupies. What an ANSI port adds is inserted around it: the direction, net, type, signing and packed dimensions just before the name, an unpacked dimension just after it, a moved comment past the comma. Two things follow, and both are why it is done this way rather than by replacing the list:

  • The header's own layout, commas and comments are untouched. A list written one port per line stays one port per line, at its own indentation; a comment the source wrote beside a port name stays beside it; the source's (/) placement is not lucisv's business. Refactored output is edited source, not reformatted source (umbrella Handshakes).
  • check::verify_splice's resolution check passes. That check requires every reference outside the edits to resolve to the same declaration at the same place, mapped through Shift::map. A non-ANSI port's Symbol is the header name (vlog_semantic models the body input a; as its detail_span, not as a second symbol — verified), so every body use of a anchors at the header. Replacing the header element would move that anchor and the verifier would refuse the whole refactoring, correctly. Inserting around the name leaves the anchor exactly where Shift::map predicts, and the identity holds.

The Plan's expected shape is therefore shape(text, module) unchanged: the module must declare the same ports, in the same order, after the edit as before. A conversion that reordered or lost a port cannot survive confirm.

The merge rule, exactly as implemented (IEEE 1800 §23.2.2.2)

merge.rs. For each header name, in header order:

what the body writes the ANSI port
input a; input a
input [7:0] a; input [7:0] a
input wire signed [7:0] a; input wire signed [7:0] a (already complete)
output b; + reg b; output reg b
output [7:0] b; + reg [7:0] b; output reg [7:0] b
output b; + reg [7:0] b; output reg [7:0] b (the one range written wins)
input a; + wire [1:0] a; input wire [1:0] a
output signed [7:0] b; + reg [7:0] b; output reg signed [7:0] b
output [7:0] mem [0:3]; + reg [7:0] mem [0:3]; output reg [7:0] mem [0:3]
input a, b; (one declaration, two ports) input a, input b

Read as rules:

  1. The port declaration (input/output/inout) always gives the direction, and there must be exactly one for each header name.
  2. If it also gives a net or data type (input wire a;, output reg b;) the port is completely declared; a second declaration of that name is an error under the LRM and lucisv refuses rather than merging it.
  3. Otherwise a net or variable declaration of the same name completes it. The merged port is the union: the net keyword from whichever half wrote one, the type name from whichever half wrote one, signed/unsigned from whichever wrote one, the packed range from whichever wrote one, the unpacked dimensions from whichever wrote one.
  4. Where both halves write the same thing, the two must agree — identical packed ranges, identical unpacked dimensions, one signing. Ranges are compared with the whitespace taken out, so [7 : 0] and [7:0] agree.
  5. The text is written in the order vlog_formatter's own ANSI port printer writes it (ansi_port_cells: direction, net, type, signing, packed, name, unpacked), so a converted header is what the formatter would have printed and formatting it moves nothing but whitespace.

Comments

Invariant 3 is the hardest part of this refactoring, because unlike every port refactoring before it this one deletes a construct a comment is attached to. Nothing is dropped and nothing is guessed at:

  • A comment written before an absorbed declaration goes on its own line above the ANSI port, at the port's indentation.
  • A comment written after one, on its line, goes at the end of the port's own line — where the source had it, relative to what it describes.
  • At most one comment may go beside a port, and only when nothing else is written there and the header wrote no comment of its own beside that port. Two comments landing on one line become one comment (a // runs to the end of the line and the lexer merges what follows into the same trailing comment), and a refactoring that joins two comments the source kept apart is not one lucisv will do. Everything that cannot sit beside the port goes above it instead.
  • A port list written on one line has no line above a port either. There a single-line block comment is written inline (/* first */ input a) and a // comment is a refusal with a sentence, because it would swallow the rest of the header.
  • A comment written inside a declaration (input /* which */ a;) is a refusal: lucisv will not decide where that one goes in an ANSI port. This is §50's precedent, applied to a declaration instead of a connection.
  • A declaration that declares several ports (input a, b; // both) hands its comments to the first of them and to no other: written onto both they would be duplicated, which is as much a corruption as dropping them. The verifier enforces this independently of the planner.

An attribute instance is not a comment and is not carried: (* keep *) on an absorbed declaration is a refusal (refusal 23), because where a (* ... *) belongs in an ANSI port list is a design question rather than a merge rule, and losing one changes what a synthesizer does.

check.rs changed for this, and the change is a tightening rather than a widening — see Handshakes and the work log.

The refusal list — exact

convert_to_ansi refuses when:

  1. The position is in no module — "there is no module declaration at this position."
  2. The file is outside the in-scope set — not_in_scope's existing sentence.
  3. The header is already ANSI — "m's header already declares its ports ANSI-style, so there is nothing to convert." This is also what makes the refactoring idempotent, and it is asserted as such.
  4. The module declares no ports (module m;, module m ();) — "m declares no ports, so there is nothing to convert."
  5. It is an interface or a program — "bus_if is an interface, not a module, and lucisv does not convert an interface's non-ANSI header in this round; it made no edits." Out of scope this round, said out loud.
  6. The header writes a port expression — "m's header writes a port expression (IEEE 1800 §23.2.2.1's .a({x,y}) or {x,y}), which has no ANSI spelling; lucisv made no edits." Recognised from the ListElem::Error a tolerant parse leaves in the list, and checked before the does-not-parse refusal so the user gets the specific sentence.
  7. The file carries a parse diagnostic — "m.sv does not parse (… at line N), so lucisv will not convert its ports to ANSI." Stricter than the verifier's "no new diagnostic" rule, for §50's reason: a header lucisv misread is a header whose ports it would declare twice.
  8. The header names a port twice — "m's header names a twice; lucisv will not guess which port that is."
  9. A header name has no body declaration — "m's header names c, but its body declares no direction for it; a port with no declaration is illegal, so lucisv made no edits."
  10. A body declaration names something the header does not — "m declares a direction for z, which its header does not name; lucisv made no edits."
  11. A port is declared twice — "m declares a direction for b twice; lucisv will not guess which one is the port." And the variable half: "m declares b twice outside its port declaration; …"
  12. A complete port declaration is declared again — "m gives b a type in its port declaration and declares it again; IEEE 1800 §23.2.2.2 makes that an error, so lucisv made no edits."
  13. The two halves disagree — packed ranges ("…with the packed range [7:0] … and [3:0] …; IEEE 1800 §23.2.2.2 asks for identical ones…"), unpacked dimensions (the same sentence), or signing ("…declares b signed … and unsigned …").
  14. A declaration is shared with a local — "m declares b, scratch in one declaration, of which only 1 is a port; lucisv cannot absorb one without the other, so split the declaration first." Deleting it would take the local with it.
  15. A declaration carries an initialiser ("…does not move an initialiser into a port list…"), a qualifier (var, const, automatic — "…does not move a qualifier into a port list…"), a net delay, or a type lucisv will not move (an anonymous enum/struct body, a parameterized #( ... ) reference, a virtual interface type).
  16. A header port is declared inside a generate region — "m declares b inside a generate region, where lucisv will not read a port's declaration; it made no edits."
  17. The port list carries compiler directives — §50's sentence, adapted: "m's port list carries compiler directives, so which ports it declares depends on the configuration; lucisv does not preprocess, so it made no edits."
  18. A declaration stands inside a conditional arm, or a directive is written among the declarations the conversion would delete — two sentences, both saying lucisv does not know what body it would leave behind.
  19. A comment is written inside an absorbed declaration — see Comments.
  20. A // comment would have to move into a one-line port list — "the comment // the clock on m's declaration of a would have to move into a port list written on one line, where it would swallow the rest of it; break m's port list across lines first, and lucisv made no edits."
  21. The header already writes a comment beside the port and one would have to join it — this one never surfaces as a sentence, because the planner puts the comment on its own line above the port instead.
  22. The module is declared twice in the workspace, or its indexed declaration is in another file — locate_module's existing sentences.
  23. An absorbed declaration carries an attribute instance — "(* keep *) on m's declaration of a would be dropped, and lucisv does not decide where an attribute belongs in an ANSI port list; move the attribute onto the port by hand, and it made no edits." Item.span covers the (* ... *), so the deletion would take it and only the comments are carried onto the port — and unlike a comment, a lost (* keep *) changes what a synthesizer does. Added by the rework; see the work log.
  24. Verification fails — the five checks in docs/features/refactor-ports/README.md, unchanged.

Every one of 1–20, 22 and 23 is pinned by a behaviour test in crates/vlog_refactor/tests/ansi.rs. Nothing is offered as a code action where the refactoring would be refused, so the lightbulb never appears to explain itself.

Assumptions

  • The module's own file is the only file edited. A non-ANSI header's ports keep their names and their order, so no instantiation anywhere changes — this refactoring has no fan-out at all, which is what makes the lazy code action exact rather than optimistic.
  • vlog_semantic models a non-ANSI port as one symbol, in the header. The body input a; is that symbol's detail_span, and a separate reg a; produces no second symbol. Verified against the analyzer before the edit shape was chosen, and it is the assumption the insertion-based edit rests on; if it ever changed, the resolution check would refuse every conversion rather than let a wrong one through.
  • lucisv does not preprocess, so a port list or a body split across `ifdef arms is refused rather than read straight through — §50's assumption, and stricter here for the same reason: this refactoring enumerates and deletes a whole set of declarations rather than appending one element.
  • lucisv is not a legality checker. inout merged with reg is illegal Verilog; lucisv writes what the two declarations said and lets the compiler say so. What it refuses is what it cannot express, not what a tool would reject.
  • A module name is unique in scope, and the index is the server's authority on where it is declared — the ports engine's assumptions, unchanged.

Handshakes

Consumed from vlog_parser (no change required): parse_source_tolerant and its ParseDiagnostic, tokenize and token::Comment (the comment scan), TextRange, and ast::{Module, PortList, NonAnsiPort, Item, ItemKind, PortDecl, DataDecl, Declarator, Dim, DataType, ListElem, GenBlock, GenElse}. PortList::NonAnsi holding a ListElem::Error for a port expression is what makes refusal 6 possible.

Consumed from vlog_semantic: nothing new. The conversion asks no semantic question of its own; the verifier asks all of them.

Changed inside vlog_refactor — two new files and four small edits to existing ones:

  • ports/ansi.rs (new, 464 lines, 362 of them code): the planner — locate, refuse, place the comments, write the insertions and the deletions.
  • ports/merge.rs (new, 325 lines, 254 of them code): IEEE 1800 §23.2.2.2, and nothing else.
  • ports/mod.rs: convert_to_ansi, conversion (the edit plus its port count), the fourth port_actions offer, and in_non_ansi_header — the one new position port_action_modules answers for.
  • ports/add.rs: Directive, Nesting, nesting_of and body_directives are pub(super) instead of private. Four visibility words; no call site changed, no behaviour changed.
  • ports/list.rs: comma_after is pub(super). One word.
  • check.rs: never_dropped replaces the "no deletion may cover a comment" rule. The one substantive change outside the new files; see the work log for why it is a tightening and for the attack tests that ship with it (CLAUDE.md invariant 4). It counts attribute instances alongside comments, so every refactoring — not only this one — is now refused if an edit of its deletes a (* ... *) without writing it back.

Promised to lucisv_server: everything the other port refactorings promise. convert_to_ansi does not panic, returns no partial edit, sorts and de-overlaps its edits, edits exactly one file, and produces no warnings at all. PortAction.title is user-facing text the server does not rewrite — and (N ports) is not a sites_phrase, so ports::counted leaves it alone (vlog_refactor::is_sites_phrase, §50's own guard, already answers false for it; no change was needed there).

Changed in lucisv_server (protocol layer only): CONVERT_TO_ANSI (lucisv.convertToAnsi) added to ports::commands() and to ports::execute. The dispatch arm, the capability advertisement and both code-action paths needed no change — commands are advertised from commands(), every workspace/executeCommand already routes through ports::execute, and code_actions/offers already fan out from port_actions. The VS Code extension needed nothing: server commands are discovered over LSP.

Requested of nobody. No change was needed in vlog_parser, vlog_semantic, vlog_formatter or lucisv_core.

The LSP surface

Surface What it says
Code action, kind refactor.rewrite.lucisv.ports "lucisv: convert ports to ANSI (2 ports)" — offered with the cursor anywhere in a non-ANSI module's header, lazily (offers → resolve, §37.1) or eagerly (code_actions), whichever the client supports.
lucisv.convertToAnsi [uri, Position] The same edit for a client with no lightbulb — a Vim user's keybinding.

The count is the ports the header declares, and it is exact in the offer already: the conversion reads and edits one file. It is written 1 port for one, which is why the plan's "(N ports)" is a shape rather than a literal.

Status / TODO

  • 51.1 convert_to_ansi engine (ports/ansi.rs + ports/merge.rs) and every refusal above
  • 51.1 the §23.2.2.2 merge table, one behaviour test per row
  • 51.1 comments moved, never dropped, never joined; check.rs's comment rule restated with its attack tests
  • 51.2 code action through both offer paths, with port_action_modules answering for a cursor anywhere in a non-ANSI header
  • 51.2 lucisv.convertToAnsi in commands() / execute
  • Tests: 54 behaviour tests in vlog_refactor/tests/ansi.rs, 14 attack tests in check.rs, 2 corpus tests, 3 in lucisv_server's ports.rs, 1 e2e session over the wire — the rework added 2 behaviour tests (the attribute refusal, both halves of the merge), 7 attack tests and one tests/ports.rs test for the placeholder whitelist's realistic flow
  • Rework (QA 2026-09-05): V-1 never_dropped is an exact equation with wrote <= gone; V-2 attributes refused by the conversion and counted by the verifier
  • Gates: cargo fmt per crate, clippy --all-targets clean, the workspace suite, the corpus gate, byte-identity vs 0.45.0, the VS Code smoke test
  • Corpus and OpenTitan census (see Acceptance — the count is zero, and that is the finding)
  • Deferred, deliberately: an interface's non-ANSI header (refusal 5). An interface body also holds modports that name the same ports, and moving a declaration into the header without reading them is not something to do unverified. Worth a backlog line of its own.
  • Deferred: the inverse refactoring (ANSI → non-ANSI), which nobody asked for and which the test fixture in tests/corpus.rs shows is three lines of text editing when it is ever wanted.
  • Deferred: absorbing a declaration that also declares a local (refusal 14) by splitting it first. A second refactoring, not this one.

Docs to apply at merge (lead)

README.md, docs/topo.md, docs/repository-analysis.md and docs/site/ are the lead's; the text for them is here rather than edited in place.

README.md — the refactoring list gains a row beside "expand .*":

| convert ports to ANSI | Rewrites a Verilog-2001 header (module m (a, b); plus input a; output [7:0] b;) as an ANSI one, merging each port declaration with the net or variable declaration that completes it (IEEE 1800 §23.2.2.2) and deleting both from the body. Code action anywhere in the header, or lucisv.convertToAnsi. |

docs/site/ (editors / language-tools page) — the same sentence in the code-action list: "convert ports to ANSI — a Verilog-2001 header rewritten the modern way, with each body declaration merged into the port it described and its comments carried along."

TODO.md §8 (the refactoring backlog): the non-ANSI→ANSI line is annotated "— shipped in 0.46.0, docs/features/ansi-conversion/README.md" (done in this branch), and the list gains a backlog entry: "convert an interface's non-ANSI header (needs the modports that name the same ports read first)."

docs/topo.md: no new edge. vlog_refactor ──▶ vlog_formatter (dev-dependency, tests only) already exists from §50 and is what the two new corpus tests use.

Work log

2026-09-05 — dev agent. Built ports/ansi.rs + ports/merge.rs, the fourth port_actions offer, the fifth command, and one change to check.rs. The decisions worth recording:

  • Insertions, not a replacement — and the verifier is why. The obvious edit is "replace the port list with the ANSI one". It cannot work, and the reason is worth writing down: a non-ANSI port's symbol lives in the header (the body declaration is only its detail_span), so every body reference to the port anchors at the header name. Replacing the element moves that anchor, Shift::map maps the old span onto the whole replacement, and verify_splice's resolution check refuses — correctly, since from its point of view a declaration moved. Inserting around the untouched name leaves every anchor where the map predicts. The happy consequence is that the header's layout and its own comments are never touched, and Plan::expected is the unchanged shape, which is the strongest thing the shape check could say.
  • check.rs's comment rule had to be restated, and it came out stricter. The old rule was "no deletion may cover a comment", which exists because a comment deleted from both sides of the piece comparison passes unnoticed. This refactoring must delete a declaration a comment is attached to and write that comment somewhere else, so the rule is now stated over the text: every comment the file had, it still has, matched by exact text and counted, so two identical comments must still be two. That is stronger than the rule it replaces — it catches a comment rewritten or duplicated by an edit, which the old rule never looked for — and it is one-directional, since a refactoring may legitimately write a comment (add_port's /* TODO: connect */, which the first draft of this rule wrongly refused and the existing suite caught within a minute). Seven masked-corruption attack tests ship with it (CLAUDE.md invariant 4): the honest conversion verifies; one of two identical comments dropped, a comment rewritten to the same length, a comment truncated, a comment written back in the wrong place, a comment written twice, and a deletion nothing writes back are all refused. The pair the budget-only and the search-only formulations each forgive is in there by name.
  • The duplication half of that rule caught a real bug in this very refactoring. A declaration that declares two ports (input a, b; // both) is absorbed by both of them, and the first draft carried its comment onto each — one comment in, two out. Nothing was dropped, so invariant 3 was intact; the piece comparison could not object because it checks the edits against themselves and the duplicate was in the edits. The planner now hands each declaration's comments to the first port that claims it, and comments_kept refuses a comment a deletion covers being written back a different number of times — so the same class of bug is a refusal rather than output, whoever writes it next. Found by review, pinned by a behaviour test and by the seventh attack test.
  • Two comments never become one. The lexer merges every comment following a token on one line into a single trailing comment, so writing // a beside a port that already carries // b produces one comment where the verifier expects two — a refusal, not corruption, but a pointless one. The planner therefore places at most one comment beside a port and puts the rest on their own lines above it. Everything about comment placement is a fallback chain ending in a refusal sentence, never a guess.
  • The merge is a table, and it is small. §23.2.2.2 fits in one function once "the port declaration is complete" is named. The only judgement call is what to refuse rather than express: an initialiser, a qualifier, a net delay, an anonymous aggregate or a parameterized type reference are all things lucisv could textually move into a port list and none of them is something it should decide to move for the user. Each is a sentence.
  • (N ports) is not a sites phrase, and §50 already made that safe. The server's counted rewrites an offered title's parenthesised tail from its index; is_sites_phrase — added in §50 after exactly this bug — answers false for "2 ports", so nothing had to change. The server test asserts the offered title character-for-character anyway.
  • The corpus and OpenTitan hold no non-ANSI headers at all. See Acceptance. This is the round's one real deviation from the plan, and it is a fact about the world rather than a gap in the work: the acceptance material had to be manufactured out of real ANSI headers instead, which turned out to be a better test than the plan's.

No unwrap/expect/panic! and no unsafe in any library path (test modules only). ansi.rs is 464 lines (362 of them code) with no function over 50; merge.rs 325 (254 code) with none over 65; every file touched stayed inside the size rule — ports/mod.rs 494, check.rs 1 068 of which 363 are its #[cfg(test)] module, lucisv_server/src/ports.rs 1 511 of which 1 053 are tests.

2026-09-05 — rework (dev agent), after QA's REWORK verdict. Two findings, both in the safety net rather than in the shipped output; neither reached a user, and both are closed by making the verifier stricter.

  • V-1 — the rule is now an equation, not an inequality. comments_kept bounded an untouched comment only from below ("before ⊆ after"), so two insertions could each write a third copy of a comment nothing deleted and the verifier said Ok. The rule is renamed never_dropped and restated as three equations over every piece text, with had/has the file's counts before and after, gone the old pieces a non-empty edit range covers and wrote the pieces lexed out of the edits' own inserted text: (1) has >= had — nothing is ever lost, which is invariant 3 and all the old rule had; (2) wrote <= gone unless the text is one the engine generates — a piece is written back where it was deleted and nowhere else; (3) has == had − gone + wrote — the applied text says exactly what the edits say.
  • Why (2) is wrote <= gone and not "may not write a text the file already has outside the edits". The latter was the shape the plan proposed, and it is both too weak and too strong. Too weak: it forgives the input a, b; // both bug, where the comment is deleted and is written twice — the attack test that already existed would have regressed. Too strong: it refuses an honest conversion of a file that writes // unused on an absorbed declaration and somewhere untouched, where wrote = gone = 1 and nothing is duplicated at all. wrote <= gone refuses QA's V-1 pair and the doubled comment, and refuses no honest edit in the suite.
  • The whitelist, choice (a), and the evidence for it. With (2) stated that way, any comment a planner invents needs an exemption, so generated() names the one text lucisv writes itself — /* TODO: connect */, from ports/add.rs and ports/propagate.rs. It is not a judgement call: stubbing generated() to false fails six tests, four of them pre-existing (a_connection_with_no_signal_of_that_name_is_left_as_a_todo, propagating_adds_only_the_connections_that_are_missing, propagating_needs_to_know_which_instance_when_a_statement_declares_several, a_port_refactoring_finds_an_interface_the_way_it_finds_a_module). The realistic flow the plan asked about is pinned by a new behaviour test, a_second_port_may_leave_a_second_todo_where_the_first_one_already_is: a module gains its ports one at a time, so the second add_port finds the first one's placeholder already in the file and writes another.
  • V-2 — attributes, in both halves. The conversion now refuses a declaration that carries an attribute instance (ports/ansi.rs::attributes_clear, refusal 23) rather than deleting it with the declaration; refuse rather than move, because where a (* ... *) belongs in an ANSI port list — and whether one may be split across the ports a multi-name declaration declares — is a design question, now a TODO §8 backlog line. The verifier treats an attribute as a never-dropped piece exactly as it treats a comment. pieces was never the hole: TokenKind::Attribute is a real token and Piece::Code has always carried it, so an attribute outside an edit was already pinned. The hole was the same one comments had — a piece inside a deleted range vanishes from both sides of the comparison — and it is closed by counting attributes in never_dropped beside comments, keyed by the noun the refusal uses (attributes are never dropped). That covers every refactoring, not only this one: any edit that deletes a (* ... *) without writing it back is now refused.
  • The attack tests (CLAUDE.md invariant 4). Seven new, on top of the seven §51 shipped. In check.rs: an_insertion_that_duplicates_an_untouched_comment_is_rejected (QA's V-1 pair, three copies out of one), a_generated_placeholder_may_be_written_where _the_file_already_has_one (the whitelist, accepted), an_application_that_grew_a_copy_the_edits_do_not_write_is_rejected (equation 3 — honest edits, corrupted application), a_comment_written_back_inside_a_string_or_another_comment_is_rejected (the lexer must see a comment, not a substring — both halves), a_deletion_that_swallows_an_attribute_is_rejected, an_edit_that_moves_an_attribute_verifies and an_edit_that_rewrote_an_attribute_is_rejected. In tests/ansi.rs, two behaviour tests pin refusal 23 on both halves of the merge.
  • No test without a guard it proves. QA's note that four of the seven existing attack tests were really caught by the piece-order comparison is answered one by one. Three of them — a_move_that_kept_only_one_of_two_identical_comments_is_rejected, a_move_that_dropped_a_comment_and_invented_another_is_rejected and a_move_that_shortened_a_comment_is_rejected, the last of which gained the assertion — now assert comments are never dropped, which only never_dropped says and which it says first, so neutering it breaks them. The fourth, a_move_that_left_the_comment_where_it_was_is_rejected, is honestly the piece comparison's: every count is equal on both sides, and its doc comment now says so and asserts that guard's own sentence. It is also the plan's "a comment deleted here and written back somewhere unrelated" — placement is bound to the edits, not to the totals. a_splice_that_also_dropped_a_comment_is_rejected gained the same treatment.
  • Nothing legitimate was refused. The stricter rule refuses no edit any of the five port refactorings produces: cargo test -p vlog_refactor is green with no change to any existing expectation, and the §51 corpus round trips and census are unchanged. check.rs measures 566 production lines (566 < 600), so the comment/attribute rule stays where it is; never_dropped is 63 lines (three passes and their three sentences) and nothing else grew.

Gates

All guarded (tools/guard.sh, 8 GB / 30 min defaults); no guard kill.

  • fmt: cargo fmt -p vlog_refactor, cargo fmt -p lucisv_server; cargo fmt --all -- --check clean.
  • clippy: cargo clippy --all-targets, 0 warnings, and no new #[allow] anywhere in the diff — the one this round nearly needed (clippy::type_complexity on a returned pair) was removed by naming the pair merge::Body instead.
  • suite: cargo test --workspace — 3 941 passed, 0 failed, 44 ignored across 51 test binaries (baseline 3 876, +65: 52 behaviour, 7 attack, 2 corpus, 3 server unit, 1 e2e).
  • corpus gate: tools/corpus_check.sh — 814/820 (804 would-reformat + 10 ok-unchanged), the same six known parse errors, 0 verification errors, 0 crashes.
  • formatter byte-identity: lucisv format --stdout over all corpus files, this build vs ~/.cache/lucisv-baselines/lucisv-0.45.0 — 860 total, 854 checked identical, 0 differing, 6 refused by both. git diff over vlog_formatter, vlog_parser and verify.rs is empty; this round touched neither.
  • vsix smoke: node editors/vscode/smoke.js target/release/lucisv-server — OK, 20 messages.
  • opentitan after the round: git -C ~/repo/opentitan status --porcelain shows only the three pre-existing modifications. Every run over it was read-only, and every edited copy went to the session scratchpad.

Re-run after the 2026-09-05 rework, same guard, no guard kill:

  • fmt: cargo fmt -p vlog_refactor; cargo fmt --all -- --check clean.
  • clippy: cargo clippy --all-targets, 0 warnings, no new #[allow].
  • suite: cargo test --workspace — 3 951 passed, 0 failed, 44 ignored across 51 test binaries (+10 on the round's own 3 941: 7 attack tests in check.rs, 2 behaviour tests in tests/ansi.rs, 1 in tests/ports.rs). Not one existing expectation changed to make the stricter rule pass — the five port refactorings' suites are green as written, so nothing legitimate is refused.
  • corpus gate: tools/corpus_check.sh — 814/820 (99.3 %), 10 ok-unchanged, the same six known parse errors, 0 verification errors, 0 crashes; the §51 corpus round trips and the non-ANSI census are unchanged.
  • file size: check.rs 566 production lines, under the 600 threshold, so the comment/attribute rule stayed in place rather than moving to check/comments.rs.

Acceptance

The corpus, and OpenTitan: zero non-ANSI headers

Deviation from the plan, stated plainly: there is nothing to convert in either tree. The plan asks for a census of PortList::NonAnsi modules across corpus/ and ten conversions under OpenTitan's hw/. Both counts are zero:

Tree Files PortList::NonAnsi modules
corpus/ (common_cells, ibex, opentitan, picorv32) 860 0
~/repo/opentitan (all of it) 3 979 0

Cross-checked against the AST census with a text grep for a body port declaration (^\s*(input|output|inout)[^;()]*;): 18 files in the corpus and 47 under OpenTitan match, and every one of them is an interface body, a function/task argument list, or an ANSI header whose output ...; line is inside a function — not a single non-ANSI module header. Even picorv32, the oldest code in the corpus, writes module picorv32 #(...) (input clk, ...).

The census is nevertheless shipped as a test (every_non_ansi_module_in_the_corpus_converts) rather than as a number: it converts every non-ANSI module it finds and asserts the properties on each, so it stays honest the day the corpus gains one.

Real RTL, made non-ANSI and converted back

Since the world's non-ANSI headers are not in these two trees, the acceptance material is manufactured out of real ANSI ones. A corpus module's ANSI port list is rewritten the Verilog-2001 way — each element replaced by its own name, each declaration moved into the body verbatim, layout otherwise untouched — and convert_to_ansi is asked to undo it. Three properties per module:

  • the result parses with no diagnostic, formats, and formatting it twice does not move it;
  • its module declares the same ports, in the same order, with the same direction, net type, data type, signing, packed range and unpacked dimensions as the module the tree actually ships;
  • and the file's comment count is unchanged.

Not byte-identity after formatting: the formatter preserves the author's column alignment in an ANSI port list, and a refactoring writes edited source rather than formatted source, so the hand-alignment the corpus wrote is not something the conversion undertakes to reproduce. (The first draft asserted byte-identity and this is what it found — recorded because it is the honest limit of the property.)

an_ansi_header_written_the_2001_way_converts_back_to_itself in crates/vlog_refactor/tests/corpus.rs does five of these in the shipped suite (~2.4 s each in debug, the index build over 860 files): binary_to_gray, boxcar, cc_onehot, cdc_2phase and cdc_2phase_clearable.

OpenTitan (read-only)

The same round trip over hw/ip, run from a throwaway probe (tests/zz_census.rs, never committed) with every edited copy written into the session scratchpad:

files under hw/ip 1 807
PortList::NonAnsi module headers 0
files holding a module the fixture can rewrite 291
round trips fully verified 290
refused by the conversion 0
failed 1 — kmac/pre_dv/kmac_reduced_tb/rtl/kmac_reduced_tb.sv

The one failure is not the conversion's: its parse, its port signature and its comment count are all correct, and only the formatter half of the check fails — because lucisv format already refuses that file as it ships (parse error: 53:3: expected expression (found ")") — a trailing comma in a #( ... ) parameter override list, kmac_reduced #( .EntropyWidth(...), )). Pre-existing, unrelated to this round, and worth a line of its own to the lead.

A single-file scope is used per conversion rather than the whole 1 807-file index, since this refactoring reads and edits exactly one file; the shipped corpus test uses the full 860-file scope and agrees.

git -C ~/repo/opentitan status --porcelain shows only the three pre-existing modifications (hw/ip/aes/dv/tb/tb.sv, hw/top_darjeeling/ip/ast/rtl/ast.sv, hw/top_earlgrey/ip/ast/rtl/ast.sv) before and after. Nothing was written into the repository.

QA log

2026-09-05 — QA agent. Verified against the plan (TODO §51) and this README, with git diff reads of every file the Handshakes section names, targeted attack tests against check.rs's new comments_kept (added as extra #[test] functions, run, then removed — the tree is unchanged apart from this log and the TODO checkbox), engine probes through convert_to_ansi/vlog_formatter::format_source (same in/out discipline), an independent re-derivation of the OpenTitan census on scratch copies, and the full gate battery, all through tools/guard.sh. No guard kill.

Priority 1 — the verifier (comments_kept, CLAUDE.md invariant 4)

Read comments_kept line by line (crates/vlog_refactor/src/check.rs:499-544). Its two halves: (a) every comment text in old must have a match in new (a plain multiset "before ⊆ after" by exact text, no position check), and (b) for a comment whose span was itself covered by a non-empty-range edit (moved), the count of its text in new must equal the count in old. Attack table (pair → verdict):

# Attack Verdict
1 Honest ANSI conversion output verifies (dev's own test, reconfirmed)
2 One of two identical comments dropped after a real conversion REJECTED — but via the piece-order comparison (would lose the comment), not via comments_kept's count check. Confirmed by neutering comments_kept (env-gated stub, scratch-only, reverted): the test's is_err() still held, only its specific message.contains("comments are never dropped") assertion broke, because the rejection now came from a different message. Not a gap — the outcome is still correctly refused — but it means this attack test does not actually exercise comments_kept in isolation the way its comment claims.
3 A dropped comment "replaced" by an invented one of different text, same position REJECTED, same caveat as #2 — piece-order comparison catches it (would write the comment ... where ... belongs), comments_kept is not the operative guard here either.
4 Comment shortened after a real conversion REJECTED — piece-order comparison again, not comments_kept.
5 Comment left in the body instead of moving to the header (position swapped, count intact) REJECTED — piece-order comparison (position is part of what the edits promise).
6 One declaration's comment written onto two ports, via edits that are internally self-consistent (the dev's own found bug, reproduced) REJECTED, and only by comments_kept — neutering it turns this into Ok(()). This is a true, load-bearing dependency.
7 A deletion that covers a comment; nothing writes it back REJECTED, and only by comments_kept (its first half). Neutering it turns this into Ok(()) — the exact case the old rule existed for.
8 (new, QA) A comment duplicated where the original is left completely untouched — no edit's range overlaps the original comment's span; a second, independent insertion elsewhere writes the identical text FORGIVEN — Ok(())`. See finding V-1 below.
9 (new, QA) Comment rewritten with different whitespace only (// the note → // the note) REJECTED (exact-text compare, no normalization).
10 (new, QA) Moved comment's text written nested inside a surviving block comment (/* keep */ → /* keep // moved */) rather than as its own piece REJECTED — the lexer sees one comment with new text, not two, so the original text reads as dropped.
11 (new, QA) Comment text that is a substring of another comment in the same file (// a vs. // a and more) Not confused — exact string equality, verified against an unedited file (comments_kept on identity input returns Ok).
12 (new, QA) A // written back mid-line with no following newline, swallowing the rest of the file into the comment REJECTED, and rejected by the token/piece comparison before the parse-diagnostic check is ever reached (pieces_match alone returns Err; verify_splice's "no new diagnostic" gate is redundant here, not the first line of defense).

Finding V-1 (HIGH). comments_kept's "written back exactly once" half (crates/vlog_refactor/src/check.rs:531-541) only runs if moved — i.e. only for a comment whose own span was overlapped by a non-empty-range edit. A comment whose span nothing deletes is checked only by the first half's "before ⊆ after" pass, which requires the text to still be present at least once but places no upper bound on how many times it may now appear. Reproduction (as a temporary test against pieces_match, removed after confirming):

before: "module m (\n  a,\n  b\n);\n  input a; // shared\n  output b;\nendmodule\n"
edits:  two pure insertions (empty ranges), each writing " // shared"
        after the header names `a` and `b`; nothing deletes or even
        overlaps the body's own "// shared".
after:  the same text 3 times (1 original + 2 inserted copies)
result: pieces_match(...) == Ok(())

This is not exploitable through today's ports/ansi.rs (its claimed vector already prevents attaching one declaration's comment to more than one port, and every comment it moves comes from a declaration it also deletes — see the work log's account of the bug it did catch), so it is not corrupting anything the shipping planner produces. But it is a real, untested hole in the invariant-4 safety net itself: a future planner bug that duplicates an untouched comment's exact text elsewhere in the file — rather than one it is actively deleting — passes verification silently. The rule's own doc comment says "a comment nothing deleted" may be freely written (true, and needed for add_port's /* TODO: connect */), but the implementation doesn't distinguish "genuinely new text" from "a second copy of an existing comment's exact text," which is the case that matters. Recommend: extend the equality check to every text present in before with count > 0, not only the ones whose span is moved — or, if that's judged too strict for legitimate cases, at minimum ship a masked-corruption attack test for this pair so the gap is a documented, accepted risk rather than an untested one.

Everything else Priority 1 asked for held. No finding for the "different owner, same text" case (e.g. two ports' comments swapped): that is a placement-correctness question the piece-order comparison settles only when it is fed a corrupted-after-the-fact text that disagrees with the literal edits; it is not a new gap introduced by comments_kept, and placement correctness is what tests/ansi.rs's behaviour tests (leading above, trailing beside, at-most-one-beside) already pin.

Priority 2 — the conversion

Read merge.rs and ansi.rs in full; every §23.2.2.2 table row and every one of the 20 pinned refusals has its own test in tests/ansi.rs (52 tests, confirmed present by name). The multi-name-declaration bug pin (a_comment_on_a_declaration_of_two_ports_is_written_once, input a, b; // both of them → one comment, on the first port only) is present and correct.

QA's own probes (temporary #[test]s in tests/ansi.rs, removed after running) against scenarios not named in the 52: attribute on the absorbed declaration, inout+tri, input signed/wire signed combination, escaped port name, a port named inputs (keyword-prefix collision), the three-declaration case (output b; reg b; wire b;), idempotency plus a formatter-fixpoint check on the converted output, and a body declaration also referenced inside an always block. Results:

Probe Result
inout b; tri [3:0] b; inout tri [3:0] b — correct
input signed a; wire signed a; input wire signed a — correct, signing not duplicated
Escaped port name \my$sig input \my$sig ; — correct
Port named inputs input inputs — correct, no substring false-positive
output b; reg b; wire b; refused ("declares b twice outside its port declaration") — correct
Re-running the converted output refused ("already declares its ports ANSI-style") — correct, idempotent
Formatting the converted output twice fixpoint — correct
reg b; also driven in an always block, header port b converts; the always block's reference to b still resolves to the ANSI port — correct
(* keep *) input a; the attribute is silently deleted — see finding V-2

Finding V-2 (HIGH). An attribute instance on an absorbed body declaration is silently dropped. Item.span is documented as including its (* ... *) attributes (crates/vlog_parser/src/ast/mod.rs:157,330), and ansi.rs's carried()/deletions() delete the item's whole span; only Meta::leading/Meta::trailing comments are read out and carried anywhere (ports::ansi::Carried) — attributes are never inspected. Nothing in merge.rs's refusal list (initialiser, qualifier, net delay, fancy type) mentions attributes either. Reproduction:

input:  "module m (a);\n  (* keep *) input a;\nendmodule\n"
output: Ok("module m (input a);\nendmodule\n")

(* keep *) (or dont_touch, mark_debug, any synthesis attribute) is gone, with no refusal and no warning. This is not covered by invariant 3 (comments only) and not visible to check.rs's resolution check (attributes aren't symbols or references), so nothing in the safety net catches it — this is planner-level silent data loss, not a verifier gap. Unlike a dropped comment this can change synthesis behaviour, which makes it arguably more serious than the comment-loss class invariant 3 was written for. Recommend either refusing a declaration that carries an attribute (same shape as the qualifier/initialiser refusals) or moving it into the ANSI port list, with a masked-corruption test either way. Not fixed by QA — this is a planner design decision, not a small unambiguous fix.

Priority 3 — round-trip acceptance

Ran the dev's own five corpus round trips and the census test under guard (cargo test -p vlog_refactor --test corpus -- --nocapture): both green, identical output to the dev's account — corpus non-ANSI module headers: 0, five round trips (binary_to_gray, boxcar, cc_onehot, cdc_2phase, cdc_2phase_clearable), 0 refused.

Independent OpenTitan re-derivation (own script, read-only, ~/repo/ opentitan/hw/ip, scratch-only edited copies, removed after running): 1780 files scanned (dev: 1807 — the gap is .sv/.v extension filtering, not a discrepancy in the conversion), 0 PortList::NonAnsi headers (matches), 291 files holding a module the round-trip fixture can rewrite (exact match with the dev's 291). Sampled 30 (every 9th of 291): 24 fully verified (parses, same port signature, same comment count, formats and converges), 0 failed, 6 refused — but the 6 refusals are an artifact of QA's own script using the whole 1780-file workspace as scope rather than the dev's single-file-per-conversion scope, which surfaces prim_* module-name collisions across prim_xilinx/ prim_generic/prim_asap7 variants that a single-file scope never sees. Not a defect in the conversion. Directly re-confirmed the dev's one opentitan failure: lucisv --check .../kmac_reduced_tb.sv reproduces parse error: 53:3: expected expression (found ")") byte-for-byte as claimed, pre-existing and unrelated to this round.

Five QA-constructed round trips, deliberately different from the dev's five and deliberately comment-bearing — worth calling out because the dev's own fixture (tests/corpus.rs::as_non_ansi) explicitly bails out of any ANSI port list containing a comment (if list.contains("//") || list.contains("/*") { return None; }), so neither the shipped 5-module round trip nor the OpenTitan census ever exercises a real comment-bearing RTL header — only the synthetic ones in tests/ansi.rs. QA wrote an independent generator that keeps a port's own leading/trailing comment and moves it into the fabricated body declaration, run against common_cells: sync.sv, max_counter.sv (10 ports, each with a trailing comment), fall_through_register.sv, lfsr.sv, lzc.sv (leading /// doc comments on every port). All 5/5 round-tripped: parse clean, same port signature, same comment count, format and converge, and each comment landed on its own line above the port it described exactly as the Comments section says. This is a genuine coverage gap closed by QA rather than a defect — noting it so the dev/lead can decide whether to fold a comment-bearing corpus fixture into the shipped suite.

Priority 4 — server wire

Read crates/lucisv_server/src/ports.rs and tests/e2e.rs diffs in full against the LSP surface table. CONVERT_TO_ANSI/lucisv.convertToAnsi is listed in commands(), dispatched in execute, and the e2e test (the_ansi_conversion_is_offered_resolved_and_commanded_over_the_wire) exercises all five wire behaviours the plan named: advertised command, offer with port count and no edit, command answer with the insertions/ deletions, a body-position refusal as RequestFailed with the engine's sentence, and codeAction/resolve returning the same edit. Read in_non_ansi_header (ports/mod.rs): returns false immediately for an PortList::Ansi module (confirmed: the offer cannot appear in an ANSI header), and treats any offset from the module keyword up to the first body item (leading comments included) as "header" for a non-ANSI module — correct given module_at already guarantees the offset is inside the module's own span before this function is reached. Confirmed is_sites_phrase("2 ports") is false by inspection (phrase != "no instantiation in scope" and does not start with "updates "), so ports::counted leaves the ANSI title untouched — matches the claim, no test needed beyond reading the two functions side by side.

Gates

All guarded, no guard kill:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --all-targets: 0 warnings (re-ran on the tree with every QA probe removed).
  • cargo test --workspace: 3941 passed, 0 failed, 44 ignored — exact match to the dev's reported baseline.
  • tools/corpus_check.sh: 814/820 parsed & formattable (99.3%), 10 ok-unchanged, 6 parse-error (the same six known ones), 0 verification-error, 0 crash.
  • Byte-identity: lucisv format --stdout over all 820 corpus files vs ~/.cache/lucisv-baselines/lucisv-0.45.0 — 814 checked, 0 differing, 6 refused by both.
  • node editors/vscode/smoke.js target/release/lucisv-server: OK, 20 messages.
  • OpenTitan: git -C ~/repo/opentitan status --porcelain showed only the three pre-existing modifications before and after every QA read.

Noted but out of scope for this log: CHANGELOG.md, editors/vscode/ CHANGELOG.md and editors/vscode/README.md acquired uncommitted 0.46.0 entries during this QA session that QA did not make — flagged to the lead as a fact, not investigated further (outside the file set this QA pass owns).

Verdict: REWORK — not because anything shipped is broken (nothing QA found reaches the shipping planner: V-1 is unreachable through today's ports/ansi.rs, and no corpus/OpenTitan file exercises V-2), but because CLAUDE.md invariant 4 requires masked-corruption attack tests for every widening of the verifier's forgiveness, and V-1 is a widening with none. Two items before this closes clean:

  1. V-1: either tighten comments_kept so an untouched comment's text cannot be silently duplicated, or add a masked-corruption attack test documenting the accepted gap (dev + lead's call which).
  2. V-2: a decision on attributes — refuse (safe, matches the existing qualifier/initialiser refusals) or carry them into the ANSI port list — with a test either way. Silent attribute loss should not ship unaddressed given it can change synthesis results, not just comments.

Everything else — the merge table, the 20 refusals, the wire surface, the corpus and OpenTitan acceptance, and all five gates — verified clean and is ready to merge as soon as V-1 and V-2 are resolved.

2026-09-05 — Re-attack of the rework

Re-attacked check::never_dropped (replacing comments_kept) and ports::ansi::attributes_clear against V-1 and V-2, per CLAUDE.md invariant 4: every widening of the verifier's forgiveness is guilty until proven innocent. All probes were temporary #[test] functions in check.rs's own test module and tests/ansi.rs (plus one neutering pass that stubbed never_dropped to Ok(())), run under tools/guard.sh, removed afterward. git diff/git status confirm check.rs and tests/ansi.rs carry only the dev's rework — no residue.

Attack table (pair → verdict; "gone"/"wrote"/"had"/"has" as the dev's equations name them):

# Attack (task's numbering) Verdict
1.1 Untouched comment // x, one insertion writes // x again (gone=0, wrote=1) REJECTED — "comments are never duplicated" (equation 2)
1.2 Whitelist text (/* TODO: connect */) written where the file had zero ACCEPTED
1.2b Whitelist text written twice by two insertions where the file had zero ACCEPTED — unbounded, by design (see finding QA-1 below)
1.3 Whitelist text deleted once (gone=1), written back twice, with no separator between the two copies REJECTED, but for a reason unrelated to the intended attack: the lexer merges the two adjacent, unseparated /* TODO: connect */ block comments into one trailing comment whose text is /* TODO: connect */ /* TODO: connect */ (a space inserted), which no longer equals the whitelisted key, so equation 1 (has >= had) fires as "would delete the comment". Confirmed by dumping tokenize()'s trailing field directly.
1.3b Same, but comma-separated the way add_port/propagate_ports actually write two placeholders (.a(/* TODO: connect */), .b(/* TODO: connect */), one deleted, both rewritten) ACCEPTED — this is the realistic shape, and it verifies. See finding QA-1.
2.1 Two // a comments, one deleted+rewritten in place (no-op), one untouched ACCEPTED
2.2 Applied text drops the untouched // a instead of the deleted one (has=1) REJECTED by never_dropped's equation 1 directly ("would delete the comment"), not by piece order — confirmed by calling never_dropped in isolation, which alone returns the same Err.
2.3 Applied text relocates the untouched // a to a distant, non-merging line while the edit's own // a stays exactly where the edit wrote it (counts stay balanced, has == had == 2) never_dropped alone: Ok(()) (it is text-only, no position). pieces_match as a whole: REJECTED — "would write the token outputwhere the comment// a belongs". The piece-order comparison is the guard for this one, confirmed by calling both separately. (First draft of this attack accidentally placed both copies on the same source line, which the lexer's comment-merging folded into one piece and made never_dropped itself reject — corrected to isolate the intended guard.)
3.1 Insertion text // x lands, in the full file, inside a string literal's content ($display("a// xb")) — never a real comment in after REJECTED — "comments are never duplicated ... without deleting it". This is wrote overcounting: it is computed by lexing edit.new_text alone (pieces(&edit.new_text), check.rs:407), context-free, so // x counts as a comment piece even though in context it is swallowed into a string token. The direction is safe (a false rejection, not a forgiven corruption) but it is a real context-free-lexing gap in wrote, worth a comment in the code — see finding QA-2.
3.2 Insertion of */ that closes an already-complete block comment early (/* note */ → insert */ before the real closer, giving /* note*/ */) REJECTED — by never_dropped equation 1 (the comment's text changed from /* note */ to /* note*/, a straight count/text mismatch), not by the "still parses" gate.
3.3 Insertion of a bare /* that opens an unterminated block comment swallowing the rest of the file REJECTED at the very first step of pieces_match — pieces(after) returns None because the corrupted file no longer lexes at all ("would no longer lex after an edit"). This fires before never_dropped and before verify_splice's "no new parse diagnostic" check ever runs — confirmed via both pieces_match alone and the full verify_splice path.
3.4 A brand-new (non-whitelisted, non-moved) comment inserted at EOF with no trailing newline REJECTED — "comments are never duplicated ... without deleting it". Not a bug: rule 2 refuses any comment insertion that is neither the exact generated whitelist text nor a piece moved out of a deletion, EOF or not. First draft of this test wrongly asserted the opposite; corrected.
3.5 // inserted immediately before an existing // existing on the same line REJECTED — the two merge into one trailing comment (// new // existing), which fails equation 1 against the original // existing text.
4.1 (* a *) (* b *) input a; — two attributes on one absorbed declaration REJECTED by attributes_clear (reports the first: `(* a *)`)
4.2 (* keep *) inside a // comment (// (* keep *) above a port) Not treated as an attribute — converts cleanly, the comment (not an attribute) moves onto the port intact. Confirmed the lexer's comment scan consumes the whole line before the attribute-detection branch is ever reached (lexer.rs's ////* dispatch precedes the (* ... *) dispatch).
4.3 "(* keep *)" as a string literal's content Not treated as an attribute — converts cleanly, string untouched.
4.4 (* keep *) on an always block, not on any absorbed port declaration, in the same module being converted Not refused — attributes_clear only inspects absorbed[].items, so a non-absorbed item's attribute is invisible to it and survives verbatim in the output, confirmed byte-for-byte.
4.5 An absorbed declaration and an unrelated attributed declaration crammed onto the same source line (input a; (* keep *) wire w;) — attacking list::whole_line's deletion-range widening Not swept — whole_line only widens a deletion to the full line when everything outside the item's own span on that line is whitespace; a real neighboring token blocks the widening, so the sibling's attribute survives untouched. Confirmed by direct conversion.
4.6 Verifier-level attribute checks (deleted-not-rewritten, moved, rewritten) Already exercised by the dev's own an_edit_that_moves_an_attribute_verifies / a_deletion_that_swallows_an_attribute_is_rejected / an_edit_that_rewrote_an_attribute_is_rejected; re-run and re-read, no changes needed.
5 Whitelist completeness: grep -rn '"[^"]*//[^"]*"|"[^"]*/\*[^"]*"' crates/vlog_refactor/src/ports/*.rs crates/vlog_refactor/src/rename/*.rs Exactly two call sites produce a comment-shaped string literal that is ever written into an edit (ports/add.rs:469, ports/propagate.rs:112), both /* TODO: connect */ verbatim — matching generated()'s only whitelisted text exactly. No second generated text found; rename/*.rs's only hits are test fixtures.
6 Neutering: stub never_dropped to Ok(()), run check.rs's full test module 14 tests fail, exactly the ones that claim never_dropped (or one of its three equations) as their guard: both attribute tests that assert dropping/rewriting, the "written onto two ports" bug pin, the "deletion nothing writes back" pins (old and new), the three "moved comment" attacks the work log says now assert never_dropped's sentence, the V-1 pair (dev's and this QA's own copy), the equation-3 pin, and this QA's own EOF/duplicate-comment probes. a_move_that_left_the_comment_where_it_was_is_rejected — the one test the work log says is honestly the piece-order comparison's — still passes stubbed, confirming the dev's own attribution. No test that should be piece-order-only broke, and no test that should be never_dropped-only survived.

Finding QA-1 (LOW, confirmed-by-design, not a defect). Equation 2 (wrote <= gone) is fully bypassed for generated() text, with no upper bound at all — has == had - gone + wrote is the only remaining check, and it balances for any wrote the edits themselves honestly claim. So a refactoring may legitimately write the whitelisted placeholder as many times as it wants, including duplicating one that was only deleted once (1.3b: gone=1, wrote=2, comma-separated, accepted). This matches the work log's own description ("may write however many times it needs") and is not exploitable for anything beyond a cosmetic extra /* TODO: connect */ — it never applies to a comment carrying user-authored information, only to the one generated string every call site writes identically. No test guards this specific "duplicate a deleted generated placeholder" shape today (the dev's own whitelist test only covers "written a second time where one already existed untouched", not "one deleted and two written back"); recommend one line added to check.rs's attack suite (qa_scratch_1c2 above is a ready template) so this accepted-and-intentional case has a permanent regression pin, but it is not a blocker — nothing about it is masked corruption.

Finding QA-2 (LOW, direction-safe). wrote is computed by lexing each edit's new_text in isolation (pieces(&edit.new_text), check.rs:407), not in the context of where it lands in the file. Text that is a comment (or attribute) when lexed alone but is actually absorbed into a string literal or another token in context is still counted as a "written comment/attribute", which can cause a spurious refusal of a hypothetical edit that legitimately writes //- or (* *)-shaped text inside a string. No shipped refactoring does this, so nothing is corrupted or forgiven — the effect is fail-closed, consistent with CLAUDE.md's "guilty until proven innocent" stance — but it is worth a one-line doc comment on written's computation noting the context-free lexing, so a future dev is not surprised by a refusal for an edit that never actually writes a comment. Not a blocker.

Everything else held. All 12 of the predecessor's Priority-1 attacks (re-run conceptually via the dev's own MOVED/SHARED/ATTRIBUTED fixtures) still verify or refuse exactly as before; V-1's exact reproduction pair now refuses (an_insertion_that_duplicates_an_untouched_comment_is_rejected, confirmed depends on never_dropped by the neutering pass); V-2's exact reproduction ((* keep *) input a;) now refuses via attributes_clear/refusal 23, confirmed on both halves of the merge and confirmed to not fire for a non-absorbed sibling. No new HIGH or MEDIUM finding.

Gates, all guarded, no guard kill:

  • cargo clippy --all-targets: 0 warnings.
  • tools/guard.sh -- cargo test -p vlog_refactor -p lucisv_server: all binaries green — 1499 (vlog_refactor lib) + 97 + 3 + 101 + 54 + 8 + 32 + 53
    • 70 (vlog_refactor integration suites) + 97 + 2 + 32 (lucisv_server) + doc tests, 0 failed across the board.
  • tools/guard.sh -- cargo test --workspace: 3951 passed, 0 failed, 44 ignored — exact match to the dev's reported baseline for this rework (the predecessor's pre-rework count plus the seven new check.rs attack tests and two new tests/ansi.rs behaviour tests this rework added).

Verdict: PASS. Both of the predecessor's blocking findings are closed with attack-tested fixes: V-1 by never_dropped's equation 2 (confirmed load-bearing by neutering), V-2 by attributes_clear plus never_dropped's attribute counting (confirmed load-bearing by neutering, confirmed scoped correctly — fires only on absorbed items, never on a sibling). Two LOW, non-blocking notes (QA-1, QA-2) are recorded above for the lead's awareness; neither is masked corruption and neither requires rework before merge.

Review

2026-09-05 — lead. Accepted after one rework; ships in 0.46.0 with §50. The engine is the right shape — insertions around each header name, so no reference anchor moves and the verifier's resolution check holds — and the §23.2.2.2 merge table is implemented row by row with a refusal for every disagreement. That no non-ANSI module exists in the corpus or in opentitan is a finding about the trees, not the feature; the round-trip acceptance (an ANSI header rewritten the 2001 way and converted back, same ports in the same order with the same types) is the honest substitute and the census test keeps it live. QA's two HIGHs were exactly the invariant-4 case: a widened verifier without the attack tests to prove it. The rework's rule — has ≥ had, wrote ≤ gone unless generated, has == had − gone + wrote, over comments and attribute instances alike — is stricter than the wording I gave (which would have forgiven the doubled-comment pin) and refuses nothing honest; the whitelist is the one placeholder two engines write, with a test for the two-ports-in-sequence flow; an attributed declaration is refused rather than moved, and the verifier now refuses any refactoring that drops an attribute. QA's re-attack (30-plus pairs, a neutering pass) found only two fail-closed LOWs. This is what invariant 4 is for.