# testbench-mopup ## Goal Close the small, well-scoped grammar gaps `syntax_coverage.md` left after the testbench-syntax wave's three big rounds — its own ranked recommendation #3, "sweep the small, well-scoped grammar gaps as one mop-up round". Nine shapes, **47 OpenTitan files** blocked between them, no two of which share a parser path: a block-scoped `typedef` statement, a system function call used as a casting type, enum member ranges, a cast applied to an assignment pattern, a gate's multi-value delay list, a modport-qualified virtual interface type, `rand` on a plain struct member, a `foreach` with a skipped dimension, and a hierarchical path in a `bind`'s instance list. None of these is a new *kind* of thing lucisv must model. In every one the new surface is data the source already laid out — a bracket, a qualifier word, a modport suffix, one more delay value — so there is no layout decision in any of them, and the printer work is "put the bytes back where they were". That is why they were worth bundling: nine independent one-function changes with one build/sweep/corpus/README overhead, exactly as `mop-up-2` did for an earlier grab-bag. Result: the OpenTitan sweep goes **88 → 43** failures, 45 files clean, 2 advanced to a different documented bucket, **zero** newly failing. ## Assumptions ### The corpus is the specification, and it disagreed with the analysis twice Every bucket was re-read at its real `file:line` before anything was written, and two of the brief's bucket labels did not survive that reading: - **Bucket 6 is not drive strengths.** `syntax_coverage.md` §6 called the nine `unsupported cast base expression` files "`weak0'(...)`/`pull1'(...)` as a cast base". A `grep` for that spelling across all 3,943 files finds **zero** occurrences. The eight files that actually raise that message are all a **system function call** used as the casting type — `$bits(periph_data_mux)'({...})` (`pinmux.sv:490`, three tops) and `$clog2(RomSize)'(RomSize)` (`pulp_riscv_dbg`, five files) — which is a `constant_primary` and therefore legal `casting_type` per IEEE 1800 §6.24.1. That is the gap this round fixed. The ninth file (`spi_host/dv/tb.sv`, `unexpected keyword \`weak1\``) is a genuinely different construct and is **skipped** — see Status. - **Bucket 12 is six files, not five.** The five `spid_*_tb.sv` declarations are joined by `spid_common.sv:563`, where the same type stands in a task's argument list and so raises a different message. Both corrections are recorded here rather than in `syntax_coverage.md`, which is not this worktree's file. ### No verbatim capture, so invariant 4 does not engage Every shape here is **real grammar**: parsed into ordinary nodes and printed by the ordinary printer. Nothing in this round captures source bytes and replays them, so there is no new `RawText`, `verify.rs` is untouched, and the standing "masked-corruption attack tests for a widened normalization" requirement has nothing to attach to. What replaces it is the ordinary safety net: all 45 newly-formatting files went through `format_source`'s own token-equivalence and convergence checks, and the whole-tree output diff below shows the change is a strict superset of the old behaviour. ### Costing the AST changes against topo §2.2 The brief's instruction was to avoid new AST variants where a span-preserving existing shape serves. Seven of the nine buckets needed **no** new AST surface at all; the two that did were costed: | bucket | AST change | exhaustive arms it cost | |---|---|---| | 4 local `typedef` stmt | **new variant** `StmtKind::Typedef(Typedef)` | 3 — `format.rs`, `bind.rs`, `spans.rs`. `visit.rs`, `type_def.rs`, `linked.rs`, `selection.rs` all have wildcards and needed nothing. | | 6 system-fn cast base | none | none | | 8 enum member range | new field `EnumMember::range: Vec` | 2 — `parse_enum_type`, the enum printer (`spans.rs` gained a check, not an arm) | | 10 cast-to-pattern | new field `ExprKind::Cast::pattern: bool` | 2 — the `format.rs` arm and the `spans.rs` arm; the four other `Cast` sites already used `..` | | 11 gate delay list | `GateInstantiation::delay: Option` → `Vec` | 3 — `format.rs`, `bind.rs`, `spans.rs` | | 12 virtual+modport | none (the modport is glued into `DataType::name`) | none | | 14 rand on struct | new field `StructMember::qualifiers: Vec` | 1 — the struct printer | | 15 foreach skip dim | none (an empty `Name`) | none | | 16 bind hier path | none (dots glued into the instance `Name`) | none | `StmtKind::Typedef` is the one place a new variant was the right call rather than a dodge: the statement form *is* the item form — same payload, same layout, same binding — so reusing `Typedef` and adding one dispatch arm is both smaller and more honest than any encoding that avoided the variant. ### Why `Cast` needed a flag and could not just look at its argument The obvious zero-cost encoding of `ty'{...}` is `Cast { ty, expr: AssignPattern(..) }` with the printer noticing that the argument is a pattern and printing no brackets. It is wrong, because `ty'('{a: 1})` produces exactly the same tree and would then print as `ty'{a: 1}` — a different token stream, which the safety net would (correctly) refuse, turning a file that formats today into one that does not. Neither corpus contains that spelling today, but "nothing writes it yet" is not a reason to build a shape that cannot represent it. One `bool` on the variant costs two edits and makes the two spellings distinguishable by construction; `the_two_cast_spellings_over_a_pattern_stay_distinct` pins it. ### The deliberate over- and under-acceptances - **`is_cast_base` admits only *system* function calls.** A constant function call is a legal casting type too, but no file in either corpus writes one, and admitting `f(x)'(y)` would also admit a mis-read of a method call followed by an unrelated sized literal. Pinned by the negative half of `a_system_function_call_may_be_a_casting_type`. - **A multi-value delay list is refused off gates.** IEEE 1800 allows `assign #(1,2) y = x;` and `wire #(1,2) w;` too, but neither corpus writes one and widening `ContAssign`/`DataDecl` to `Vec` would cost arms for nothing. `parse_delay_value` now says which construct may write a list instead of failing at the comma; pinned by `a_multi_value_delay_is_refused_where_only_a_gate_may_write_one`. - **`EnumMember::range` is a `Vec`, so `A[1][2]` is accepted** even though the LRM allows one dimension. The field is echoed, never interpreted, so the extra permissiveness costs nothing and reusing `parse_dims`/`self.dim` is smaller than a bespoke one-dimension parser. - **`rand` on a struct member is not LRM-legal at all** (randomization qualifiers belong to class properties). It is in the corpus, vendor tools take it, and lucisv models no randomization semantics either way, so the words are carried and printed and nothing else happens. - **The modport widening is scoped to `virtual`.** `bus_if.mp v;` without `virtual` still refuses, which is the exact thing `docs/features/ansi-first-port/README.md` was protecting when it left this open — a `.` after a bare identifier still reads as a member access everywhere. Pinned by `a_dot_after_a_plain_type_name_is_still_not_a_modport`. ## Handshakes **Consumed, unchanged:** - `types-decls` — `parse_typedef`, `parse_dims`, `parse_opt_data_type`, `parse_modport_port_type`. All four are called from one new place each; none changed behaviour for its existing callers. - `ansi-first-port` — `at_modport_port`, the `Ident . Ident Ident` lookahead written for interface ports, reused verbatim as the modport-suffix test in the two `virtual` positions. - `expressions-2` — the `'{...}` assignment-pattern parse, lifted out of `parse_primary`'s symbol match into `parse_assign_pattern` **with no change to its body**, so that a cast can reach it. `parse_primary` now calls it instead of inlining it. - `bind` — `BindDirective::instances: Vec`, unchanged in type. That feature's own README already flagged the shape ("`instances: Vec` doesn't carry per-instance structure beyond a bare name list; the fix is the same shape — accept a dotted path per instance name"); this round does exactly that, and the promise `bind` made — the instance list is printed verbatim from its names — still holds. - `error-recovery` — untouched. Nine constructs that now parse produce no error nodes, so there is nothing to recover from; the tolerant improvement below is a pure consequence. - `verify.rs` — untouched, and no capture added. Invariant 4 does not engage. **Promised to others:** - **`StmtKind::Typedef` binds in the enclosing block scope**, via the same `Binder::bind_typedef` the item form uses. A `typedef` written inside a `begin`/task/function therefore contributes a type symbol scoped to that block, which is what IEEE 1800 §6.18 asks for and what a language server wants. - **A skipped `foreach` dimension declares nothing.** It arrives as a `Name` with empty text and a zero-width span at the point the source wrote nothing; `Binder::declare` already ignores empty names, so this falls out rather than needing a guard. Anything that iterates `Foreach::vars` and assumes each is a real variable must skip empty ones — `bind.rs` is the only such consumer today and it does. - **A `bind` instance name may now contain `.`.** Any consumer treating `BindDirective::instances[i].text` as a single identifier must accept a dotted path. `spans.rs`'s name check was widened to the same modulo-whitespace comparison the `bind` target already used; no other consumer reads the field. - **A `virtual` type's `name` may now contain `.`** (`spi_if.tb`), exactly as an interface port's already could. Same contract, one more position. **Requests to the lead (not acted on):** 1. `docs/features/ansi-first-port/README.md`'s Status lists `virtual bus_if.mp v;` as a deliberate non-goal. That is now stale — this round closes it, narrowly. The pinning test in `parser.rs` was updated in place (it still pins the half that remains open, the generic `interface` port, plus the bare-identifier case the old reasoning was really about), but the other feature's README is not this round's file. 2. `syntax_coverage.md` bucket 6's description is a mis-diagnosis (see Assumptions). It is untracked and outside this worktree; the correction is recorded here. ## Status / TODO - [x] Bucket 4 — block-scoped `typedef` statement (10 files). - [x] Bucket 6 — a system function call as the casting type (8 files). - [x] Bucket 8 — enum member ranges `Name[N]` / `Name[hi:lo]` (6 files). - [x] Bucket 10 — a cast over an assignment pattern, `ty'{...}` (6 files). - [x] Bucket 11 — a gate's `#(rise, fall[, turn-off])` delay list (5 files). - [x] Bucket 12 — `virtual iface.modport name` (6 files). - [x] Bucket 14 — `rand`/`randc` on a plain struct member (3 files). - [x] Bucket 15 — `foreach` with a skipped dimension (2 files). - [x] Bucket 16 — a hierarchical path in a `bind`'s instance list (1 file). - [x] OpenTitan sweep 88 → 43, set difference: **0 newly failing**. - [x] Corpus gate 813/820 — the exact baseline, and byte-identical output on all 817 corpus files. - [x] Whole-tree output diff: zero output change on any of the 3,896 previously-passing OpenTitan files. - [x] Tolerant mode measured before and after; no file got worse. - [x] 14 parser unit tests, 1 tolerant regression test, 3 new `spans.rs` `SOURCES` entries, 9 formatter cases in a new `mopup_round.cases`. - [x] `cargo fmt` / `cargo clippy --all-targets` / `cargo test --workspace`. - [ ] **Skipped, deliberately: a gate's drive strength** (`pullup (weak1) pd_in_i (...)`, `spi_host/dv/tb.sv:101`, **1 file**). This is the ninth file `syntax_coverage.md` §6 lumped in with the cast bases, and it is a different production: `n_output_gatetype [drive_strength] [delay2]`, plus the single-strength `pullup_strength` spelling `(weak1)` that `parse_opt_drive_strength` — which requires a comma-separated pair — cannot express. Closing it needs **two** AST changes for one file: `DriveStrength::second` widened to `Option` (with an arm wherever a strength is printed) and a new `strength` field on `GateInstantiation`. Judged disproportionate against a bundle whose other eight buckets each cost at most one field; it is a clean, bounded follow-up whenever a second file wants it. - [ ] **Not done, out of scope:** the next blocker behind two of this round's files — `iff` in an event control (`spid_common.sv:1042`, `spid_upload_tb.sv:304`), which is a distinct unbucketed shape, not a regression. ## Work log ### 2026-08-29 — dev (mop-up round) **Method.** Every bucket was read at its real `file:line` in `/Users/guoliangchen/repo/opentitan` (read-only throughout) before a line was written, using a script that resolves each sweep failure's reported position back to its source. That is what caught the two mis-diagnoses recorded in Assumptions — bucket 6 is not the construct the analysis named, and bucket 12 has a sixth file. **Baseline.** 88 failures over 3,943 files on trunk `7f65a24`, not the 151 of `syntax_coverage.md` (which predates the wave's three merged rounds) nor the "~99" of the brief. Recorded per-file with its message so every later claim is a set operation, not a count comparison. **The nine changes, each in one function.** 1. **Local `typedef` statement.** One dispatch arm in the statement-keyword match calling the existing `parse_typedef`, plus `StmtKind::Typedef`. The formatter arm is `self.typedef(t)` with no `;` appended, because the item printer already writes one. All four typedef spellings (enum, struct, alias, `typedef class`) reach statement position for free, since it is the same function. 2. **System function call as a casting type.** The cast-base whitelist moved out of an inline `matches!` into `is_cast_base`, which adds one arm: `Call` whose callee is an `Ident` starting with `$`. (`$bits` lexes as `TokenKind::SystemIdent` and parses to `ExprKind::Ident("$bits")`, so the test is a string prefix, not a new token concept.) 3. **Enum member ranges.** `EnumMember::range: Vec` filled by the existing `parse_dims`, printed by the existing `self.dim` — tight against the name, with no leading space, because the bracket is part of the name rather than a dimension standing beside it. The range is parsed *before* the `= value`, so `C[16] = 5` keeps both. 4. **Cast over an assignment pattern.** Two edits: `at_postfix_segment` now treats `'{` as a postfix segment when the base may stand left of a cast (so a bare `'{...}` literal still reaches `parse_primary` as a whole expression), and the cast branch builds `Cast { pattern: true }` over the pattern. The pattern parse itself was **lifted verbatim** out of `parse_primary` into `parse_assign_pattern` so both callers share it; the `start` it is handed is the `'{`'s own position, so the pattern's span excludes the casting type and span nesting stays strict. 5. **Gate delay list.** `parse_delay_value` split into `parse_delay_values` (the general form) and a one-value wrapper for nets and continuous assignments. The one-value parenthesized spelling still produces the same `ExprKind::Paren` node it always did, which is what keeps `#(5)` printing as `#(5)` and `#(1:2:3)` as itself — only a real comma list yields more than one element, and only then does the printer write its own parens. `GateInstantiation::delay` became `Vec`. 6. **Modport-qualified virtual interface.** Two positions, because a declaration and a type position take different routes: `parse_data_decl` (where `virtual` has already gone into `qualifiers`) tests `at_modport_port` before calling `parse_opt_data_type`, exactly as `parse_ansi_port` does; `parse_opt_data_type` itself tests it right after consuming its own `virtual`. Both glue the modport into `DataType::name`, so nothing downstream needs a second field. 7. **`rand` on a struct member.** A `while` over `rand`/`randc` before the member's type, into a new `qualifiers: Vec` mirroring `DataDecl`'s, printed the same way. 8. **`foreach` with a skipped dimension.** `expect_name` replaced by `parse_foreach_var`, which returns an empty `Name` at the current position when the slot is empty. `join_names` then prints nothing for it, which is exactly `[, bank]`. 9. **Hierarchical `bind` instance.** `parse_bind_instance` glues a dotted path into one `Name`, the same three lines `parse_bind` already used for its target. **One pinned test had to change.** `the_two_shapes_left_open_by_ansi_first_port_still_refuse` asserted that `virtual bus_if.mp v;` refuses. That was a deliberate non-goal recorded by `ansi-first-port`, whose stated reason was that "a modport-qualified *declaration* type would change how a `.` after an identifier reads everywhere". This round's version does not do that — it reads the modport only after `virtual` — so the test now pins the half that is still true (`bus_if.mp v;` without `virtual` still refuses), with a comment naming this feature. Flagged in Handshakes as a request, not edited into the other feature's README. **Measured on the real OpenTitan checkout** (3,943 `.sv`/`.svh`, `--no-cache --check`, read-only; `git status --porcelain` in the corpus unchanged before and after, still showing only the pre-existing `hw/ip/aes/dv/tb/tb.sv` modification from an earlier session). | | before | after | |---|---|---| | files failing (whole sweep) | 88 | **43** | | files this round's nine buckets blocked | 47 | 0 | | of those, now fully clean | — | **45** | | of those, advanced to a *different* bucket | — | 2 | | **files that newly fail (set difference)** | — | **0** | The two advances are `spid_common.sv` and `spid_upload_tb.sv`, both of which now get past the modport type and stop on `iff` in an event control — a distinct shape no bucket in this round covers. Every other still-failing file's message is byte-identical to its message before. **Strict-superset check, done as an output diff rather than a count.** Both binaries (trunk and this worktree) were run over every file in both corpora and their stdout compared byte for byte: | | files | outputs that differ | |---|---|---| | pinned corpus | 817 | **0** | | whole OpenTitan tree | 3,943 | 47 — and all 47 are files that were *failing* before (45 now format, 2 changed error) | So no previously-passing file's formatting moved by a single byte. This is the check that matters for a grammar widening: a count could hide a file that started formatting differently while another started failing. **Idempotency** on the 45 newly-clean files: formatted through stdin twice and diffed, **45 idempotent, 0 not**. (`format_source` runs its own convergence check on every call, so a non-idempotent output would already have been refused; this is the independent confirmation.) **Corpus gate.** `scripts/corpus_gate.sh`: `{"passing":813,"total":820,"pct":99.1,...}` — the recorded baseline exactly, 0 verification errors, 0 crashes, no score movement in either direction. **Tolerant mode**, probed with a standalone crate path-depending on this worktree's `vlog_parser` and calling `parse_source_tolerant` directly (the method `syntax_coverage.md` documents; `lucisv check`'s exit code deliberately discards `ParseDiagnostic`s). Run over the 88 before-failing files plus a 25-file control sample of always-clean files, with the fix stashed out and back in: | | before | after | |---|---|---| | total diagnostics, 88 failing + 25 control | 1 644 | **1 290** | | over the 45 files this round fixed | 147 | **0** | | control sample (25 clean files) | 0 | 0 | | files whose count got **worse** | — | **0** | | `spid_common.sv` (worst cascade here) | 207 | 2 | | `flash_ctrl_env.sv` (×2) | 28 | 0 | | `spi_host_env_pkg.sv`, `ast.sv`, `flash_ctrl_env_pkg.sv` (×2) | 6 | 0 | `spid_common.sv` is the round's one real cascade collapse: a modport-qualified type in a task's argument list wrecked the recovery for the rest of a 1,000-line file. It still reports 2 (the `iff` gap), but the buffer went from unusable to two honest points. **Tests added.** - `crates/vlog_parser/src/parser.rs`, test module, new section — 14 tests: `a_typedef_is_a_statement_inside_a_block`, `a_typedef_statement_carries_the_same_payload_as_the_item`, `a_system_function_call_may_be_a_casting_type` (with the negative half: an ordinary call still refuses), `an_enum_member_may_carry_a_name_range`, `a_cast_may_be_applied_to_an_assignment_pattern`, `the_two_cast_spellings_over_a_pattern_stay_distinct`, `a_gate_takes_a_multi_value_delay_list`, `a_multi_value_delay_is_refused_where_only_a_gate_may_write_one`, `a_virtual_interface_type_may_name_a_modport`, `a_dot_after_a_plain_type_name_is_still_not_a_modport`, `a_struct_member_may_be_declared_rand`, `a_foreach_may_skip_a_dimension`, `a_bind_instance_may_be_a_hierarchical_path`, and the amended `the_two_shapes_left_open_by_ansi_first_port_still_refuse`. - `crates/vlog_parser/tests/error_recovery.rs`: `the_mopup_shapes_report_nothing_in_tolerant_mode` — all nine shapes in one buffer, asserting **zero** tolerant diagnostics and strict/tolerant agreement. - `crates/vlog_parser/tests/spans.rs`: three new `SOURCES` entries covering all nine shapes, picked up for free by that file's existing exhaustive walkers (byte coverage, span nesting, name-span slicing, token reconstruction); plus a range check on `EnumMember::range`, a delay walk on `GateInstantiation`, the `StmtKind::Typedef` arm, and the widened `bind`-instance name comparison. The item-level typedef span check was extracted into `check_typedef` so the statement form reuses it rather than copying it. - `crates/vlog_formatter/tests/cases/mopup_round.cases` (new file): 9 cases, one per bucket, including the `ty'('{...})` round-trip that pins the two cast spellings apart and the `#(5)`/`#5`/no-delay gate spellings that pin the delay printer's one-value path. The harness asserts expected output *and* idempotency per case. **Gates.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` clean (0 warnings, no `#[allow]`); `cargo test --workspace` green; corpus gate 813/820. No `git commit`, no `git push`. **Deviations from the brief.** One skip, declared in Status: the gate drive-strength file (`pullup (weak1) ...`), which the brief inherited from `syntax_coverage.md`'s bucket-6 label. It is a different production from the cast bases that label named, and it costs two AST changes for one file. The eight files that label actually described are fixed. ## QA log ### 2026-08-29 — QA (mop-up round) **Verdict: SHIP**, with one real-but-narrow finding filed below (LOW severity — LSP-only, no corruption/safety-net risk) and no other defects found after an adversarial pass over all nine buckets. Every headline number in the Work log was independently reproduced from scratch (not re-derived from the dev's own scripts/output) using two freshly-built release binaries (trunk `7f65a24` in a separate worktree, this round's tree) and read-only sweeps. **Incident, disclosed up front.** My first attempt at the whole-tree "strict superset" check ran `lucisv --no-cache ` (no `--check`) directly over all 3,943 real OpenTitan files, not realizing that spelling rewrites the file **in place** (`crates/lucisv/src/main.rs:280`, `std::fs::write`). This reformatted ~3,759 files in `/Users/guoliangchen/repo/opentitan` before I caught it via `git status`. Recovery: `git stash push -u` (preserving the damage for forensic inspection if ever needed, `stash@{0}`, message "QA accidental mutation recovery snapshot"), then the working tree came back byte-identical to committed HEAD `0098135` via the stash. Net effect: the corpus is now **cleaner** than before my mistake — the README's noted "one pre-existing uncommitted modification to `hw/ip/aes/dv/tb/tb.sv` from an earlier session" is gone too, since it was never committed and I could not disentangle it from my own accidental reformat after the fact. It was already flagged as unrelated to any analysis, so nothing this round relied on is affected, but the lead and the user should know the corpus is no longer bit-for-bit what earlier sessions left it as. All further reproduction below used **read-only** stdin/stdout mode (`lucisv - < file`) or `--check`, verified after every sweep with `git status --porcelain` returning empty. **1. Reproduced the OpenTitan sweep from scratch (88 → 43).** Built trunk `7f65a24` in `git worktree add --detach .../scratchpad/trunk-base` and this round's tree, ran `--no-cache --check` over all 3,943 `.sv`/`.svh` files with both binaries (writing each file's exit code + message to its own file, not a shared stream — my first pass shared one output file across 8 parallel workers and silently interleaved partial lines; per-file output fixed it). Results: **trunk 88 failing, new 43 failing, 0 newly failing, 45 newly fixed** — exact match. Confirmed the two "advanced to a different bucket" files by diffing their messages directly: `spid_common.sv` moved from `563:19: expected `)` (found ".")` to `1042:19: expected `)` (found "iff")`, `spid_upload_tb.sv` from `30:17: expected `;` (found ".")` to `304:21: expected `)` (found "iff")` — both exactly the line numbers and shape the Work log names. **2. Reproduced the strict-superset / zero-output-movement claim, at full tree scale (stronger than the dev's own methodology).** Using stdin/stdout mode (never touches disk), diffed both binaries' formatted stdout across all 3,943 files: of the 3,855 files trunk formats successfully, **0** differ in the new binary — byte-for-byte and exit-code-for-exit-code identical. Exactly 45 files flip from error to success; nothing else moves. This is a full-tree check, not sampled — a stronger version of the dev's own 817-file corpus check, which I also ran independently (see 4). **3. Reproduced idempotency (45/45).** Round-tripped each of the 45 newly-clean files' formatted output back through the new binary a second time via stdin/stdout (no disk writes): 0 not idempotent. **4. Reproduced the corpus gate.** `scripts/corpus_gate.sh ~/.cache/lucisv-corpus` → `{"passing":813,"total":820,"pct":99.1,...}`, 0 verification errors, 0 crashes — the exact recorded baseline. Separately diffed stdin/stdout output for all 860 `.sv`/`.v`/`.svh`/`.vh` files under `~/.cache/lucisv-corpus` between trunk and new: **0 differ**. **5. Reproduced the tolerant-mode table, and extended it to the whole tree.** Built two tiny standalone binaries path-depending on each worktree's `vlog_parser` (trunk and new) calling `parse_source_tolerant` directly, matching the dev's own methodology. Over the 45 newly-fixed files: **147 → 0**, 0 files worse — exact match. Then ran the same probe over **all 3,943** OpenTitan files (not just the dev's 88-failing + 25 control sample): total diagnostics **1,644 → 1,290** (matches the dev's reported total exactly, confirming their 88+25 sample already accounted for every file with any diagnostics at all), **0 files worse anywhere in the whole tree**, 47 improved (the 45 plus the two advanced files, whose `spid_common.sv` cascade reproduced at exactly **207 → 2** and `spid_upload_tb.sv` at **9 → 7**). **6. Reproduced the skip.** `spi_host/dv/tb.sv` still fails, message unchanged (`unexpected keyword` `weak1``-shaped), confirmed identical between trunk and new in the byte-for-byte message diff in step 1/2 — not a half-parse, exactly as claimed. **7. Blast-radius audit.** For each new variant/field, grepped every match on the enclosing type across all crates (not just the four files the dev's README names) and read every wildcard's body, not just its existence: | Type/field | Consumer | Verdict | |---|---|---| | `StmtKind::Typedef` | `vlog_formatter::format.rs`, `vlog_semantic::bind.rs`, `vlog_parser::tests/spans.rs` | Correct — dedicated arms, reuse `check_typedef`/`bind_typedef`/item printer. | | `StmtKind::Typedef` | `vlog_linter::visit.rs` (AST walker) | Correct — `f(stmt)` fires unconditionally before the descend-match; the new variant has no nested statements so the wildcard `_ => {}` is exactly right. | | `StmtKind::Typedef` | `lucisv_server::linked.rs`, `selection.rs` | Correct — neither construct has a closing label or nested statement to widen selection into; wildcard is right. | | `StmtKind::Typedef` | `lucisv_server::type_def.rs` (`stmt_site`) | **BUG — see Finding 1.** No arm; falls to `_ => None`. Not "needed nothing" as the dev's README states. | | `StmtKind::Typedef` (block scoping) | `vlog_semantic::bind.rs` scope tree | Correct — verified live with a standalone probe: a typedef inside `initial begin...end` resolves inside the block and does **not** leak to a sibling declaration outside it (`definition_of` returns `None` for the outer use). | | Block-scoped typedef in outline | `vlog_semantic::document_symbols` | Correct — verified live: the unnamed `initial` block bubbles its typedef/enum-variant/var children up to the module level, exactly as the "unnamed scope contributes to the enclosing level" doc comment promises. No AST-walker special-casing needed; this falls out of the generic Scope/Symbol model. | | `EnumMember::range` | `format.rs`, `spans.rs` | Correct — printed tight against the name, span-checked. | | `EnumMember::range` | `lucisv_server` (hover/completion/inlay/tokens) | Correct — none read the AST field directly; all go through the `Symbol`/`Reference` model, which is unaffected. | | `StructMember::qualifiers` | `format.rs` | Correct — printed before the type. | | `StructMember::qualifiers` | Every `lucisv_server`/`vlog_semantic` consumer of `StructMember` | Correct — all key off `SymbolKind::StructMember` (semantic model) or `.declarators`, never `.ty`'s qualifiers. | | `GateInstantiation::delay: Vec` | `format.rs`, `bind.rs`, `spans.rs` | Correct — dedicated loops replace the old `Option` arm. | | `GateInstantiation::delay` | `vlog_semantic::instantiations.rs`, `vlog_linter::signals.rs` | Correct — neither reads `.delay` at all (gates are explicitly excluded from the hierarchy census; signals only reads `.instances`). | | `ExprKind::Cast::pattern` | `format.rs`, `spans.rs` | Correct — dedicated arm for `pattern: true`; `spans.rs` walks both `ty` and `expr` regardless of the flag. | | `ExprKind::Cast::pattern` | `bind.rs`, `vlog_linter/signals.rs` | Correct — both already used `..` and only ever touch `expr`, never `ty`; unaffected by the flag. | | `ExprKind::Cast::ty` when it is now a `Call` (`$bits(x)'(y)`) | `bind.rs` | **Not a regression** — `bind.rs`'s `Cast` arm has *never* bound `ty` for any shape (documented: "resolving \[type names\] is the work this crate does not do anywhere else either"), so `$bits(periph_data_mux)` inside a cast base gets no more and no less binding than `(NumLevels)'(x)` did before this round. Parity holds; flagged only for the record. | **Finding 1 — LOW severity, LSP-only, no corruption risk.** `crates/lucisv_server/src/type_def.rs`'s `stmt_site` (used by `textDocument/typeDefinition`) has explicit arms for `VarDecl`, `ParamDecl`, `PortDecl`, `Block`, `If`, `Case`, `Labeled`, `For`/`While`/ `DoWhile`/`Repeat`/`Forever`/`Foreach`, `Timing`/`Wait`, `Assert` — and a wildcard `_ => None` for everything else, which now silently includes `StmtKind::Typedef`. The item-level twin (`alias_site`, called from `item_site`'s `ItemKind::Typedef` arm) already does the right thing one level up; `stmt_site` was never given the matching arm. *Reproduction* (built as a temporary test, verified, then reverted so the tree matches what ships): ```rust let text = "\ module m; typedef enum logic { A, B } state_t; task run(); typedef state_t alias_t; alias_t x; endtask endmodule "; jumps(&ws, &uri, at(text, "alias_t;")) // cursor on the block-scoped alias's own name ``` Expected (by analogy with the item-level test `an_alias_chain_is_walked_one_hop_at_a_time`, which pins exactly this one-hop jump at item scope): `[(1, 30)]` (state_t's declaration). Actual: `[]` — empty, no jump. Confirmed by direct build/run against this round's `lucisv_server`, not just static reading. *Why LOW, not blocking*: fails safe (empty result, not a panic or a wrong jump), affects only the "go to type definition" hop from a block-scoped typedef's own alias name to what it aliases — a narrow, rare gesture even among LSP users. Does not touch any hard invariant (no corruption, no crash, `cargo test` stays green because no test exercised this exact path). Does not block this round; recommend a one-line follow-up (`StmtKind::Typedef(t) => alias_site(t, stmt.span),` mirroring the item arm) whenever `lucisv_server` is next touched. Not fixed directly here since `type_def.rs`/`lucisv_server` is outside this round's file ownership (`vlog_parser`/`vlog_formatter`/`vlog_semantic`/`TODO.md`/the new `docs/features/testbench-mopup/` + `mopup_round.cases`), so it is recorded here rather than silently patched. **8. Production-widening attacks (all held).** - `is_cast_base`: zero-arg system call (`$clog2()'(x)`) — accepted, consistent with "echoed, not interpreted." An escaped identifier spelled `\$foo` does **not** false-positive the `$`-prefix check: the lexer's escaped-identifier token text retains the leading backslash (`crates/vlog_parser/src/lexer.rs:301-313`), so `n.starts_with('$')` is false for it — confirmed by reading the lexer, not just the parser. - Multi-value delay: refused on `wire #(1,2) w;` and `assign #(1,2) y = x;` (already pinned); also confirmed every other delay call site (`# delay` timing control, blocking-assignment timing, `event control`) routes through the single-value `parse_delay_value`, not the new `parse_delay_values` — grepped all 6 call sites. - `virtual pkg::iface_t.mp v;` (a scope, not a plain ident, before the dot): `at_modport_port` requires `Ident "." Ident Ident`; `::` is a distinct token from `.`, so this cleanly falls through to the ordinary type path and refuses at the stray `.mp` rather than misreading it — under-accepts, never corrupts. - `EnumMember::range` accepts more than the documented over-acceptance: besides nested dims (`A[1][2]`, documented), a dynamic-array dim (`A[]`) and a wildcard dim (`A[*]`) also parse, since `range` reuses the general-purpose `parse_dims`. Undocumented, but harmless by the same "echoed, never interpreted" argument the dev already made for the documented case — not filing as a separate finding. - `rand`/`randc` on a struct member with a preceding attribute (`(* attr *) rand bit cpol;`) refuses with a parse error. Verified this is **pre-existing**, not a regression: the identical shape without `rand` (`(* attr *) bit cpol;`) already refuses on trunk. Attributes on struct members were never supported; this round didn't change that. **9. Comment/round-trip hostile variants.** A comment wedged directly between a new production's leading token and the next real token (e.g. `rand /* c */ bit cpol;`, `buf /* c */ #(1,2) b(o,a);`, `typedef /* c */ enum bit {A} e_t;`, a comment inside a `foreach` skipped slot) each trip `verify.rs`'s token-equivalence check and refuse cleanly (exit 2, empty stdout, no corruption) rather than corrupt — invariant 1 holds. Confirmed this is **not new to this round**: the identical "comment between a qualifier and the next token" shape already fails the same way on trunk for pre-existing constructs (`rand /* c */ int x;` in a class, `input /* c */ logic a;` in a port list, `wire /* c */ #(1) w;`). This is a known, systemic, pre-existing formatter limitation (comments are only guaranteed preserved at recognized attachment points — leading/before-separator/trailing — not at arbitrary mid-construct positions), extended consistently rather than newly introduced. Not filing as a mop-up-specific finding. CRLF line endings round-trip correctly and idempotently through the new gate-delay and typedef-statement productions together. **Gates**, re-run independently in this worktree: `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` clean (0 warnings); `cargo test --workspace` → **2,604 passed**, 0 failed, 36 ignored (summed across every crate's test binaries) — matches the claimed count exactly. **Tests added**: none needed as permanent additions — every hostile variant I tried either matched existing pinned behavior (comment mid-construct: pre-existing, already implicitly covered by the general verify.rs safety net) or is the one real finding above, which is an LSP gap outside this round's file ownership and is recorded rather than patched. No masked-corruption attack tests were needed per invariant 4, because this round adds no new normalization to `verify.rs` (confirmed: `git diff` touches no file under that path). ## Review **2026-08-29 — lead.** Reviewed after QA's SHIP; gates re-run on the worktree. Nine buckets, seven of them zero-new-AST-surface, one disciplined skip with the cost argument written down, and two corrections to the wave's own analysis document — reading the real file:line before believing the bucket label is exactly the discipline the brief asked for. QA's blast-radius audit earned its place: the missing `stmt_site` arm for `StmtKind::Typedef` was a real product gap behind a compiling wildcard, precisely the failure mode the charter named, and the lead applied the one-arm fix with its regression test in this merge. QA's incident — an in-place format of the owner's opentitan checkout via a missing `--check` — was disclosed immediately, recovered via stash with the owner's one uncommitted file restored token-faithfully by the lead, and produces a standing rule: QA charters against real checkouts run `--check`/`--stdout` ONLY, and `git status` the checkout after every sweep. The whole-tree strict-superset check (0 of 3,855 previously-passing files' output moved) is stronger than the round claimed for itself and is the right bar for parser waves. Accepted; merged by the lead. OpenTitan sweep: 151 at the wave's start, 43 after this round.