Files
lucisv/docs/features/formatter-bug-fixes/README.md
T

522 lines
31 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# formatter-bug-fixes
## Goal
Fix the five confirmed formatter/parser bugs the case-tables and safety-net
features found and parked. All five made `lucisv` refuse to write output (exit 2)
because the runtime safety net caught them as token loss, comment motion or
non-convergence — so every one of them was a file the formatter could not
format at all. Each fix lands with its parked `#SKIP` case turned into a live
regression case plus new cases around it.
The five:
1. Continuation lines of a multi-line block comment gain the current indent on
every pass (unbounded; breaks hard invariant #2, idempotency).
2. A comment inside an expression group is lifted out of the group instead of
forcing it to break, contrary to `README.md`'s "a comment inside a group
forces it to break".
3. Closing block labels (`end : x`, `join* : x`, `endfunction : x`,
`endtask : x`, `endpackage : x`, generate `end : x`) are dropped; only
`endmodule : x` survived.
4. A multi-instance declaration (`sub u0 (.a(x)), u1 (.a(y));`) always breaks
and under-indents the continuation instances.
5. `always @( /* c */ * )` loses the comment: `parse_sens_list` discarded
comments written inside the parens of an implicit sensitivity list.
## Assumptions
- The four `#SKIP` expected outputs are the spec. None of them was changed.
- **Comment re-indentation is relative to the comment's original opening
column.** A block comment's continuation lines are dedented by
`original_column - 1` (spaces/tabs only, never past the first non-blank
character) before the printer re-indents them. That is what makes the
transform a fixed point: the second pass sees the column the first pass
produced and dedents by exactly what it added. Continuation lines that
started *left* of the opening column cannot be preserved as-is — the printer
always prepends the current indent — so they land on the new indent; that is
stable from the second pass on and is pinned by a case.
- The same re-indent rule is applied to multi-line **directives**
(`` `define X \``) and **attributes**, which had the identical unbounded
drift for the identical reason. See the work log.
- Comments are compared by text in stream order by `verify.rs`, so a comment
kept on a construct must be printed lexically between the same two tokens it
sat between in the input. For the sensitivity list that means comments
written before the `*` are printed before it and comments after it are
printed after it, rather than all being pushed to one side.
- **`verify.rs` needed no new normalization and none was added.** With the
comment printed inside the parens (`@(/* c */ *)`), input and output produce
the same stream and the existing `@ ( * )` → `@ *` collapse simply does not
fire on either side (it requires the four symbols to be adjacent). The only
`verify.rs` edit is that comment items now report their *own* line/column
instead of the owning token's, which is a diagnostics improvement — positions
are never compared.
- `(*` immediately followed by anything but `)` lexes as an attribute
instance, so `@(*` may only be printed when `)` follows immediately. When
there is a comment after the star the formatter prints `@( * /* c */)` with
the star off the paren. This is a lexer constraint, not a style choice.
- A closing label is always printed in the `endmodule : m` spelling already
used for modules (space, colon, space). Labels are preserved verbatim; the
formatter never invents or removes one, and never checks that a closing
label matches its opening label (that is a linter's job).
- A comment inside an expression makes the enclosing `=` **hug**: the value
keeps its opening bracket on the assignment's line (`assign y = {`) instead
of moving to the next line. Without that, the parked case's expected output
is unreachable, because a hard line anywhere inside a group breaks every
enclosing group in this printer. The hug only applies when the value already
contains a forced break, so no case without comments changed.
## Handshakes
- **`vlog_parser::token::Comment` gained a position** (the handshake request
filed by the safety-net feature): `Comment { text, blank_before, line, col }`,
1-based, pointing at the opening `//` or `/*`. `col` is what makes bug 1
fixable. **Consumers**: anything constructing a `Comment` must supply the two
fields; in-tree that is only `lexer.rs`.
- **`vlog_parser::token::Token::trailing` is now `Option<Comment>`** instead of
`Option<String>`, so a trailing comment carries a position too (it can be
re-attached as a leading comment by the parser, and then it is re-indented).
`verify.rs` and one lexer unit test were the only readers.
- **`ast::RawText { text, col }`** is new and replaces the bare `String` in
`ItemKind::Directive`, `StmtKind::Directive` and `Meta::attrs`, for the same
re-indent reason.
- **AST: closing labels are new fields** — `ItemKind::Package.end_label`,
`GenBlock.end_label`, `FunctionDecl.end_label`, `TaskDecl.end_label`,
`StmtKind::Block.end_label`, `StmtKind::ForkJoin.end_label`.
- **AST: `SensList::Star` is now a struct variant** `Star { before, after }`
carrying the comments written inside `@( ... * ... )`.
- **AST: expression lists carry comments.** `ast::ExprItem { meta, expr }` is
new; `Expr::Concat`, `Expr::Call.args` and `Expr::Inside.ranges` hold
`Vec<ExprItem>` instead of `Vec<Expr>`, `PatternItem` gained a `meta`,
`Expr::Paren` became `Paren { inner, before, after }`, and `Expr::Binary`
gained `comments` (written between the left operand and the operator).
`Expr::Repl`'s inner list was left as `Vec<Expr>` — it is printed with a
fixed `", "` join rather than through `delimited`, so it has no break to
force; a comment inside a replication is still refused by the safety net.
- **`printer::contains_hard_line` is now `pub(crate)`** so `format.rs` can ask
"does this value break on its own?" for the `=` hug described above.
- `Meta.trailing` is still a bare `String`: several trailing comments merge
into one there, and it is printed verbatim on one line, so it needs no
position.
- Nothing outside `vlog_parser` / `vlog_formatter` was touched. `crates/lucisv`
and the top-level `README.md` (another agent's scope) are untouched;
`cargo fmt` was run and left those files byte-identical.
## Status / TODO
- [x] Bug 3 — closing block labels preserved (`end`, all `join` kinds,
`endfunction`, `endtask`, `endpackage`, generate `end`).
- [x] Bug 4 — multi-instance declarations stay on one line when they fit and
indent their continuation when they do not.
- [x] Bug 5 — comments inside `@( * )` are kept next to the `*`.
- [x] Bug 1 — block-comment continuation lines are dedented to their original
opening column before re-indenting; idempotent. Same fix applied to
multi-line directives and attributes.
- [x] Bug 2 — a comment inside an expression forces its group to break, for
concatenations, call arguments, `inside` sets, assignment patterns,
parenthesized expressions and between the operands of a binary chain.
- [x] `#SKIP` markers removed from all four parked cases; 17 new cases added
across `comments`, `statements`, `instantiation`, `functions_tasks`,
`module_headers` and `generate`.
- [x] `cargo test --workspace` green, `cargo clippy --all-targets` silent
(including the four pre-existing warnings), `cargo fmt --check` clean.
- [ ] Not fixed, still refused by the safety net (documented, not hacked
around): a comment inside a **replication** (`{2{a, // c`), a comment
inside a compactly-printed bracket expression (`x[a /* c */ + b]`, where
`expr_compact` has no line to break), and a comment between a value and
the `;` that follows it (`assign y = a /* c */ ;`), which the statement
harvests and re-prints after the `;`. All three are pre-existing and
each needs its own small design decision.
- [x] TODO.md: nothing to check off — none of these bugs had a backlog item.
The "re-enable the four `#SKIP` cases" item lives in the case-tables
README's TODO and is now satisfied.
## Work log
### 2026-08-18 — dev agent
**Bug 3 (closing block labels) — fixed.** The parser was parsing `: name`
after every closing keyword and throwing the identifier away
(`parse_package`, `parse_gen_block`, `parse_tf_body`, and the `begin` / `fork`
arms of `parse_keyword_stmt`). Added `Parser::parse_end_label` — one helper,
used by all six sites plus `parse_module`, which already kept its label by
hand — and an `end_label` field on the six nodes. The formatter grew
`Fmt::closing(kw, label)`, exactly the `endmodule : m` rendering generalized,
and now uses it for `endmodule` too, so all seven closing keywords share one
spelling. Un-skipped the parked `end : main` case and added five more: all
three `join` kinds, nested `begin : inner`, `endfunction` + `endtask`,
`endpackage`, and a generate-block `end : lane`.
**Bug 4 (multi-instance declarations) — fixed.** `Fmt::instantiation` emitted
`text(",")` + `HardLine` between instances unconditionally, which both forced
the break and left the continuation at the head's indent. Rewrote it in the
shape `declarators` already uses: a single instance is emitted directly (no
extra indent level, so its connection list still lines up under itself — the
first attempt indented every instantiation's broken connection list by two
extra columns and three existing cases caught it), several instances go into
`group(indent(...))` with `Doc::Line` separators, so they fit on one line when
they can and indent one level when they cannot. Per-instance leading and
trailing comments are emitted in the multi-instance path, which also makes a
comment between two instances break the list. Three cases: fits, does not fit,
and comment-forces-break.
**Bug 5 (comments in an implicit sensitivity list) — fixed.**
`parse_sens_list` now recognizes `@( * )` before consuming the `(` and keeps
the comments the lexer attached around the star, in two buckets (`before`,
`after`) so their order relative to the `*` survives the round trip. Two new
parser helpers, `take_leading_here` / `take_trailing_here`, read the comments
straight off the token instead of going through `pending_leading` /
`pending_trailing`; that matters because the pending queues can hold older
comments from before the `@`, and stealing one of those would move it across a
token and trip the equivalence check. The formatter prints
`@(/* c */ *)` / `@( * /* c */)`; a line comment inside gets a hard line so it
cannot swallow the `*)`. **No `verify.rs` change was needed** — see
Assumptions. One lexer constraint surfaced while testing: `@(*` followed by a
space lexes as an attribute instance, so the `after` spelling keeps a space
after the paren.
**Bug 1 (multi-line comment re-indent) — fixed**, using the handshake the
safety-net agent asked for: `token::Comment` now carries `line`/`col`, filled
in by the lexer (which already had both for every raw token). `Fmt::raw_text`
became `raw_lines(text, col)`: continuation lines are dedented by `col - 1`
before the printer prepends the current indent, so pass two removes exactly
what pass one added and the text is a fixed point. `Token::trailing` had to
become `Option<Comment>` for the same reason — an unharvested trailing comment
is re-attached as a *leading* comment by `take_meta`, and from that moment it
goes through the re-indenting path.
While testing this I found the **same unbounded drift on multi-line
directives** (`` `define FOO(a) \`` continued onto the next line, inside a
module) and on multi-line attributes: identical root cause, identical
refusal from the convergence check. Since the fix was one field away I did it
rather than leave a known non-convergent input behind: `ast::RawText` pairs the
verbatim text with its starting column, and `Directive` / `Meta::attrs` use it.
This is beyond the five bugs as briefed; it is called out here and covered by a
case (`a continued \`define inside a module keeps its continuation indent`).
**Bug 2 (comment inside an expression group) — fixed**, in three steps.
1. *List-shaped groups.* `ast::ExprItem { meta, expr }` gives concatenation
elements, call arguments and `inside` set members the same `Meta` that port
and connection lists already had, and `PatternItem` gained one; the parser
harvests around the commas exactly the way `parse_declarators` does, and the
formatter feeds them to the existing `delimited`, which already emits a hard
line per comment and therefore already forces the break. So the fix was
plumbing, not new layout code.
2. *Parenthesized expressions.* `Expr::Paren` carries the comments written
just inside its parens (`( // why` … / … `// sum )`), mirroring
`SensList::Star`.
3. *Between operands.* `Expr::Binary` carries the comments written between the
left operand and the operator. When present, `binary_chain` puts the
comment last on its line and starts the next line with the operator
(`a // hi` ⏎ `+ b`) instead of the usual trailing-operator layout, which
would produce `a // hi +` — i.e. an operator swallowed by a comment.
The parked case then still failed, on layout: `assign y =` broke before the
`{` because a hard line anywhere inside a group breaks every enclosing group in
this printer. Rather than redesign the IR, added `Fmt::assign_rhs`: if the
right-hand side already contains a forced break, `= {` stays on the head line
(the same shape as a broken port list keeping `module m (` on its line);
otherwise the previous `Line`-and-indent behavior is unchanged. This is why
`printer::contains_hard_line` became `pub(crate)`. Un-skipped the parked
concatenation case and added five more (call args, assignment pattern,
paren-adjacent, between binary operands, comment before an operator in a
chain).
**Pre-existing clippy warnings.** All four are in files this change already
touches, and all four fixes were trivial, so they are gone:
`printer.rs`'s `manual_repeat_n` (`repeat_n`), `parser.rs`'s two
`if_same_then_else` (the net-or-`var` test in `parse_ansi_port` /
`parse_port_decl`, merged into one condition), and `format.rs`'s dead
`ListItem::blank_before` (removed — `delimited` documents that blank lines
inside bracketed lists are dropped deliberately, so the field had no future
reader). `cargo clippy --all-targets` is now completely silent.
**Verification.** Beyond the suite: a hand-written stress file combining all
five constructs (labeled package/function/task/fork, a starred sensitivity
list with a comment, a commented concatenation, a multi-instance declaration,
an indented banner comment) formats cleanly, and `lucisv` on its own output is
byte-identical. Every bug's original repro from the two feature READMEs was
re-run through the built CLI and now exits 0.
## QA log
### 2026-08-19 — QA agent
**Scope**: ran the full tool chain, read every line of the diff (`token.rs`,
`lexer.rs`, `parser.rs`, `ast.rs`, `format.rs`, `printer.rs`, `verify.rs`)
against the seven claims in the assignment, then went well beyond the
committed cases with a hand-built stress corpus (15 constructive `.sv` files
plus the 3 known-refusal reproductions) run through a 3-pass fixed-point
script, and a second script that re-ran every one of the 200 committed cases
and all 4 `tests/fixtures/*.sv` files through 3 passes independently of
`cargo test` (which only checks 2). No regression found. Full corpus and
scripts left at `/private/tmp/claude-501/-Users-guoliangchen-repo-verilogrustformatter/9ecac3b9-8a0e-4065-85de-23cc2a396bad/scratchpad/{stress,stress3.py,regress3.py}` for reference (outside the repo).
**Tool chain** (workspace root):
- `cargo test --workspace`: **70/70 pass**, 0 failed (18 `lucisv` unit + 12
`cli.rs` + 3 `vlog_formatter` unit + 1 `cases.rs` (covering all 200 cases
internally) + 2 `fixtures.rs` + 19 `verification.rs` + 15 `vlog_parser`
unit). Confirmed 200 cases / 0 `#SKIP` two ways: `grep -c '^====' ` per
file (14+32+18+26+16+13+20+18+28+15 = 200) and `grep -rn '#SKIP'` across
`tests/cases/*.cases` (zero hits).
- `cargo clippy --all-targets`: silent — `Finished` with no warning lines at
all. Grepped the diff for `#[allow]`: none added anywhere. Independently
confirmed the four previously-documented warnings are actually gone at
their old sites: `printer.rs:91` now uses `repeat_n` (not
`repeat().take()`), `parser.rs`'s `parse_ansi_port` (line 599-607) and
`parse_port_decl` (line 741-749) both use the merged `net = { ... }` block
instead of the old duplicated if/else-if, and `ListItem.blank_before` is
gone from `format.rs` entirely (`grep` for the field name: no hits).
- `cargo fmt --check`: exit 0, no output.
**Claim verdicts**
1. **Block-comment continuation drift — PASS.** Confirmed via 3 independent
probes beyond `comments.cases`: a column-0 banner
(`stress/01_comment_col0.sv`), a comment nested four `begin` levels deep
(`02_comment_deep_nested.sv`), a comment inside a `case` item
(`03_comment_in_case_item.sv`), a tab-indented comment
(`05_tab_indented_comment.sv`), and — the sharpest probe —
`04_ragged_continuation.sv`, a comment whose five continuation lines have
five *different* indents (7, 3, 0, 8, 5 spaces), one of them starting
left of the opening column. All five are stable across 3 passes. Hand
-verified the ragged case's exact output against the dedent-then-reindent
formula in the Assumptions (dedent by `col-1`, reindent by current
indent = 2): input indents 7/3/0/8/5 → output indents 7/3/2/8/5, i.e.
every line kept its *relative* raggedness except the one that started
left of the opening column, which landed on the new indent exactly as
the Assumptions predict. This is a materially stronger check than what's
in `comments.cases` (whose ragged-indent case only has two continuation
lines, both indented the same way).
- **Tab/column consistency, audited as requested**: `lexer.rs`'s
`RawLexer::bump` (line 72-82) increments `col` by exactly 1 per byte
regardless of character, i.e. a tab counts as 1 column, not 8. The
dedent side, `format.rs::strip_blanks` (line 1607-1616), strips up to
`n` *characters* (space-or-tab, one per iteration), also byte-count
based. The two are consistently unit-for-unit. Verified concretely: a
comment opening after one leading tab (`col` = 2, so dedent = 1) whose
continuation lines are themselves tab-indented dedents by exactly one
leading tab per line, confirmed by hand-tracing
`05_tab_indented_comment.sv`'s output.
2. **Comment inside expression groups forces a break — PASS.** Built
`stress/07_expr_comments_everywhere.sv` stacking every position at once:
nested concat-inside-concat, nested call-inside-call, both ternary
branches (parenthesized), an assignment pattern, an `inside` set, a
binary-chain comment before the operator, and a standalone
leading-and-trailing-commented paren. All eight comments survived in
their original stream position, all eight groups broke open, 3-pass
stable. One layout observation, not a defect (see Findings #3 below).
3. **Closing block labels — PASS.** `stress/08_closing_labels.sv` exercises
all three `join` kinds (`join`, `join_any`, `join_none`) plus nested
labeled blocks (`begin : outer` › `begin : inner` › `end : inner` ›
`end : outer`, checking the labels come back in the correct nesting
order, not swapped) plus a labeled `function`/`task` inside a labeled
`package`. `08c_generate_labeled.sv` adds a labeled generate `if`/`else`
and a labeled generate `for`. `08b_end_label_trailing_comment.sv` (a case
from the assignment's specific ask: "trailing comment AFTER an end
label") — `end : blk // trailing after end label` — round-trips
correctly with the comment staying trailing on the label line. All
stable across 3 passes; all closing-label cases in the committed
`.cases` diff (`statements.cases`, `functions_tasks.cases`,
`generate.cases`, `module_headers.cases`) independently re-verified by
hand-reading the diff, all four look correct against their stated
construct.
4. **Multi-instance declarations — PASS**, including the boundary the
assignment specifically asked for. Built a generator
(inline, not left in the corpus) that produces a two-instance
declaration whose one-line rendering is *exactly* 100 and 101 columns:
at 100 it stays on one line, at 101 it breaks with the continuation
indented one level (4 spaces) under the 2-space head — distinguishable
from a new statement, matching the bug-4 fix description exactly. Also
checked instance arrays (`arr0 [3:0] (...)`) and parameter overrides
together in one declaration (`09_multi_instance_params_arrays.sv`); all
four sub-cases (fits / breaks / arrays / short) render as expected and
are 3-pass stable.
5. **`@( /* c */ * )` — PASS**, and more spellings than documented.
`10_sens_list_spellings.sv` mixes `@( /* a */ * )`, `@(*)`, `@*`,
`@( * /* trailing */ )`, and — not in any existing case —
**both a before- and an after-comment on the same sensitivity list**:
`@( /* before */ * /* after */ )` → `@(/* before */ * /* after */)`.
Comment order relative to `*` preserved on both sides simultaneously,
3-pass stable. Confirmed by direct code read that `verify.rs`'s only
change is the two `comment_item(...)` call sites at lines 174 and 187
now reading `comment.line`/`comment.col` (or `trailing.line`/
`trailing.col`) instead of the owning token's — no comparison logic
touched, no normalization added or removed. `git diff
crates/vlog_formatter/src/verify.rs` is exactly those two one-line
changes plus a doc-comment wording update; confirmed line-by-line.
6. **Multi-line directives/attributes — PASS.** `06_define_ifdef.sv` (a
3-continuation-line `` `define`` inside an `` `ifdef``, at top level) and
`06b_define_inside_module.sv` (the same, nested inside a module — the
specific case the work log calls out) both stable across 3 passes.
`11_attribute_multiline.sv` (a 3-line `(* foo = 1, bar = 2, baz = 3 *)`
attribute) also stable. Audited `RawText` usage for consistency across
the three call sites the Handshakes promise (`ItemKind::Directive`,
`StmtKind::Directive`, `Meta::attrs`): all three are populated via the
same `Parser::take_raw_text()` (`parser.rs:215-218`, captures `col`
before `bump()`) and all three are read via the same
`Fmt::raw_text()` → `raw_lines(text, col)` (`format.rs:112-114`). No
third code path exists for either type.
7. **200 cases / 0 `#SKIP` / green workspace / silent clippy / clean
fmt / self-format-stable — PASS**, all independently reproduced above.
Additionally ran lucisv-on-its-own-output beyond the work log's one
hand-written file: **every one of the 200 committed cases' expected
outputs plus all 4 real fixture files** (204 total) through 3 passes via
`regress3.py` — 0 failures, 0 cases where pass1's output differs from
the `.cases` file's recorded expected output (an independent
cross-check of the harness itself), 0 cases of 3rd-pass drift anywhere
in the corpus.
**Handshake audit**
- `token::Comment{line,col}`: confirmed 1-based, confirmed populated only by
`lexer.rs` (`tokenize`, lines 564-580) from `RawTok.line`/`.col`, which
come from the raw lexer's running position at the *start* of the comment
(`RawLexer::bump`, byte-granular column counting, tab = 1 column,
consistent with the dedent side — see claim 1 above).
- `Token::trailing: Option<Comment>`: grepped every `.trailing` site in both
crates (`grep -rn '\.trailing'`). No caller still assumes `String`; the
one remaining `Option<String>` is the unrelated `Meta.trailing` (several
merged trailing comments, printed verbatim, no position needed — matches
the Handshakes note that it "needs no position"). The lexer unit test
(`lexer.rs:638`) uses `.expect("trailing comment")`, which is fine per
CLAUDE.md's test exemption.
- `RawText.col`: confirmed all three consumers (`ItemKind::Directive`,
`StmtKind::Directive`, `Meta::attrs`) go through one producer
(`take_raw_text`) and one consumer (`raw_text`/`raw_lines`) — see claim 6.
- `printer::contains_hard_line` now `pub(crate)`: two call sites, both sane
— the pre-existing two internal to `printer.rs` (group-fits and
hard-line-forces-break checks) plus the one new external use in
`format.rs::assign_rhs` (`format.rs:240`), which is exactly the "does
this value already break?" check the Assumptions describe. No other new
callers.
- `CLAUDE.md` no-`unwrap`/`expect`/`panic!`-in-library-paths: grepped the
diff's added (`+`) lines for `.unwrap()`/`.expect(`/`panic!`; the only
three hits are all inside `#[cfg(test)] mod tests` in `lexer.rs`
(`lexer.rs:638,644,653` in the new file), which CLAUDE.md exempts.
`format.rs:532`'s pre-existing `unreachable!()` in `binary_chain` is
unchanged context, not new.
- No new dependencies (`git diff` on all three `Cargo.toml` + `Cargo.lock`:
empty). No `#[allow]` added anywhere. `TODO.md`, top-level `README.md`,
and `crates/lucisv/` are all byte-identical to `HEAD` (`git diff --stat`
empty for all three) — matches the Handshakes claim that nothing outside
`vlog_parser`/`vlog_formatter` was touched.
**Regression hunting**
Specifically tried to break something that used to work. Constructed and
fixed (after finding my own test-file bugs, not formatter bugs — `initial`
inside a function, `always` inside a function, `fork` at package scope are
all illegal Verilog, not lucisv defects) a combined-stress file
(`12_combo_stress.sv`: banner comment + labeled package/function/nested
begin + `@( /* c */ * )` + commented concatenation + multi-instance, all in
one file) — 3-pass stable, matches the work log's own combined-stress claim.
Ran the entire `tests/cases/` corpus (all 200 inputs) and all 4
`tests/fixtures/*.sv` through 3 passes independently of `cargo test`
(`regress3.py`): **zero regressions, zero drift, zero unexpected refusals.**
This is the strongest evidence available that nothing which used to format
correctly now breaks.
**Findings**
*Should-fix*
None. No blocking or correctness issue found in the diff itself.
*Nit / informational*
1. **A comment in a ternary branch with no enclosing group still refuses
cleanly** (exit 2, file untouched) — verified with
`assign w = cond ? a : // c\n b;` → `verification failed: token stream
diverges at index 10: ...`. This is *not* a broken claim (ternary
branches were never listed among the covered constructs — Handshakes
names only concat/call-args/`inside`/assignment-pattern/paren/binary),
and it is not a regression (ternary carries no comment field before or
after this diff). It is simply a fourth refusal location beyond the
three the README's "Not fixed" list names. Worth a one-line addition to
that list for completeness next time someone touches this area, but not
blocking — filed here rather than fixed, since expanding comment support
to ternaries is a design decision (does the ternary need to hug like
`assign_rhs` does?), not a small unambiguous fix.
2. **Pre-existing lexer limitation, not caused by this diff**: `@(* )` —
parens with a bare space between `*` and `)`, *no comment involved* —
fails to lex at all (`lex error: unterminated attribute (* ... *)`),
because `(*` immediately followed by anything other than `)` is always
treated as the start of an attribute instance
(`vlog_parser/src/lexer.rs:223`, `peek_at(2) != b')'`), and that line is
untouched by this diff (confirmed via `git diff` showing no hunk
touching it). So legal input with incidental whitespace inside `@( * )`
was already unparseable before this change and still is. Flagging
because this feature's Assumptions specifically discuss this exact `(*`
ambiguity for the *output* spelling of `after`-comments, so it's a
natural thing for whoever reads that section next to wonder about; it's
out of scope for a bug-fix feature that (correctly) didn't touch
`lexer.rs`'s core tokenizing logic.
3. **Style observation, not a bug**: a comment on its own source line
immediately before a closing construct — the closing `)` of a `Paren`,
or before a binary operator — gets glued onto the end of the preceding
line in the output rather than kept on its own line. Example: input
```
assign s = (
// paren leading comment
a + b
// paren trailing comment
);
```
formats to `a + b // paren trailing comment` on one line. This is
deliberate and consistent — it's the exact same mechanism the committed
`comments.cases` case "comment before the operator of a long operator
chain" already pins down (`first // wait for the second one too` ⏎
` && second;`), and it mirrors `SensList::Star`'s `after` handling. Not
a correctness issue (order and content both preserved, 3-pass stable),
just a readability wrinkle worth knowing about if a future case author
is surprised by it.
**Overall verdict**: all 7 claims **PASS**. No regression found anywhere in
204 pre-existing inputs re-run through 3 passes, nor in 15 hand-built
adversarial stress files targeting the specific corners the assignment
named (ragged/tab/column-0 comments, every expression-comment position,
every closing-label kind including nested and trailing-comment-after-label,
the exact 100/101-column multi-instance boundary, and mixed sensitivity-list
spellings). The three documented remaining refusals all still refuse
cleanly with an accurate error and leave the file byte-identical. CLAUDE.md
compliance (no unwrap/expect/panic in library paths, no new deps, no
un-explained `#[allow]`, TODO.md/README.md/`lucisv` untouched) all confirmed
by direct inspection, not just by trusting the work log's claims.
## Review
**2026-08-19 — lead. Verdict: accepted and committed as-is; no lead fixes
needed.**
The strongest round so far. All five briefed bugs fixed with the parked
expected outputs hit verbatim, a sixth (directive/attribute drift) found
and fixed with the same root-cause discipline, and — the part I care most
about — verify.rs untouched except for diagnostic positions. The safety
net was never weakened to make a fix pass, and QA independently confirmed
that with a diff audit. The dedent-by-`col-1` design for comment
re-indentation is the faithful fix the safety-net work log asked for, and
preserving *relative* raggedness inside comments (rather than
normalizing it away) is the right reading of "comments are never
dropped": we don't own the inside of a comment.
Also noteworthy: triple-pass stability over all 204 inputs, the
100/101-column boundary probes, and honest documentation of the three
remaining comment-placement refusals instead of hacks. Clearing the four
pre-existing clippy warnings in files already being touched was within
the letter of the brief and leaves clippy fully silent — worth keeping
that way.
Dispositions on QA findings (all nit-level):
- **Ternary-branch comment refusal** (a 4th refusal location): added to
this README's open items alongside the documented three. All four are
refusals, not corruption — safe to leave until a comments-in-
expressions round.
- **`@(* )` fails to lex** (bare space before `)`; `(*` greedily starts
an attribute): pre-existing lexer limitation, now recorded in TODO.md.
- **Comment glued before a closing `)` / binary operator**: consistent
with committed cases; goes on the style-rulings list from the
case-tables review.