diff --git a/crates/vlog_formatter/tests/verification.rs b/crates/vlog_formatter/tests/verification.rs index f7f02ad..05d9166 100644 --- a/crates/vlog_formatter/tests/verification.rs +++ b/crates/vlog_formatter/tests/verification.rs @@ -138,6 +138,39 @@ fn spacing_out_a_macro_digit_number_is_rejected() { expect_divergence(input, output); } +/// QA round-2 attack (mop-up-2 mandate): a based number joined with a macro +/// whose argument list carries a multi-line string. Re-lexing the *output* +/// still splits this back into a `Number` (`32'h`) and a macro `Ident`, so +/// the string-aware trim on that `Ident` is what has to hold here, exactly as +/// it does for a bare macro statement — nothing about gluing a base onto the +/// front should widen what gets forgiven inside the string. +#[test] +fn a_macro_digit_numbers_multiline_string_may_not_be_reindented() { + let input = "module m;\n localparam int A = 32'h`M(\"a\nb\", c);\nendmodule\n"; + let output = "module m;\n localparam int A = 32'h`M(\"a\n b\", c);\nendmodule\n"; + expect_divergence(input, output); + // The line break introduced by the argument list itself (not the string) + // is still free to be re-indented, same as any other multi-line macro. + let input = "module m;\n localparam int A = 32'h`M(\"ab\",\n c);\nendmodule\n"; + let output = "module m;\n localparam int A = 32'h`M(\"ab\",\n c);\nendmodule\n"; + verify_equivalence(input, output).expect("only the non-string line moved"); +} + +/// QA round-2 attack: the hoisted `at_macro_item` line rule reads +/// `Parser::macro_end_line`, which counts every `\n` byte in the invocation's +/// *text* — including ones inside a string argument — to find which source +/// line the macro ends on. A macro whose only newlines come from a multi-line +/// string, immediately followed by an unrelated symbol on the next line, must +/// still refuse a reindented string exactly like any other multi-line macro. +#[test] +fn a_macro_ending_its_line_still_rejects_a_reindented_multiline_string() { + let input = + "module m;\n initial begin\n `uvm_info(\"id\", \"a\nb\", UVM_LOW)\n x = 1;\n end\nendmodule\n"; + let output = + "module m;\n initial begin\n `uvm_info(\"id\", \"a\n b\", UVM_LOW)\n x = 1;\n end\nendmodule\n"; + expect_divergence(input, output); +} + /// `new src` (IEEE 1800 §8.12) prints with exactly one space. Closing it would /// make one identifier out of two tokens — the net refuses that, in both /// directions. diff --git a/docs/features/assertions/README.md b/docs/features/assertions/README.md index c54a6d8..550ac71 100644 --- a/docs/features/assertions/README.md +++ b/docs/features/assertions/README.md @@ -400,3 +400,29 @@ Targeted attacks: No BLOCKING findings for this cluster. The `skip_action_stmt` begin/end gap above is the most concrete follow-up item. +### 2026-08-21 — round-2 adversarial QA (verifying the round-1 fix) + +Confirms the dev's 2026-08-21 "response to QA round 1" work log entry above: +the `skip_action_stmt` depth-counter rewrite. + +- **The exact repro from round-1** (`if (cond) begin x = 1; end else y = 2;` + as an assertion's action block) now formats correctly and no longer drops + the `else`/leftover `end`; re-ran both the `begin`-first and non-`begin`- + first spellings. +- **`fork`/`join_none` with `disable fork` and `wait fork` inside**, and + `case`/`endcase` as the action block, both nested one level deeper than the + dev's own test cases (a `case` inside a `fork`, a `disable fork` inside a + `begin` inside a `fork`) — all keep the whole action block, all correctly + swallow nothing past `end`/`endcase`/`join_none`. +- **Unbalanced input, both directions:** a `begin` with no matching `end` + before EOF, and a `join_none`/`end`/`endcase` with nothing open at depth 0 + — both exit 2 with a clean, on-the-spot error and the input file untouched; + no run to EOF, no loop. Consistent with `an_unbalanced_action_block_is_a_ + clean_error`. +- **Whole-corpus idempotency and the pre/post-fix binary diff** — see + `docs/features/mop-up-2/README.md`'s round-2 QA log for the full corpus, + clippy/fmt/test-suite, and swallowed-error sweep that covers this file's + half of the `a4f8476` commit too (the two changes were reviewed together). + +No BLOCKING findings. The round-1 gap is closed. + diff --git a/docs/features/bind/README.md b/docs/features/bind/README.md index b9c0887..f7f2155 100644 --- a/docs/features/bind/README.md +++ b/docs/features/bind/README.md @@ -287,3 +287,28 @@ Targeted attacks: No BLOCKING findings for this cluster. +### 2026-08-21 — round-2 adversarial QA (verifying the round-1 fix) + +Confirms the dev's 2026-08-21 "response to QA round 1" work log entry above: +`target_comments`/`module_comments` on `BindDirective`. + +- **The exact repro from round-1** (`bind /*c1*/ dut checker_mod + c_inst(.clk(clk));`) now round-trips: the comment stays between `bind` and + the target, byte-identical, idempotent. +- **The sibling position**, between the target (or `: instance, list`) and + the instantiation's module name — `bind dut /*c2*/ chk u (.*);` and `bind + dut : u_a /*c2*/ chk u (.*);` — both round-trip. +- **Line comments in both slots**, not just block comments — + `bind // c\n dut chk u (.*);` and `bind dut // c\n chk u (.*);` — both + format correctly, ending their line and pushing the next token to a new + line, matching `Fmt::inline_comments_spaced`'s general rule. +- **The "already worked" claim** — a comment after the module name / before + the instance name (`checker_mod /*c3*/ c_inst /*c4*/ (.clk(clk))`) — + reconfirmed unchanged. +- **The deliberately-refused position** — a comment inside the `: instance, + list` (`bind dut : /*x*/ u_a chk u (.*);`) — still refuses cleanly: exit 2, + `verify_equivalence` catches the drop before it reaches disk, input file + untouched. Consistent with the "Still refused, deliberately" note above. + +No BLOCKING findings. The round-1 gap is closed. + diff --git a/docs/features/dv-statements/README.md b/docs/features/dv-statements/README.md index 28ace23..dc6ad2e 100644 --- a/docs/features/dv-statements/README.md +++ b/docs/features/dv-statements/README.md @@ -468,5 +468,57 @@ 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 + +### 2026-08-21 — round-2 adversarial QA (verifying the round-1 fixes) + +Confirms the dev's `a4f8476` "Fix round-1 QA findings" commit against both +gaps this feature's round-1 log opened. + +**The `Doc::Inline` `fits()` bug is fixed.** Re-ran the exact `with5.sv` +repro above at `--line-length 40`: the `&&` operand now wraps onto its own +line instead of overflowing to 99 characters — + +``` +if ( + a.randomize() with { + x == 1; + y == 2; + } && + some_really_quite_long_flag_name_that_would_overflow_the_line_length_for_sure +) begin +``` + +— and the output is idempotent (`cmp` clean across two `--stdout` passes). +Also checked the case the fix's own new printer unit tests +(`group_stays_flat_when_the_tail_after_an_inline_fits` / +`group_breaks_when_the_tail_after_an_inline_overflows`) pin: a tail that +*does* fit after the Inline correctly stays flat, so the fix isn't just +"always break." Separately built `0557933` with only `printer.rs` swapped +for the `a4f8476` version and diffed its output against the unmodified +binary over the full 820-file corpus: 0 files differ, so the width-accounting +fix has no observable effect on any layout in this corpus that doesn't +involve a multi-line `Inline` — consistent with the bug being real but narrow, +as originally reported. + +**The `.randomize()`/`with` comment gap is fixed.** `CallComments` and +`WithComments` now give `before_open`, the empty-call `dangling` slot, +`before_kw` and `after_kw` each a place to attach. Re-ran the exact round-1 +repro, `x.randomize /*c1*/ ( /*c2*/ ) /*c3*/ with /*c4*/ { a == 1; } /*c7*/ +;` (the seven-comment stress case) — all four of the previously-dropped +positions (`/*c1*/`–`/*c4*/`) now round-trip; `/*c7*/`, after the closing +`}` and before the `;`, was never part of this gap (it belongs to the +statement's own trailing-comment handling) and still round-trips too. Also +checked **line comments** in all four slots (not just block comments, which +is all the dev's own tests use) — `o.randomize // c\n()`, `f( // c\n)`, +`o.randomize() // c\nwith {...}`, `o.randomize() with // c\n{...}` — each +correctly ends its line and pushes the following token to a fresh line +(`Fmt::inline_comments_spaced`'s general rule), and all four are idempotent. +Also confirmed the call case that must *not* grow a comment slot: `f( /*c*/ +a)` — a list with an element attaches the comment to that element +(`args[0].meta.leading`), and `CallComments::is_empty()` stays true, matching +`an_argument_carries_its_own_comments_and_the_call_carries_none`. + +Both round-1 gaps are closed; no new BLOCKING findings from re-attacking +either fix. rather than filing it as routine cosmetic feedback. diff --git a/docs/features/mop-up-2/README.md b/docs/features/mop-up-2/README.md index e13dbaf..8e28202 100644 --- a/docs/features/mop-up-2/README.md +++ b/docs/features/mop-up-2/README.md @@ -252,4 +252,117 @@ would fail to lex and the net would refuse it, which is what ## QA log +### 2026-08-21 — round-2 adversarial QA + +Scope: this feature's own commit (`e35da29`), reviewed together with the +sibling "Fix round-1 QA findings" commit (`a4f8476`) per the round-2 mandate. + +**Gates.** `cargo build --release`, `cargo test --workspace` (883 tests, 0 +failed), `cargo clippy --all-targets` (clean, no warnings), `cargo fmt +--check` (clean). `scripts/score.sh` → 800/820, matching the work log. + +**Swallowed-error grep.** `git diff 0557933..a4f8476` for `let _ =`, `.ok()`, +`unwrap_or`, `if let Ok(`, `Err(_) =>`, `_ => {}` inside `crates/`: one hit, +`tail.strip_prefix(['s','S']).unwrap_or(tail)` in +`Token::is_base_only_number` (`token.rs`) — a default on a plain string +strip, not an error path. Nothing swallowed. + +**Truncated/unbalanced input, all the new grammar surfaces:** `a = new` ++EOF, `32'h`+EOF, `` 32'h` ``+EOF, `bind /*c`+EOF, `` `randomize() with `` ++EOF, unbalanced `with {`, unbalanced `with (`, an assertion action block +with an unclosed `begin`. All eight exit 2 with a clean parse/lex error and +the input file untouched — no hang, no panic, no partial write. + +**`32'h`MACRO` join, every shape in the mandate:** unsized (`` 'h`X ``), +`32'H`, `32'sh`, `` 32'h`X + 1 ``, inside a concatenation and a replication, +as a port connection, as a parameter default, at EOF with no trailing +newline — all parse, format and round-trip idempotently. Whitespace between +base and backtick (`` 32'h `X ``) is a clean lex error, exit 2, input +untouched, in every position tried. A multi-line string inside the macro's +argument list (`` 32'h`M("a\nb", c) ``) formats unchanged and idempotently; +the re-lexed *output* still splits into `Number("32'h")` + +`Ident("`M(...)")`, so `verify.rs`'s existing string-aware trim on the macro +`Ident` is what protects it — confirmed by two new attack tests (below), not +assumed. + +**`macro_end_line` against multi-line strings:** built three cases where a +macro's only newlines come from a string argument (closing paren on the +string's own line, on a later line, and with trailing tokens continuing the +macro's last line right after the string) — all parse and round-trip +correctly. `macro_end_line` counts every `\n` byte in the token text +regardless of string/comment context, which is exactly what `Parser::bump`'s +line counter does when producing the *next* token's `.line`, so the two never +disagree; no case was found where this trips. + +**`verify.rs` re-attack (added, not just reasoned about):** two new tests in +`crates/vlog_formatter/tests/verification.rs`, +`a_macro_digit_numbers_multiline_string_may_not_be_reindented` and +`a_macro_ending_its_line_still_rejects_a_reindented_multiline_string`. Both +construct an (input, corrupted-output) pair that reindents whitespace inside +a multi-line string carried by a macro argument — one for the `32'h`MACRO` +join, one for a macro that ends its own line ahead of an unrelated symbol — +and both assert `verify_equivalence` rejects it. Both pass without any change +to `verify.rs`; the feature's claim that this commit needed no net change +holds up under attack, not just under reading. A third assertion in the same +test confirms the non-string line break in the same construct is still +correctly *forgiven* (so the fix isn't just "reject everything"). + +**Mutation fuzz.** Extracted the 19 cases this round added across +`macros/classes/expressions_2/assertions/bind/dv_statements.cases`. Ran every +prefix-truncation and every single-character deletion (2231 trials): 0 +crashes, 0 timeouts, every one either a clean exit 0/1 or a clean exit 2. +Ran a second pass inserting a block comment and a line comment at every +whitespace/newline gap, wrapping each case in `// vfmt: off` / `// vfmt: on` +fences, and running `--lines -` for every line (807 trials): same, 0 +crashes. + +**Whole-corpus idempotency sweep.** All 800 passing corpus files, formatted +twice via `--stdout` and compared: 0 mismatches. Repeated at `--line-length +40`, `--indent 4`, and both together: 0 idempotency failures and 0 unexpected +exit codes (always 0 or 1) across all four sweeps × 800 files. + +**Printer `fits()` change, isolated.** Built `0557933` (pre-both-commits) +with only `crates/vlog_formatter/src/printer.rs` replaced by the `a4f8476` +version, and diffed its output against the unmodified `0557933` binary over +the *entire* 820-file corpus (not just the 800 that currently pass, since the +old parser accepts a different set): **0 files differ.** The `fits()` change +is a no-op for every layout in this corpus that doesn't involve a multi-line +`Doc::Inline`, which is what the change was scoped to. + +**Byte-identical-output claim, verified against the correct baseline.** +Built `e35da29` (this feature's own commit, before the "Fix round-1 QA +findings" commit) and diffed its output against `a4f8476` over the 800 +currently-passing files: **0 differ**, confirming the sibling commit's "800 +passing files byte-identical against the pre-change binary" claims in the +assertions/bind READMEs (their baseline is `e35da29`, i.e. this commit, not +`0557933`). + +**One thing worth recording, not a defect.** Diffing `0557933` (before +*either* commit) against `a4f8476` (after both) over the 800 passing files +shows 7 differences, not 0: 4 are files this commit newly rescues from a +parse/lex error (expected — see Status/TODO), and 3 +(`corpus/ibex/dv/formal/check/peek/mem.sv`, +`corpus/ibex/vendor/lowrisc_ip/ip/prim/dv/prim_esc/tb/prim_esc_tb.sv`, +`corpus/opentitan/hw/ip/uart/dv/env/seq_lib/uart_loopback_vseq.sv`) passed +*before* this commit too but now format differently. Traced it: `at_macro_item` +is also called from `take_list_directives`, i.e. its hoisted line rule reaches +into connection/port-list contexts, not only the module/statement-item case +the Assumptions section describes. In all three files a macro that expands to +several named connections stands on its own source line, followed by a +`.name(...)` connection on the next line; before this commit the parser read +the two as one continued expression (`` `MACRO ``, then `.name(...)` as a +dot-postfix on it) and the formatter joined them onto one line, which is +arguably a misparse of the author's intent. After this commit each is +correctly read as its own list element, matching the source's own line +break. Confirmed safe: all three still verify, still round-trip, still +idempotent — this is a behavior change worth a line in Assumptions (the +"whatever kind of token opens the next line" rule reaches list-directive +contexts too, not just item/statement position) but not a bug. Not fixed +here since it's documentation, outside QA's remit to redesign. + +**Findings: nothing blocking.** No corruption, no idempotency failure, no +panic, no swallowed error, and no gap in `verify.rs`'s forgiveness found +under attack. The one item above is a documentation gap (Assumptions doesn't +mention the list-directive blast radius), not a code defect. + ## Review