549 lines
32 KiB
Markdown
549 lines
32 KiB
Markdown
# comments-round
|
||
|
||
## Goal
|
||
|
||
Close the comment-attachment gaps left open after `corpus-bugs`: a comment
|
||
written inside a list — a port list, a parameter list, a connection list, an
|
||
assignment pattern — was printed on the *wrong side of the separator*, so the
|
||
safety net refused the file (exit 2, nothing written). At corpus scale the
|
||
`format-fences` QA round measured that as 112 of 1 868 injection trials. The
|
||
same round found a second, quieter bug: two leading comments separated by one
|
||
blank line came out separated by *two*, because `Fmt::leading` emitted a
|
||
`HardLine` after each comment and then a `BlankLine` before the next. This
|
||
round fixes both, delivers the `Meta.trailing` span the `format-fences`
|
||
Handshake asked for, and takes as many of the documented expression refusals
|
||
as could be fixed by giving the AST somewhere to keep the comment. **Nothing
|
||
in `verify.rs` was touched**: every fix makes the comment survive *in place*,
|
||
none makes the net forgive its loss.
|
||
|
||
## Assumptions
|
||
|
||
- **A comment belongs on the side of the separator the author wrote it on.**
|
||
`a /* c */,` and `a, /* c */` are different token streams and mean different
|
||
things to a `verilator lint_off` pragma. Guessing one spelling for both is
|
||
what the net was rejecting; the parser now records which one it saw.
|
||
- **"No separator follows" is not the same as "a separator follows".** The
|
||
harvest that moves comments to `Meta::before_sep` is a no-op unless the
|
||
cursor is actually on the separator, so a comment after the *last* element
|
||
keeps landing in the bucket it always landed in (`trailing`, or the list's
|
||
`dangling`). That is what makes the existing suite show zero churn.
|
||
- **A line comment runs to end of line, so the separator that follows it goes
|
||
on the next one.** `a // why` ⏎ `,` is ugly and faithful; `a // why ,`
|
||
would delete the comma into the comment. Every emitter of `before_sep` goes
|
||
through `Fmt::inline_comments`, which already had this rule for binary and
|
||
ternary comments.
|
||
- **A merged trailing comment keeps the first comment's position.** Several
|
||
same-line trailing comments still merge into one text joined by a space, as
|
||
they always have; the merged `Comment` carries the first one's `line`/`col`
|
||
(what re-indenting a multi-line one needs) and a span running from the first
|
||
byte of the first to the last byte of the last.
|
||
- **Comments are compared by text in stream order**, so a fix is correct
|
||
exactly when the comment is printed lexically between the same two tokens it
|
||
sat between in the input. Every case in this round is checked that way by
|
||
`format_source` itself, not by eye.
|
||
- **Bracket interiors that print compactly still have no comment slot.**
|
||
`x[a : b]`, `[7:0]` and the two ends of `x[...]` are printed by
|
||
`Fmt::expr_compact` / `Fmt::dim` from nodes (`Dim`, `ExprKind::Range`,
|
||
`ExprKind::Index`) that carry no comments at all. Those stay refusals — see
|
||
Status / TODO.
|
||
|
||
## Handshakes
|
||
|
||
**Changed in `vlog_parser::ast` (consumed by `vlog_formatter::format`):**
|
||
|
||
| item | before | after |
|
||
|---|---|---|
|
||
| `Meta::trailing` | `Option<String>` | `Option<Comment>` — the fences Handshake. A same-line trailing comment now carries `line`/`col`/`span`, so a fence written there can be located in the source. Text callers read `.text`. |
|
||
| `Meta` | — | new `before_sep: Vec<Comment>`: comments written *between* the node and the separator that follows it. Empty when no separator follows, which is every node that is not a list element. |
|
||
| `ExprKind::Repl::inner` | `Vec<Expr>` | `Vec<ExprItem>`, so a replication's elements carry comments like a concatenation's. |
|
||
| `GateInstance::args` | `Vec<Expr>` | `Vec<ExprItem>`, same reason. |
|
||
| `Module::imports` | `Vec<Vec<String>>` | `Vec<HeaderImport>`; new `struct HeaderImport { meta, paths }`. A header import is not an `Item`, so it had nowhere to keep a comment. |
|
||
| `Connection` | — | new `close_comments: Vec<Comment>`: comments between the value and the connection's own `)` (`.data_i (x /* lint_off */)`). |
|
||
| `SensItem` | `{ sep, edge, expr }` | `+ meta: Meta` — comments around one event-list element, `before_sep` covering both separator spellings (`,` and `or`) and the closing `)`. |
|
||
| `GenElse::If` | `If(Meta, GenIf)` | `If(Meta, Box<GenIf>)` — `Meta` grew by one `Vec`, which re-tripped `clippy::large_enum_variant` on this enum. Purely a size fix; the variant was already reached through an `Option<Box<GenElse>>`, so root-to-leaf depth is unchanged. |
|
||
| `Parser::parse_expr_list` | `(first)` | `(first, close)` — the token that ends the list (`}`, `)`, or the `:` of a case-label list), so the comments before it can be harvested onto the last element instead of drifting past it. |
|
||
|
||
New parser helpers: `Parser::take_before_sep(meta, sep)` (a no-op unless the
|
||
cursor is on `sep`) and its unconditional half `Parser::take_before(meta)`,
|
||
for the event list, which separates with a `,` *or* with the `or` keyword.
|
||
|
||
New formatter helper: `Fmt::inline_comments_spaced` — `inline_comments` plus
|
||
the space (or line break, after a line comment) that keeps the next token off
|
||
the last comment.
|
||
|
||
**Delivered to `format-fences`:** the Handshake it filed — "a span on
|
||
`Meta.trailing`" — is now satisfied. That feature's README still documents
|
||
same-line fences as blocked on it; updating that README is the lead's call,
|
||
since it is another feature's document. `fence.rs` itself was not touched and
|
||
needs no change to keep working.
|
||
|
||
**Consumed from `verify.rs`: nothing new. No normalization was added,
|
||
broadened or weakened** (`git diff --quiet -- crates/vlog_formatter/src/verify.rs`
|
||
exits 0), so CLAUDE.md hard invariant #4 does not bind this round. Seven new
|
||
**rejection** tests were added to `tests/verification.rs` anyway — one per
|
||
shape fixed here — each asserting that the "corrupted" output a widened
|
||
normalization would have forgiven is still rejected. The comma case asserts
|
||
both directions.
|
||
|
||
**Recursion/chain budgets (`docs/features/recursion-limit/README.md`):**
|
||
unaffected. Nothing here recurses or builds a left-nested chain: `before_sep`
|
||
is a `Vec` beside two existing `Vec`s on `Meta`; `Repl::inner` and
|
||
`GateInstance::args` gain a wrapper struct at the same tree depth the elements
|
||
already sat at; `Box<GenIf>` adds an indirection inside a variant that was
|
||
already behind a `Box`, so the AST is one *pointer* deeper and zero *nodes*
|
||
deeper.
|
||
|
||
**`line_starts_inside_string` is still the one in-string-break definition** —
|
||
untouched, and nothing here parses comment or string text.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] **1. `Meta.trailing: Option<String>` → `Option<Comment>`** — the fences
|
||
Handshake. 14 formatter read sites migrated; several merge into one
|
||
`Comment` spanning the whole run.
|
||
- [x] **2. Comments between a list element and its separator** —
|
||
`Meta::before_sep`, harvested at every list kind: ANSI and non-ANSI port
|
||
lists, parameter ports, named and ordered connection lists, parameter
|
||
overrides, instance lists, declarators, enum members, struct members,
|
||
assignment patterns, concatenations, call arguments, `inside` sets,
|
||
case-label lists, function/task arguments, gate instances, event lists.
|
||
- [x] **2b. Comments before a list's closing bracket**, where the bucket was
|
||
missing: ordered connection lists, instantiation parameter overrides,
|
||
concatenations/`inside` sets/assignment patterns (`}`), case-label lists
|
||
(`:`), and a connection's own `)`.
|
||
- [x] **2c. `EnumType::dangling` was collected and never printed** — a
|
||
*dropped* comment (hard invariant #3), found while probing. Now printed
|
||
inside the braces via `delimited_dangling`.
|
||
- [x] **3. Double blank line between leading comments** —
|
||
`Fmt::leading_comments` emits the break before each comment instead of
|
||
after. Zero test churn; six corpus files became fixed points.
|
||
- [x] **4a. Comment inside a replication** (`{2{a /* c */, b}}`) — one of the
|
||
three documented survivors from `formatter-bug-fixes`.
|
||
- [x] **4b. Comment in a compactly-printed bracket expression**
|
||
(`x[a /* c */ + b]`) — the second documented survivor, for the
|
||
binary-operator position it was documented with.
|
||
- [x] **4c. Comment between a continuous assignment's value and its `;`**
|
||
(`assign y = a /* c */;`) — the third documented survivor.
|
||
- [x] **4d. Comment before the closing `}` of a concatenation** — the
|
||
`corpus-bugs` QA log's first non-blocking observation.
|
||
- [x] **4e. Comments between header imports** — the second one.
|
||
- [x] 26 new `.cases` entries, 7 rejection tests, 4 parser unit tests.
|
||
- [x] `cargo test --workspace` 229 passed (was 194 + the concurrent
|
||
define-table round's 25), clippy silent, fmt clean.
|
||
- [x] Corpus acceptance: 0 verification errors, 0 crashes, exit 0; six files
|
||
moved `would-reformat → ok-unchanged` and nothing else changed.
|
||
- [x] `TODO.md` §2: both comment items checked.
|
||
- [ ] **Not done, deliberately — bracket interiors.** `x[a /* c */]`,
|
||
`x[a /* c */ : b]` and `logic [7 /* c */ : 0]` still refuse. `Dim`,
|
||
`ExprKind::Range` and `ExprKind::Index` carry no comments and are
|
||
printed by `expr_compact`, which by contract introduces no line breaks;
|
||
giving them comment slots means deciding what a *broken* dimension looks
|
||
like, which is a layout design decision, not a plumbing one. 20 of the
|
||
22 remaining probe positions are this shape.
|
||
- [ ] **Not done — comment before a *procedural* statement's `;`**
|
||
(`initial y = a /* c */;`). The continuous-assignment twin is fixed
|
||
here because `cont_assign` emits its own `;` in one place; a statement's
|
||
`;` is emitted by roughly ten different `StmtKind` arms, so this needs a
|
||
`Stmt`-level restructure rather than one field.
|
||
- [ ] **Not done — comment before a construct's opening bracket**
|
||
(`sub u /* c */ (...)`, `if /* c */ (c)`, `typedef struct packed /* c */ {`).
|
||
Each head position is its own slot; nobody writes comments there, and
|
||
the aggressive probe harness over-samples them badly (see Measurements).
|
||
- [ ] **Not done — comment before `else`**, and the bare name lists
|
||
(`genvar i /* c */, j;`, `import a::* /* c */, b::t;`,
|
||
`defparam u.a = 1 /* c */, u.b = 2;`), which are `Vec<String>` /
|
||
`Vec<(Expr, Expr)>` with no `Meta` anywhere. All refusals, not
|
||
corruption.
|
||
|
||
## Measurements
|
||
|
||
Two injection harnesses, both run against the same pinned 820-file corpus with
|
||
the same seed on the pre-change binary (a `git worktree` at `HEAD` = 0ba29d4)
|
||
and on the working tree's binary. Scripts left in the session scratchpad
|
||
(`inject_lines.py`, `inject.py`, `probe/gaps.py`); none is checked in, since
|
||
none of the earlier rounds' harnesses were either.
|
||
|
||
**1. Line-position injection (the TODO's methodology).** One padding comment
|
||
inserted on its own line, at the surrounding indentation, at a random line of
|
||
a random parsable corpus file; 1 868 trials, seed 20260819.
|
||
|
||
| | before | after |
|
||
|---|---|---|
|
||
| usable trials | 1 861 | 1 861 |
|
||
| refused (exit 2, verification) | **42 (2.3%)** | **8 (0.4%)** |
|
||
|
||
This is the number to compare against the TODO's "112 of 1 868 (~6%)". It is
|
||
lower than that on *both* sides because the original harness injected an
|
||
`off`/`on` *pair* — two comments per trial — and its script was never checked
|
||
in; treat 2.3% as this harness's own baseline, measured here, not as a
|
||
reproduction of the 6%.
|
||
|
||
**2. Delimiter-position injection (deliberately adversarial).** A block
|
||
comment inserted immediately before or after a random `,` `(` `)` `{` `}` in
|
||
a corpus file — i.e. aimed squarely at the gaps, including ones no human
|
||
writes; 500 trials, seed 20260819.
|
||
|
||
| | before | after |
|
||
|---|---|---|
|
||
| usable trials | 460 | 460 |
|
||
| refused | **282 (61.3%)** | **164 (35.7%)** |
|
||
|
||
What is left is dominated by *head* positions rather than list gaps: 68 of the
|
||
remaining refusals are a comment written just before an opening `(` (between
|
||
an instance name and its connection list, between `if` and its condition),
|
||
which is the "not done" item above.
|
||
|
||
**3. Exhaustive gap probe.** 26 hand-written templates — one per list kind
|
||
plus the documented expression refusals — with a line comment and a block
|
||
comment inserted at each of four gap positions (after the opening bracket,
|
||
before the separator, after the separator, before the closing bracket): 186
|
||
inputs.
|
||
|
||
| | before | after |
|
||
|---|---|---|
|
||
| refused | **90** | **22** |
|
||
|
||
All 22 survivors are the two parked shapes: bracket interiors (20) and a
|
||
procedural statement's `;` (2).
|
||
|
||
## Corpus results
|
||
|
||
`./tools/corpus_check.sh corpus`, release build, corpus verified unmodified
|
||
afterwards.
|
||
|
||
```
|
||
outcome files share
|
||
-------------------- ----- -------
|
||
ok-unchanged 8 1.0% (was 2)
|
||
would-reformat 460 56.1% (was 466)
|
||
parse-error 352 42.9% (unchanged)
|
||
verification-error 0 0.0% (unchanged)
|
||
other-error 0 0.0%
|
||
crash 0 0.0%
|
||
-------------------- ----- -------
|
||
total 820 100.0%
|
||
```
|
||
|
||
Script exit status 0. The TSV was diffed **by path**, not by count: exactly
|
||
six files moved, all `would-reformat → ok-unchanged`, and no file changed to a
|
||
worse outcome. The six are `google_riscv-dv`'s `rv32*_instr.sv` /
|
||
`rv64b_instr.sv` family, and the reason is item 3 — each opens with a license
|
||
block comment, one blank line, then a banner comment, and the old code emitted
|
||
two blank lines between them. They are now fixed points on the first pass.
|
||
|
||
The md5 is therefore **not** byte-identical to the `format-fences` baseline:
|
||
`3fab114f4f00626b254259e9dafe0ed7` → `aa982463f68c1a3568c02a0fc5e0c455`. The
|
||
baseline was reproduced exactly from the `HEAD` worktree binary first
|
||
(`3fab114f...`, bit for bit), so the whole delta is attributable, and it is six
|
||
lines of the TSV. The corpus repos are unmodified afterwards
|
||
(`git status --porcelain` clean apart from the pre-existing untracked
|
||
`.lucisv-corpus-rev` stamps).
|
||
|
||
## Work log
|
||
|
||
### 2026-08-19 — dev agent
|
||
|
||
- Read `CLAUDE.md`, `README.md`, TODO.md §2, and the `format-fences`,
|
||
`formatter-bug-fixes` and `corpus-bugs` READMEs before touching code.
|
||
Baseline: `cargo test --workspace` 194 passed, clippy silent, fmt clean,
|
||
corpus TSV md5 `3fab114f4f00626b254259e9dafe0ed7` — reproduced from a
|
||
`git worktree` at `HEAD` so every later number has a real control.
|
||
- **Measured before designing.** Wrote the 26-template exhaustive gap probe
|
||
first (186 inputs, a comment in every gap of every list kind). The first run
|
||
reported 137/186 refusals, which was my harness's bug — a line comment
|
||
inserted with no newline after it swallows the rest of the line. Fixed, the
|
||
honest baseline is 90/186, and the shape of the failures made the whole
|
||
round obvious: **gap 1 — between an element and its comma — failed for 16
|
||
of 26 list kinds, and almost nothing else did.** One bug, sixteen call
|
||
sites.
|
||
- **Root cause.** Every list harvests `meta.trailing = self.take_trailing()`,
|
||
and `Fmt::delimited` prints `trailing` *after* the comma. A comment written
|
||
before the comma and one written after it both land in `pending_trailing`
|
||
and are indistinguishable by the time they are harvested. The information
|
||
simply was not in the AST — the same diagnosis `corpus-bugs` reached for the
|
||
event-list separator.
|
||
- **Chose one field on `Meta` over a field on each of fourteen list-element
|
||
structs.** `before_sep` reads oddly on a `Stmt` (nothing separates a
|
||
statement), but the alternative is fourteen near-identical fields and
|
||
fourteen near-identical printers. Documented as "empty for a node no
|
||
separator follows" and left at that.
|
||
- **Chose "harvest only when the separator is actually there" over "harvest
|
||
always".** `take_before_sep` returns immediately unless the cursor is on the
|
||
separator, because the comments before a *closing bracket* belong to the
|
||
list's `dangling` bucket, which already renders them correctly. Harvesting
|
||
unconditionally would have re-routed every last-element comment through a
|
||
new path and churned the snapshots for no gain. This is the single decision
|
||
that kept the existing 194-test suite byte-for-byte green.
|
||
- **`Meta.trailing: Option<String>` → `Option<Comment>`** (item 1) turned out
|
||
to be the smaller half of the work: `take_trailing` merges the run into the
|
||
first comment (text joined by a space, span extended to the last), and the
|
||
formatter's 14 read sites became `self.comment(tr)` instead of
|
||
`format!(" {tr}")`. That is a real behavior change for a *multi-line* block
|
||
comment in trailing position — it is now re-indented by the same
|
||
dedent-then-reindent rule every other comment gets — and it is the right one
|
||
(`raw_lines` is a fixed point by construction). No case or fixture moved.
|
||
- **Item 3 was three lines and I nearly got it wrong.** `HardLine` followed by
|
||
`BlankLine` is three newlines, so the fix is to emit the break *before* each
|
||
comment rather than after, with one `HardLine` at the end for the node
|
||
itself. Wrote it, expected snapshot churn, got none — and then found the
|
||
churn where it actually was: six corpus files. That is a better test than
|
||
any fixture I would have written.
|
||
- **`clippy::large_enum_variant` fired on `GenElse` the moment `Meta` grew.**
|
||
Boxed `GenIf` inside `GenElse::If`, which is the fix clippy suggests and the
|
||
one `corpus-bugs` already used twice for the same reason. Noted in
|
||
Handshakes that this is a pointer, not a tree level.
|
||
- **Found a dropped comment while probing.** `EnumType::dangling` is filled by
|
||
the parser and was never read by the formatter — `typedef enum {A, B\n// c\n}`
|
||
loses the comment. It is hard invariant #3, caught only because the net
|
||
refused the file. Fixed by switching the enum to `delimited_dangling`, and
|
||
pinned by its own rejection test.
|
||
- **Order of the item-4 work was driven by the harness, not by the list.**
|
||
After items 1–3 the delimiter harness's remaining refusals were dominated by
|
||
four shapes, and three of them were cheap: a connection's own `)`
|
||
(28 trials), an instantiation `#(...)`'s closing `)` (12), the enum `}` (2).
|
||
The fourth — a comment before an opening bracket — is 68 trials and a
|
||
grab-bag of unrelated head positions; parked with a reason rather than
|
||
half-done.
|
||
- **Replication and gate arguments were one change each** once
|
||
`parse_expr_list` took its closing token as a parameter: both were
|
||
`Vec<Expr>` printed with a fixed `", "` join, and both become `Vec<ExprItem>`
|
||
printed through the existing `expr_list`. The visible consequence is that a
|
||
very long replication can now break one-element-per-line like a
|
||
concatenation; nothing in the corpus or the suite has one.
|
||
- **`expr_compact` got the comment path it was missing**, for the
|
||
binary-operator position only. When a comment is present the tight spelling
|
||
(`[WIDTH-1:0]`) gives its spaces back — there is nowhere else to put the
|
||
comment — and a line comment breaks the line. Without a comment the output
|
||
is byte-identical to before, which is why no dimension in the suite moved.
|
||
- **`verify.rs` was not touched and did not need to be.** Every refusal fixed
|
||
here was the formatter printing a comment somewhere the input did not put
|
||
it; the net was right every time. Added seven rejection tests anyway, each
|
||
crafted as "what this fix would look like if it had been done in the safety
|
||
net instead", so a future shortcut fails loudly.
|
||
- Did not touch `tools/`, `corpus/`, `crates/lucisv/`, `verify.rs`, or the
|
||
concurrent define-table round's files (`crates/vlog_parser/src/defines.rs`,
|
||
its tests, its `lib.rs` line, its `TODO.md` §6 entry). Did not run
|
||
`git commit`/`git push`.
|
||
|
||
**Results:** `cargo test --workspace` **229 passed, 0 failed** (194 at the
|
||
start of the round plus 25 from the concurrent define-table round; this
|
||
round's own additions are +26 `.cases` entries inside `case_tables`, +7
|
||
`tests/verification.rs` rejection tests, +4 `parser.rs` unit tests).
|
||
`cargo clippy --workspace --all-targets` silent. `cargo fmt --all --check`
|
||
clean. Every one of the 299 `.cases` inputs and all three
|
||
`tests/fixtures/*.sv` files re-run through **three** passes independently of
|
||
`cargo test`: zero drift, zero refusals. Fences: `tests/fences.rs` 6/6 and the
|
||
25 `fences.cases` entries unchanged and green, so no fenced region moved.
|
||
|
||
Files touched: `crates/vlog_parser/src/{ast,parser}.rs`,
|
||
`crates/vlog_parser/tests/spans.rs` (two walker arms, for the
|
||
`Vec<Expr>` → `Vec<ExprItem>` changes),
|
||
`crates/vlog_formatter/src/format.rs`,
|
||
`crates/vlog_formatter/tests/cases/comments.cases`,
|
||
`crates/vlog_formatter/tests/verification.rs`, `TODO.md` (§2, two
|
||
checkboxes), this README.
|
||
|
||
## QA log
|
||
|
||
### 2026-08-19 — QA agent
|
||
|
||
Read `CLAUDE.md`, this README, and the diff (`vlog_parser::{token,lexer,
|
||
parser,ast}`, `vlog_formatter::format`, `comments.cases`, `verification.rs`,
|
||
parser units) before touching anything. Verdict: **all 7 claims pass**, no
|
||
blocking findings, no should-fix findings. Two informational notes below.
|
||
|
||
**Tooling (exact results).**
|
||
`cargo test --workspace`: **229 passed, 0 failed** (summed per-binary:
|
||
lucisv 40+21, vlog_formatter 8+1+4+6+2+39, vlog_parser 53+24+19+12 = 229).
|
||
`cargo clippy --workspace --all-targets`: silent. `cargo fmt --all --check`:
|
||
exit 0. `git diff --quiet -- crates/vlog_formatter/src/verify.rs`: exit 0
|
||
(byte-identical to HEAD). Case-table count: 299 exactly (`grep -c '^# '`
|
||
across all `.cases` files sums to 299: comments.cases alone went 51→77, a
|
||
+26 delta — the task brief's "50→76" is off by one on both ends but the
|
||
delta matches exactly).
|
||
|
||
**Claim 1 (Meta.trailing migration) — PASS.** Multi-line block comment as
|
||
trailing (`wire w; /* a\n b */`) re-indents and is stable across 3 passes.
|
||
Same construct inside a `// lucisv: off` fence stays byte-exact (diffed the
|
||
fenced lines directly against input) and still 3-pass stable — fences
|
||
correctly override the new re-indent behavior. Trailing runs
|
||
(block+block, block+line, block+block+line) reproduce the parser's
|
||
space-join merge (`take_trailing`, parser.rs:536-545) exactly, matching the
|
||
new unit tests `a_trailing_comment_carries_its_own_span` and
|
||
`several_trailing_comments_merge_into_one_spanning_run`
|
||
(parser.rs:3194-3219). EOF (with/without trailing newline, multi-line block
|
||
at true EOF) and CRLF all format cleanly and are 3-pass stable, no crash.
|
||
`GenElse::If`'s `Meta` param confirmed pre-existing via
|
||
`git diff -- crates/vlog_parser/src/parser.rs` (only `Box::new(...)` was
|
||
added around `self.parse_gen_if()?`; the `meta`/`_meta` handling itself is
|
||
untouched by this round) — the Handshakes table's "purely a size fix" claim
|
||
holds.
|
||
|
||
**Claim 2 (before_sep mechanics) — PASS.** Code at parser.rs:554-559 confirms
|
||
the early return unless `self.cur().is_sym(sep)`. Ran an independently
|
||
authored 22-position probe (not the dev's 26 templates) covering ports,
|
||
params, named connections, a connection's own `)`, enum members/closing
|
||
`}`, patterns, concat, call args, case labels, event lists, and a nested
|
||
comment inside an instance array (`sub u [3:0] (.a(x /*c*/), ...)`) — all 22
|
||
positions: comment present in a sane position, 3-pass byte-stable, no
|
||
crash. Also built one dense module combining all of the above at once (18
|
||
comment markers in one file): all 18 present in the output, 3-pass stable.
|
||
See scratchpad `probe20.py` and `dense.sv`.
|
||
|
||
**Claim 3 (`EnumType::dangling`) — PASS.** `format.rs:912`
|
||
(`self.delimited_dangling("{", items, &e.dangling, "}", false)`) confirmed
|
||
live: `typedef enum logic {A, B\n// that is all\n} e_t;` now prints the
|
||
comment inside the braces instead of dropping it.
|
||
|
||
**Claim 4 (double-blank fix) — PASS**, with one informational note (below).
|
||
`leading_comments` (format.rs:243-260) confirmed to push the break *before*
|
||
each comment and one trailing `HardLine` before the node, exactly as
|
||
described. Corpus six-file delta reproduced exactly (see Corpus below).
|
||
|
||
**Claim 5 (refusals fixed/parked) — PASS.** Every position claimed fixed
|
||
worked in the probe above. Every position claimed parked still refuses via
|
||
`verify.rs`, confirmed individually: `wire [7 /*c*/:0] w;` (dim interior),
|
||
`a[7 /*c*/:0]` (range interior), `initial y = a /*c*/;` (procedural `;`),
|
||
`sub u /*c*/ (.a(x));` and `if /*c*/ (a)` (before opening bracket),
|
||
`genvar i /*c*/, j;` (bare name list) — all exit 2, "verification failed".
|
||
**Comment before `else`**, specifically: a comment written as its own
|
||
leading line directly before the `else` keyword (procedural *or*
|
||
generate-level `else if`, i.e. through `GenElse::If`'s `meta` at
|
||
parser.rs:1671, whose value the formatter reads as `_meta` and never prints
|
||
at format.rs:1170) is refused by `verify.rs`, not silently dropped —
|
||
confirmed with a generate `else if` example
|
||
(`corpus`-style: `if (A) begin ... end\n// c\nelse if (B) ...`) and a
|
||
procedural twin. This matches the parked item. Two adjacent positions that
|
||
are *not* what's parked already work and are not new fixes: a same-line
|
||
comment between the then-branch's `;` and `else` lands as that statement's
|
||
trailing comment; a comment right after `else` before its statement lands
|
||
as that statement's leading comment. No refused position outside the
|
||
documented parked list was found.
|
||
|
||
**Claim 6 (metrics) — line-position PASS, delimiter-position
|
||
directionally-consistent but should-investigate.** Wrote a fresh,
|
||
independent line-position harness (scratchpad `inject_lines_qa.py`, not the
|
||
dev's unchecked-in script) and ran it at 300 usable trials, seed 20260819,
|
||
against both binaries: **HEAD 2.33% (7/300), current 0.33% (1/300)** — both
|
||
essentially reproduce the README's 2.3%/0.4%. Wrote an independent
|
||
delimiter-position harness (`inject_delim_qa.py`) and ran it at 100 and 300
|
||
usable trials, two seeds: **HEAD ≈ 42-43%, current ≈ 27-28%** — directionally
|
||
the same story (roughly halves), but the absolute numbers sit noticeably
|
||
below the README's 61.3%/35.7% on both sides of the comparison. Given the
|
||
README already documents that this style of ad hoc, not-checked-in harness
|
||
is sensitive to exactly which delimiters/positions get sampled (the same
|
||
caveat it gives for the TODO's old 6% figure), I read this as harness
|
||
variance rather than a wrong claim — the relative improvement and the
|
||
per-position probe results agree closely. Flagging per instructions since
|
||
it's a several-point absolute deviation; not blocking.
|
||
|
||
**Claim 7 (suite hygiene) — PASS**, see Tooling above.
|
||
`crates/vlog_formatter/tests/fences.rs`: 6/6.
|
||
`git diff --stat -- fence.rs tests/fences.rs tests/cases/fences.cases`:
|
||
empty (untouched). Two fence probes: a same-line `// lucisv: off` trailing
|
||
marker is still ignored (the interior line still gets its extra spaces
|
||
collapsed — no accidental activation despite `Meta.trailing` now carrying a
|
||
span); an own-line fence immediately after a line with an unrelated
|
||
trailing comment still preserves its region byte-exact. Independent 3-pass
|
||
check across all 299 `.cases` inputs + the 4 `tests/fixtures/*.sv` files:
|
||
zero mismatches against expected output, zero refusals, zero drift.
|
||
|
||
**Sabotage (both restored; `git diff --stat` identical before/after,
|
||
confirmed).**
|
||
1. `format.rs:912`: changed `&e.dangling` → `&[]`. Result: `case_tables`
|
||
fails exactly 1/299 — `comments.cases:804` ("a comment before the closing
|
||
brace of an enum member list stays inside it"), with the error
|
||
`token stream diverges ... input has comment "// that is all" ... output
|
||
has symbol "}"` — the exact corruption the fix prevents. Reverted;
|
||
suite green again.
|
||
2. `parser.rs:554-559` (`take_before_sep`): made it an unconditional no-op.
|
||
Result: `case_tables` fails exactly 17/299 — every "before comma"/"before
|
||
closing bracket" `.cases` entry across every list kind, starting with
|
||
`comments.cases:703` (the pinned list-gap case) — plus the parser unit
|
||
test `a_comment_before_a_list_comma_lands_in_before_sep`
|
||
(parser.rs:3174) fails directly. Reverted; suite green again (229/229,
|
||
clippy silent, fmt clean).
|
||
|
||
**Corpus (exact results).** `./tools/corpus_check.sh corpus -b
|
||
target/release/lucisv`: 8 ok-unchanged (1.0%), 460 would-reformat (56.1%),
|
||
352 parse-error (42.9%), 0 verification-error, 0 crash — TSV md5
|
||
**`aa982463f68c1a3568c02a0fc5e0c455`**, exact match. Built a `git worktree`
|
||
at `0ba29d4` (release), re-ran the same script: TSV md5
|
||
**`3fab114f4f00626b254259e9dafe0ed7`**, exact match to the reproduced
|
||
baseline. Path-level diff of the two TSVs: exactly 6 lines differ —
|
||
`corpus/ibex/vendor/google_riscv-dv/src/isa/{custom/rv32x,rv32b,rv32i,
|
||
rv32m,rv32v,rv64b}_instr.sv`, all `would-reformat → ok-unchanged`, nothing
|
||
else changed. The two files that were already `ok-unchanged` on both
|
||
binaries (`.../isa/custom/rv64x_instr.sv`, `.../isa/rv32fc_instr.sv`) are
|
||
byte-identical between the HEAD and current binaries, as required. Corpus
|
||
working trees clean afterwards (only the pre-existing untracked
|
||
`.lucisv-corpus-rev` stamps) in all four vendored repos.
|
||
|
||
**Findings.**
|
||
|
||
- *Blocking:* none. No comment loss that `verify_equivalence` misses; every
|
||
induced regression was caught as a refusal (exit 2), never silent
|
||
corruption; 0 verification-errors and 0 crashes across the full corpus.
|
||
- *Should-fix:* none. No refused position outside the documented parked
|
||
list, in either the dev's probe or this round's independent one.
|
||
- *Informational, no action needed:*
|
||
1. The blank-line fix's output footprint in the corpus is wider than the
|
||
six files that changed outcome category: of the 466 files that stay
|
||
`would-reformat` on both binaries, 178 also get a different target
|
||
output — checked line-by-line and every one of the 178 diffs is a
|
||
pure blank-line deletion, no other content change. This doesn't
|
||
contradict the README (which is specifically, and correctly, about
|
||
the TSV outcome-category delta) but is worth knowing if someone reads
|
||
"six files" as the full byte-level blast radius.
|
||
2. `docs/features/format-fences/README.md`'s Handshakes line requesting
|
||
"a span on `Meta.trailing`" is now stale (delivered), as this round's
|
||
README already notes. Per CLAUDE.md this is the lead's call, not
|
||
edited here. Confirmed same-line fences remain correctly inert either
|
||
way (see Claim 7).
|
||
3. Pre-existing, not introduced by this round:
|
||
`crates/vlog_formatter/src/format.rs:786` and `:978` each call
|
||
`.next().unwrap()` on an iterator, guarded by an `items.len() == 1`
|
||
check immediately above so it cannot panic in practice. Confirmed via
|
||
`git diff` that both lines are unchanged context, not new code. Out
|
||
of this round's scope; noting only because CLAUDE.md's "no `unwrap()`
|
||
in library code" rule technically covers them.
|
||
|
||
## Review
|
||
|
||
**2026-08-19 — lead. Verdict: accepted and committed as-is. The widest
|
||
diff of the project, and the one that retires "comments are the hard
|
||
part" as an open risk.**
|
||
|
||
What earned the acceptance:
|
||
|
||
1. **`take_before_sep` being a no-op unless the cursor is on the
|
||
separator** is the design insight of the round: it's why a change
|
||
touching every list kind left all 299 pre-existing cases
|
||
byte-identical. Correct-by-construction beats correct-by-testing,
|
||
and this had both (QA's 22-position independent probe, sabotage
|
||
confirming exactly 17 cases + 1 unit test depend on it).
|
||
2. **`EnumType::dangling`** — a comment parsed and never printed is an
|
||
invariant-#3 violation that predates every QA round and survived
|
||
them all because no case exercised it. Found by reading, fixed,
|
||
pinned. That's the standard.
|
||
3. **Metrics with a corrected baseline.** The dev re-measured the
|
||
unreproducible "6%" figure on a controlled HEAD worktree (2.3%),
|
||
reported its own improvement against that (0.4%), and flagged the
|
||
discrepancy instead of inheriting the flattering number. QA's
|
||
independent harness reproduced the line-position numbers almost
|
||
exactly; the delimiter-position deviation (dev 61→36, QA 42→28) is
|
||
methodology variance in the harder harness — both directionally
|
||
identical. TODO now carries the reproducible figures.
|
||
4. The corpus footprint being *honest* — md5 changed, six files moved
|
||
to fixed-point, nothing worse, verified by path against a rebuilt
|
||
HEAD baseline binary.
|
||
|
||
Dispositions: the parked positions (dim/range interiors, procedural
|
||
`;`, before-opening-bracket, before-`else`, bare name lists) stay
|
||
documented in Status/TODO here — they are refusals, not corruption,
|
||
and the residual 0.4%/22-of-186 rate says the remaining surface is
|
||
small. The two pre-existing `unwrap()`s QA noticed (format.rs:786,
|
||
:978) join the next housekeeping pass. The stale fences-README
|
||
handshake line is corrected by the lead in this commit. Same-line
|
||
fences remain inert by choice; the data to activate them now exists.
|