QA round 1: adversarial review logs and a with-block attack test

No blocking findings over the 8 round-1 clusters: whole-corpus idempotency
and comment-preservation sweep clean (796/820), 476-run mutation fuzz clean,
no swallowed errors in the diff. Adds
reindented_string_inside_a_with_block_is_rejected. Findings (non-blocking)
are in each feature README's QA log; the printer fits() / Doc::Inline gap
is fixed separately.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-21 01:37:33 -07:00
1 parent f1db1e5746
commit 0557933994
9 files changed
+400 -8

No files matched your search

@@ -179,6 +179,20 @@ fn comment_at_end_of_file_is_rejected_if_dropped() {
assert!(matches!(expect_divergence(input, output), VerificationError::Divergence { .. })); assert!(matches!(expect_divergence(input, output), VerificationError::Divergence { .. }));
} }
/// QA round-1 (2026-08-21): `Doc::Inline` (the `with { ... }` constraint
/// block printer node, `dv-statements`) is meant to be reproduced byte for
/// byte — `Fmt::with_block` never re-indents it. This locks that in from the
/// safety-net side: even if a future change *did* try to re-indent a
/// multi-line string sitting inside a `with { ... }` block, the net must
/// still reject the corrupted result on token-stream grounds, exactly as it
/// does for the macro-argument and `` `define `` cases above.
#[test]
fn reindented_string_inside_a_with_block_is_rejected() {
let input = "module m;\n class C;\n task t();\n if (2) begin\n x.randomize() with {\n $display(\"line one\n line two\");\n };\n end\n endtask\n endclass\nendmodule\n";
let output = "module m;\n class C;\n task t();\n if (2) begin\n x.randomize() with {\n $display(\"line one\n line two\");\n };\n end\n endtask\n endclass\nendmodule\n";
expect_divergence(input, output);
}
#[test] #[test]
fn truncated_output_is_rejected() { fn truncated_output_is_rejected() {
let input = "module m;\n wire x;\nendmodule\n"; let input = "module m;\n wire x;\nendmodule\n";
+66 -1
View File
@@ -280,4 +280,69 @@ Files changed:
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks:
- **`skip_action_stmt` running off the end / infinite loop on unbalanced
input.** Not found — `skip_balanced` and the outer `skip_action_stmt` loop
both check `at_eof()` on every iteration and return a clean parse error
("expected `)`" / "expected `;`" / "expected `end`") rather than looping.
- **`skip_action_stmt` swallowing the FOLLOWING item/statement — found a real
gap (clean error, not corruption).** `skip_action_stmt`'s non-`begin`
branch (parser.rs, `fn skip_action_stmt`, ~line 1665) scans token-by-token
for a depth-0 `;`, tracking nesting only for `(`/`[`/`{`. It does **not**
track `begin`/`end` nesting unless the pass statement's *very first* token
is literally `begin`. So when the pass statement is, e.g., an `if` whose
then-branch is a `begin ... end` block, the scan stops at the first `;`
**inside** that nested block instead of after the block's `end`. Repro:
```verilog
assert property (@(posedge clk) a |-> b)
if (cond)
begin
x = 1;
end
else
y = 2;
```
→ `parse error: 8:7: unsupported construct starting with keyword 'else'
(found "else")` (exit 2). Without the `else`, the leftover `end` after the
prematurely-ended verbatim span becomes `parse error: 8:5: expected
declaration or instantiation (found "z")` for whatever follows. Both are
**clean rejections** — exit 2, zero bytes written, input untouched on disk
— so no hard invariant is broken, but this is a real, reproducible parsing
gap in the assertions cluster: an otherwise-legal concurrent-assertion
action block (`if` with a `begin/end` body, optionally followed by `else`)
is currently unformattable. Files at
`/private/tmp/claude-501/.../scratchpad/qa/assert1.sv` and `assert2.sv`.
**NON-BLOCKING** (no corruption/idempotency/comment-loss), but flagged as a
concrete follow-up: `skip_action_stmt`'s generic branch needs `begin`/`end`
depth tracking alongside its bracket tracking.
- **`restrict` matched by text.** No case found where an ordinary identifier
named `restrict` followed by `property` gets misidentified — the exact
scenario the dev's comment says cannot happen (no type/instance name is
ever followed by the `property` keyword) held up under testing.
- **Verbatim raw_text with a multi-line string inside `else $error("...")`.**
Constructed a concurrent assertion whose action block contains
`$error("line one\nline two")` at a nested `generate`/`begin` indent level
different from column 0; the whole assertion — multi-line string included —
reproduces byte-identical and is idempotent; the first line gets
re-indented with the rest of the item, the string's continuation line does
not move (per `crosses_line_inside_string`/`raw_text`, format.rs).
- **Comment immediately after `assert`/`property`/inside the property
paren/around the action-block boundary.** `assert /*c1*/ property /*c2*/ (
/*c3*/ @(posedge clk) a |-> b /*c4*/ ) /*c5*/ else /*c6*/ $error("x")
/*c7*/ ;` — every comment position round-trips byte-identical (the whole
construct is one verbatim span), no losses.
No BLOCKING findings for this cluster. The `skip_action_stmt` begin/end gap
above is the most concrete follow-up item.
+38 -1
View File
@@ -198,4 +198,41 @@ instantiation too (`bind.cases`, "implicit named *parameter* overrides").
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks:
- **`bind` recognized by shape, not keyword — `obj.bind()` must still
parse.** Confirmed: `obj.bind(); obj.bind(1, 2);` (method calls named
`bind`) format unchanged, not confused with the directive.
- **Indexed hierarchical bind targets are a clean parse error.** Confirmed:
`bind dut[3] checker_mod c_inst(.clk(clk));` → `parse error: 2:15: expected
';' (found "checker_mod")`, exit 2, zero bytes on stdout. Clean rejection,
not corruption, matches the dev's own note.
- **Comment placement inside a `bind` directive.** Found a real (but
non-corrupting) gap: a comment sitting between `bind` and the target name —
`bind /*c1*/ dut checker_mod c_inst(.clk(clk));` — is **not** currently
reproduced by the formatter's internal `Doc` construction; the safety net
catches it (`verify_equivalence`: "token stream diverges ... input has
comment `/*c1*/` at 2:8, output has identifier `dut` at 2:8") and the CLI
exits 2 with zero bytes written to stdout. Root cause: `parse_bind`
(parser.rs, `fn parse_bind` — target-name parsing via `expect_ident()`
around parser.rs:2627) never routes through `take_meta()`/the comment
bucket the way ordinary item/list elements do, so a comment landing exactly
there has nowhere to attach and gets dropped internally — but the net
refuses to let that reach the file. **NON-BLOCKING** per the hard
invariants (no corruption occurred; input is left untouched on disk), but
worth a follow-up: comments in that position currently make the file
unformattable via vfmt rather than being preserved and formatted. Same
class of gap reproduces for a comment right after the module name / before
the instance name of the `bind`'s instantiation tail — not otherwise
explored in depth.
No BLOCKING findings for this cluster.
+30 -1
View File
@@ -179,4 +179,33 @@ attack tests are owed under CLAUDE.md invariant 4.
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean (see item-misc log
for the shared methodology); 476-case mutation fuzz clean (0 panics/hangs/bad
exit codes/non-idempotent output).
Targeted attacks:
- **`context` recognized positionally, not as a keyword.** Tried `context`
used as an ordinary identifier in the position where it would be confused
with the DPI property: `import "DPI-C" function void context();` (function
*named* `context`) formats correctly and is not swallowed by the
positional check. Also exercised the real grammar order (`context`/`pure`
*before* the optional `c_identifier =`, IEEE 1800 §35.5.2) —
`import "DPI-C" context mycid = function void f1();` and the `pure` variant
both parse and round-trip.
- **`export *::*` → `ImportPath` with package `"*"`.** `package p; export
*::*; endpackage` formats unchanged and is idempotent
(`target/release/vfmt --stdout` twice, `cmp` clean).
- **`is_prototype` doubling as "DPI import".** No case found where this
conflation produces a wrong-but-plausible read; every DPI import/export
variant tried (`context`, `pure`, `c_identifier =`, task vs function,
package export lists, package export with comma-separated names) round-trips
or cleanly errors.
No BLOCKING findings for this cluster.
+96 -1
View File
@@ -298,4 +298,99 @@ Files changed:
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean. Added one regression test to
`crates/vlog_formatter/tests/verification.rs`
(`reindented_string_inside_a_with_block_is_rejected`) locking in that the
safety net would still reject a re-indented multi-line string inside a
`with { ... }` block even if a future change broke `Fmt::with_block`'s
"never touch it" contract; `cargo test -p vlog_formatter --test verification`
is green (100 passed) with it in.
**`Doc::Inline` printer width accounting — real bug found (NON-BLOCKING:
formatting-quality, not corruption).**
`with_block` (format.rs `fn with_block`, ~line 246) emits the constraint body
as `Doc::Inline(raw.text.clone())` — always byte-for-byte, never re-indented.
That part is correct and I could not break it: braces inside strings/comments
inside the block don't confuse `skip_balanced` (lexer already collapses
those to single tokens), multi-line strings inside the block survive
untouched at every indent level tried, and it's idempotent in every case.
But `printer.rs`'s `fits()` (the group flat/break decision) and `print()`
disagree about what happens *after* a multi-line `Doc::Inline`:
- `print()` (printer.rs ~line 33) correctly continues measuring from the end
of the Inline's last line — i.e. whatever comes next in the doc keeps
writing onto the *same output line* the Inline's `}` ended on. This matches
the doc comment on `Doc::Inline` in doc.rs ("what follows it continues on
the line the text ends on").
- `fits()` (printer.rs ~line 137) treats a multi-line `Doc::Inline` like
`HardLine`/`Verbatim` and returns *early* — `return width -
head.chars().count() as isize >= 0` — based only on the Inline's first
line, **without** checking whatever comes after it in the same group. This
is inconsistent with `print()`'s actual behavior: since nothing after the
Inline starts on a fresh line, the group's fits-check needs to keep
measuring past the Inline to know whether the *rest of the line* fits, but
it stops and reports "fits" prematurely.
Repro (`/private/tmp/.../scratchpad/qa/with5.sv`):
```verilog
if (a.randomize() with {
x == 1;
y == 2;
} && some_really_quite_long_flag_name_that_would_overflow_the_line_length_for_sure)
begin
z = 1;
end
```
`target/release/vfmt --stdout --line-length 40 with5.sv` keeps the whole
` } && some_really_quite_long_flag_name_that_would_overflow_the_line_length_for_sure) begin`
tail on one line (99 characters, well past the 40-column limit requested),
where the *same* `if` condition without the `with`-block correctly wraps the
`&&` operands onto their own lines under `--line-length 40` (verified with a
matching `ifbase.sv` control case). The output is still valid Verilog,
idempotent (`cmp` clean across two `--stdout` passes), and no content is
lost — this is a line-length-target miss, not corruption — but it is exactly
the class of bug the printer-width-accounting change was flagged as
highest-risk for, so I'm logging it as a concrete, reproducible finding
rather than "found nothing." Any group containing a multi-line `with { ... }`
block followed by more content that needs to wrap will silently fail to wrap
that trailing content.
Other targeted attacks:
- **`with { ... }` verbatim vs braces/strings/comments inside it.** Braces
inside a string (`"brace } in string"`) and inside a comment (`/* a } b {
c */`) inside a `with` block do not confuse `skip_balanced`/`verify.rs`;
both round-trip byte-identical.
- **Comment right after `.randomize(` / before `with` / etc.** Found a real
(non-corrupting) gap parallel to the `bind` one:
`x.randomize /*c1*/ ( /*c2*/ ) /*c3*/ with /*c4*/ { a == 1; } /*c7*/ ;` is
rejected by the safety net (`verification failed: token stream diverges ...
input has comment "/*c1*/" ..., output has symbol "(" ...`), exit 2, zero
bytes written — clean, not corrupting, but a coverage gap (comments
touching the `.randomize()`/`with` boundary currently make the statement
unformattable rather than preserved-and-formatted).
- **General statement labels vs case-item labels vs `label: assert
property`.** A `case` body containing both a case-item label (`1: y=1;`)
and, inside one arm's `begin/end`, a labeled concurrent assertion
(`my_label: assert property (...)`) round-trips correctly and is
idempotent; a top-level `label: assert (cond) else $error(...);` also
round-trips.
- **Stray `;` after `endtask: name`.** `endtask: t;` → `endtask : t;` (label
spacing normalized, the stray `;` kept as a token, nothing dropped),
idempotent.
- **Empty call argument `f(a, , b)` when the list breaks.** Under
`--line-length 40` the empty argument gets its own line (`,` alone) when
the call wraps; round-trips and is idempotent.
No BLOCKING findings for this cluster. The `Doc::Inline` `fits()` bug above
is the one concrete "this is a real bug" result of the whole round — it's a
formatting-quality regression, not a hard-invariant break, but given how the
dev flagged this exact change as highest-risk, I'm surfacing it prominently
rather than filing it as routine cosmetic feedback.
+42 -1
View File
@@ -223,4 +223,45 @@ Files changed:
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks:
- **`->` binary implication vs `-> ev;` event trigger vs `->>`.**
`-> ev;`, `-> ev1; -> ev2;` (statement-position event trigger) and
`x = (a -> b);`, `x = a ? (b -> c) : d;`, `if (a -> b) x = 1;` (expression
implication) all format correctly. `a -> b;` and `a ->> b;` at bare
statement position correctly error (there is no such statement form in
real SV either — `->` needs to be a prefix event trigger or nested in an
expression, never a bare infix statement). **Pre-existing gap, not
introduced by this round:** `->>` (nonblocking event trigger,
IEEE 1800 §15.5.2, e.g. `->> event_a;`) is not in the lexer's `OPERATORS`
table at all (`crates/vlog_parser/src/lexer.rs:53-56`) — confirmed via
`git diff` that this round only *added* `<->` to that table and did not
touch (or regress) `->>`; it lexes today as `->` followed by a lone `>`
and fails to parse in every context tried. Filing this as an
out-of-round observation, not a finding against this diff.
- **`a<-b` (no space) vs `<->`.** `x = a<->b;` and `x = a <-> b;` both format
to `a <-> b` and are equivalent/idempotent; no case found where `<->`
the new lexer entry mis-tokenizes an adjacent `<`/`-`/`>` combination.
- **`parse_implication` recursion depth.** A 3000-deep `->` chain and a
500-deep `int'(...)` cast nest both hit the recursion-limit guard cleanly
("nesting too deep (limit 64)", exit 2) with no stack overflow — confirmed
under a hard 10s wall-clock kill, no hang.
- **`'{N{0}}` vs `'{a:0}` vs `'{ /*c*/ N{0}}`.** `'{N{0}}` and `'{a:0}` (→
`'{a: 0}`) format correctly. Confirmed the known case: a comment before the
replication count — `'{ /*c*/ N{0}}` and `'{/*c*/N{0}}` — is rejected by
the safety net with a clean `verification failed: token stream diverges`
error (exit 2, zero bytes on stdout), **not corruption**, exactly as
flagged.
- `(* attr *)` on connections and `Cast::ty: Box<Expr>` were exercised via
the mutation fuzz on `expressions_2.cases` (delete paren, comment-in-gap,
fence) with no panics or idempotency breaks; did not go deeper on
alignment-inference interaction specifically.
No BLOCKING findings for this cluster.
+33 -1
View File
@@ -217,4 +217,36 @@ forgiveness, so no masked-corruption attack tests are owed.
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks:
- **`clocking`/`endclocking` reserved globally.** `logic clocking; logic
endclocking; initial clocking = 1;` now cleanly errors ("expected
identifier (found `clocking`)"), exit 2, no output. This matches real
IEEE 1800 (`clocking` is a reserved word there too), so not a regression in
practice — real RTL essentially never uses these as identifiers. Confirmed
clean, not corrupting.
- **`fence.rs`/`range.rs` (`--lines`) on interfaces.** `--lines 3-3` on a
6-item interface (ports/modport/clocking) reformats only the targeted line
and leaves everything else byte-identical; `// verilog_format: off` /
`... on` fences inside an interface correctly protect the fenced region
while the rest of the interface still gets formatted. No issues found.
- **module-filename lint firing on interfaces.** Read
`crates/vlog_linter/src/rules/module_filename.rs`: `ItemKind::Module` is
shared by `module`/`interface` (distinguished by `.kw`), and the rule
requires *exactly one* such item in the file. Confirmed a file with both a
`module foo;` and an `interface bar_if;` is silent (two "module-like"
items → rule doesn't fire), and a lone `interface bus_if;` in a
mismatched-name file fires with `interface \`bus_if\` does not match file
name ...` (matches the new test
`an_interface_is_held_to_the_same_rule`). Correct.
No BLOCKING findings for this cluster.
+48 -1
View File
@@ -278,4 +278,51 @@ directions are pinned in `item_misc.cases`).
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`, `cargo clippy --all-targets`, `cargo fmt
--check` all clean. `scripts/score.sh` reports 796/820 as expected. Ran a
whole-corpus sweep (all 796 passing files, `--stdout` twice + `cmp`, plus a
comment-multiset diff of input vs output): 0 crashes, 0 idempotency breaks, 0
comment losses (one file had a trailing-whitespace-inside-comment trim, which
is an existing, benign normalization, not a loss of content). Ran a 476-case
mutation fuzz (delete `;`, delete `(`/`)`, comments jammed into every gap,
`// verilog_format: off` fence-wrap) over 3 examples from every new `.cases`
file × `{plain, --lines 1-999, --indent 4, --line-length 40}`: 0 panics, 0
hangs, 0 unexpected exit codes, 0 idempotency breaks.
Targeted attacks from the hit-list:
- **Shared `at_macro_item` predicate misused at list position** (parser.rs
`take_list_directives` / port-param lists). Tried a macro-typed port/param
split across lines inside `#( ... )` and `( ... )` (`` `WIDTH_T`` / ⏎ /
`parameter x = 1`), a macro-with-args followed by an identifier on the same
line (`` `WIDTH_T(8) portname``), nested macro args, etc. Every wrong guess
either reproduced the same tokens (formats fine, idempotent) or was caught
by `verify_equivalence`/the parser and cleanly rejected (exit 2, zero bytes
on stdout) — never corrupted. Confirms the doc comment's claim on parser.rs
around line 860 ("guessing wrong cannot corrupt code").
- **`` `error``/`` `warning`` as permanent line directives.** Confirmed: if a
project `` `define``s its own `error(msg)`/`warning(msg)` macro and calls
it, the call is lexed as a line directive (`is_line_directive`,
lexer.rs:685), so the *rest of the physical line* becomes directive text.
Repro: `` `define error(msg) $display(msg)`` then
`` `error("oops"); x = 1 ;`` **on one line** — the badly-spaced
`x = 1;` right after the macro call is never touched by the formatter
(byte-identical in and out), because it's inside the directive's
verbatim-to-EOL span. When the macro call and the next statement are on
separate lines (the overwhelmingly common real-world layout — see
`errmacro4.sv` in scratchpad), formatting of the next statement is
unaffected. Not corruption (output is a no-op, still valid, idempotent, no
comments lost), not a parser crash — just a silent "skip formatting this"
for the rare same-line case. **NON-BLOCKING**: a real gap for projects that
shadow `` `error``/`` `warning`` as user macros with same-line follow-on
statements, but no invariant is broken.
- **Spaced macro calls (`` `M (a) ``) verbatim capture, including a comment
between name and `(`.** `` `uvm_field_int /* c */ (fetch_addr,
UVM_DEFAULT)`` round-trips byte-identical and is idempotent.
No BLOCKING findings for this cluster.
+33 -1
View File
@@ -180,4 +180,36 @@ both the before and after TSVs, so it was never in this bucket's count.
## QA log ## QA log
## Review ### 2026-08-21 — round-1 adversarial QA
Verified: `cargo test --workspace`/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks: fed the statement-position `ident [..] ... ident` lookahead
every shape from the hit-list plus variants — `x[i] y;`, `a [b] = c;`,
`foo [1] ;`, `x [i] = y;`, `arr[3] = val;`, `x[i][j] y;`, `x [7:0] y, z;`,
`x[7:0] y = 1;`, `x[a+b] y;`, `x [1] y [2];`. Findings:
- `a [b] = c;`, `foo [1] ;`, `arr[3] = val;` correctly stay ordinary
statements (array-index assignment / index expression) — not reinterpreted
as declarations.
- `x[i] y;` and friends (a trailing bare identifier before `;` with no
assignment) *are* reinterpreted as declarations (space normalized to
`x [i] y;`). This is not a corruption risk: under real SV grammar, `ident
[expr] ident;` with no operator between the two identifiers has **no**
valid non-declaration reading (bare juxtaposition isn't a legal
expression/statement), so there is nothing else this string could have
meant — the old behavior was simply "reject it," the new behavior is
"accept the only grammatical reading." Confirmed idempotent
(`x[i] y;` case, `cmp` clean across two passes).
- No case found where the lookahead grabs something that was a genuinely
valid *other* statement before this change.
Also exercised `parse_opt_data_type`'s inline-aggregate acceptance with
`DataType::extra` via the corpus sweep and mutation fuzz (delete `;`/paren,
comment-in-every-gap, fenced) over 3 samples from `types_decls.cases` — no
panics, no idempotency breaks.
No BLOCKING findings for this cluster.