# directives-in-lists ## Goal Accept `` `ifdef``/`` `ifndef``/`` `else``/`` `elsif``/`` `endif``, `` `define``, `` `include`` — and standalone macro invocations — written *between the elements* of a module header's port list, its parameter port list, and an enum member list. They were already accepted wherever a module item or a statement belongs (`macro-items`); a port list was the one place real RTL writes them that vfmt refused. This is README roadmap item 6, and its named payoff is the workspace index: `picorv32`, `picorv32_axi` and `picorv32_wb` were the index's biggest named gaps (570 external references) because their headers hold an `` `ifdef`` inside the port list, which swallowed the whole `module` declaration into an error node so the module never indexed. **Result: all three now index (521 → 530 modules, 8044 → 9174 exported members), the workspace answers 87.0 % → 93.6 % of external candidates on cleanly-parsed corpus files, two more corpus files format, six more advance past this construct to their next blocker, zero regressions, and `verify.rs` is byte-identical to `HEAD`.** ## Assumptions - **vfmt does not evaluate the condition, and this feature does not change that.** Both arms of an `` `ifdef``/`` `else`` contribute their elements to the one list, in source order, exactly as an `` `ifdef`` at item position already contributes both arms' items. The formatter is a text tool; a preprocessor is a different program. - **A directive is line-oriented, and the lexer captures it to end of line.** That is a pre-existing shape (`docs/features/macro-items/README.md`) and it is load-bearing here twice over: a directive can only stand *between* elements, and nothing the formatter emits may share its line. The direct consequence is that the one-line spelling `` module m (a, `ifdef X b, `endif c); `` is **not** supported — the lexer reads `` `ifdef X b, `endif c); `` as a single directive token. Every corpus file writes the directive on its own line; see Status/TODO for why the lexer was left alone. - **The comma placement is data, not a formatting choice.** Between two elements there is exactly one `,`, but a directive in that gap can sit on either side of it. Both spellings are real: `picorv32` writes `eoi,` ⏎ `` `ifdef RISCV_FORMAL`` (comma before the directive), and `prim_sparse_fsm_flop.sv` writes `` `ifdef SIMULATION`` ⏎ `,` (comma after it, so that both arms stay legal). See Design for why the comma is stored rather than derived. - **An `` `ifdef`` arm need not end with a comma.** `` `ifdef X`` ⏎ `input a` ⏎ `` `else`` ⏎ `input b` ⏎ `` `endif`` is two elements and no comma at all. A list that commas every element but the last would add one, and the safety net would refuse the file. - **A directive inside an *element* stays a parse error**, by design and out of scope: `input` ⏎ `` `ifdef X`` ⏎ `logic` ⏎ `` `endif`` ⏎ `a` is a declaration cut in half, not a list with a directive in it. Pinned by `a_directive_inside_an_element_is_still_a_parse_error`. - **A macro invocation between elements is disambiguated by the existing `at_macro_item` rule**, not a new one. So `` `MY_TYPE_T sig`` is still a port whose type is a macro, and `` `VECTOR_INCLUDE("x.sv")`` before an enum member is a standalone entry. The one shape that rule gets wrong is unchanged and inherited: a *parameterized* macro type (`` `SOME_TYPE(8) sig``) reads as a standalone invocation. No corpus file writes one. - **Blank lines inside a bracketed list are dropped**, directives included — that is the pre-existing `delimited_dangling` rule, not something this feature chose. ## Handshakes **New in `vlog_parser::ast` (consumed by `vlog_formatter::format`):** ```rust pub struct ListDirective { pub raw: RawText, // the directive line (or macro invocation), verbatim pub meta: Meta, // comments before it, and the one after it on its line pub before: usize, // index of the element it was written before pub comma: bool, // a `,` was written after *it*, not after the element } ``` | carrier | new field | |---|---| | `Module` | `param_directives: Vec` | | `Module` | `port_directives: Vec` — on the module, not inside `PortList`, because a list whose every element sits in an arm is still a `PortList::Empty` | | `EnumType` | `directives: Vec` | | `NonAnsiPort`, `AnsiPort`, `ParamPort`, `EnumMember` | `comma: bool` — whether a `,` followed this element in the source | **Every change is additive; no variant grew and no vector changed type.** That was the deciding constraint on the shape: `vlog_semantic::bind` and `vlog_linter`'s `explicit_parameter_storage_type` iterate `m.param_ports`, `PortList::Ansi(ports)` and `e.members` directly, so folding directives into those vectors (`enum PortEntry { Port(..), Directive(..) }`) would have forced edits in two crates outside this feature's scope. A parallel vector keyed by `before` preserves source order just as well and costs those crates nothing — **they were not recompiled against a changed API, only against new fields they ignore**. New parser helper: `Parser::take_list_directives(&mut Vec, before) -> Harvested`, the list-element twin of `parse_item_kind`'s directive arm. It is a **no-op unless the cursor is on a directive or a standalone macro invocation**, deliberately copied from `take_before_sep` / `take_before_open`: that is why a change reaching four parse loops left all 315 pre-existing `.cases`, every snapshot and every pre-existing test byte-for-byte green. Pinned by `a_list_with_no_directive_keeps_an_empty_directive_vector`. New formatter helpers: `Fmt::list_entries` (interleaves elements and directives back into source order; returns the elements untouched when there are no directives) and `Fmt::directive_entry`. `ListItem` gained `comma: Option` (`None` = "decide from the position", which every list that cannot hold a directive keeps) and `directive: bool` (a directive's comma starts a new line). **Consumed from `verify.rs`: nothing new. No normalization was added, broadened or weakened** — `git diff --quiet -- crates/vlog_formatter/src/verify.rs` exits 0, so CLAUDE.md hard invariant #4 does not bind this round. Nine tests were added to `tests/verification.rs` anyway — eight **rejection** tests, one per corruption this plumbing could plausibly produce, plus one asserting the legitimate re-indent is still accepted. The comma problem was solved by making the parser record what it read, not by teaching the net to forgive a moved comma; if it ever tempts someone to widen `normalize`, those eight tests are what the widening has to survive. **Multi-line directives ride the existing `RawText.col` path.** A `` `define`` with a `\` continuation inside a parameter port list is emitted by `Fmt::raw_text`, dedented by `col - 1` and re-indented by the printer — the same contract `ItemKind::Directive` and `Meta::attrs` already have, including the string-crossing verbatim fallback. Nothing about `verify::line_starts_inside_string` changed; it is still the single definition of which line breaks are data. **Format fences (`docs/features/format-fences/README.md`): unchanged.** `fence::scan_scope` walks item-level leading comments only, so a `// vfmt: off` written before a list directive opens no region — exactly as it opened none when the same comment landed in the first port's `meta.leading`. `fence.rs`, `tests/fences.rs` and `fences.cases` are untouched and green. **Recursion/chain budgets (`docs/features/recursion-limit/README.md`):** unaffected, and no budget is charged. A `ListDirective` is an AST **leaf** — it holds a `String`, not a `Box` — so it adds no root-to-leaf depth, and `take_list_directives` is a flat `while` over already-lexed tokens. Nesting `` `ifdef`` inside `` `ifdef`` costs nothing structurally: the arms are not nested in the AST, they are consecutive entries of one flat list. **Spans (`docs/features/spans/README.md`):** `ListDirective.raw.span` is the directive's own token range, which nests inside the enclosing item's span. The `spans.rs` walker checks all three buckets, and two sources holding list directives were added to its `SOURCES` table so `every_node_span_nests_inside_its_parent` and the token-coverage tests cover them. **Not touched, by scope:** `crates/vfmt`, `crates/vfmt_core`, `crates/vfmt_server`, `crates/vlog_linter`, `crates/vlog_semantic`, `crates/vlog_formatter/src/verify.rs`, `editors/`, `tools/`, `corpus/`. A second agent was working in `vfmt_server` and `vlog_linter` concurrently; both crates compile and their tests pass against this diff unmodified. `cargo fmt` was run per-package (`-p vlog_parser -p vlog_formatter`) rather than `--all`, so it could not rewrite the other agent's files. ## Design ### The comma problem, and why the comma is stored rather than derived The obvious cheap rule — *an element gets a `,` unless it is the last one* — is what every other list in the formatter uses, and it is wrong here in two directions: | source | positional rule prints | verdict | |---|---|---| | `A = 1` ⏎ `` `ifdef S`` ⏎ `,` ⏎ `B = 2` ⏎ `` `endif`` (`prim_sparse_fsm_flop.sv`) | `A = 1,` ⏎ `` `ifdef S`` ⏎ `B = 2` | the comma hopped across the directive | | `` `ifdef X`` ⏎ `input a` ⏎ `` `else`` ⏎ `input b` ⏎ `` `endif`` | `input a,` ⏎ `` `else`` ⏎ `input b` | a comma invented that the source never wrote | Both are token-stream changes, so both would be *refused* rather than corrupting — but a file vfmt refuses is a file vfmt cannot format, and the second shape is ordinary RTL. A derivation rule that consults the gap's directives handles the first case and still fails the second, so it was rejected as clever-and-wrong. The shipped rule is one sentence: **every entry records whether a `,` followed it in the source, and the formatter prints what it recorded.** For a list with no directive that is exactly `i < last`, which is why not one of the 315 pre-existing cases moved. The element flag lives on the four element structs; the directive's own flag lives on `ListDirective`. Two consequences worth stating: - A trailing comma before the closing bracket (`module m (a, );`) is still a parse error. The loop only continues past a comma into another element or a directive; `` `ifdef X`` ⏎ `` `endif`` ⏎ `)` after a comma is malformed Verilog in every arm and is refused as before. - The comma that a directive carries is printed on its **own line**, because anything on the directive's line is swallowed into the directive token by the lexer. That is what `ListItem::directive` is for, and `a_comma_swallowed_into_a_list_directive_is_rejected` is the test that pins the failure mode. ### Parser — one loop shape, three lists ```rust loop { elements.push(self.parse_element()?); self.take_before_sep(&mut last.meta, ","); let comma = self.eat_sym(","); last.comma = comma; let dirs = self.take_list_directives(&mut directives, elements.len()); if (!comma && !dirs.any) || (dirs.any && self.cur().is_sym(CLOSE)) { break; } } ``` The two break conditions are the whole grammar change: - **no comma and no directive** — the list is over, as it always was; - **a directive, and then the closing bracket** — the arm was the tail of the list (`` `ifdef VERILATOR`` ⏎ `input clk` ⏎ `` `endif`` ⏎ `)`). Anything else keeps reading elements, which is what lets an `` `else`` arm follow an arm that wrote no comma. Directives before the *first* element are harvested once before the loop, because both the ANSI/non-ANSI decision and the written-but-empty check read the token after them. ### Formatter — an entry is a `ListItem` `Fmt::list_entries` merges the elements and the directives by `before` into the vector `delimited_dangling` already takes, so the layout, the comment plumbing, the dangling bucket and the fence handling are all the existing code. A directive entry differs in exactly three ways: its doc is `raw_text(&d.raw)`, its comma comes from the source, and its trailing comment goes in `before_sep` (which is where the source put it — between the directive and any comma that follows it) rather than in `trailing`. `force_break` is set whenever a list holds a directive. It is not cosmetic: a single-line directive is a plain `Doc::Text`, so nothing else would force the group open, and a flat `(a, `ifdef X, b)` would fuse three tokens into one. ## Status / TODO - [x] `ListDirective` + `comma` on the four element structs; every change additive so `vlog_semantic` and `vlog_linter` need no edit. - [x] `Parser::take_list_directives`, wired into the parameter port list, the ANSI port list, the non-ANSI port list and the enum member list. - [x] Both comma placements (before and after the directive) round-trip; both shapes come from real corpus files. - [x] `` `else``/`` `elsif`` arms, nested `` `ifdef``, `` `define`` and `` `include`` in a list, a list that is nothing but one arm, a header with directives in both its lists. - [x] Standalone macro invocations between elements, via the existing `at_macro_item` predicate (`` `VECTOR_INCLUDE("...")`` between enum members, `riscv_instr_pkg.sv`). - [x] 20 cases in `crates/vlog_formatter/tests/cases/directives_in_lists.cases` (315 → 335 overall); idempotency asserted by the harness. - [x] 7 parser unit tests, 9 `tests/verification.rs` tests (8 of them rejection tests), 2 new `spans.rs` sources + walker coverage. - [x] `verify.rs` byte-identical to `HEAD`; hard invariant #4 does not bind. - [x] `cargo test --workspace` 563 passed, clippy silent, fmt clean, `tools/corpus_check.sh` exit 0 with 0 verification errors and 0 crashes. - [ ] **Not done — the same construct in an instantiation's lists.** Six corpus files write `` `ifdef``/`` `include``/`` `define`` inside a module instantiation's `#( ... )` parameter overrides or its `( ... )` connection list: `ibex_lockstep.sv:518`, `ibex_top.sv:456`, `spec_instance.sv:65`, `picorv32/testbench.v:164`, `picorv32/testbench_wb.v:110`, `picorv32/scripts/torture/testbench.v:41`. Same shape, same solution, different parse loops; out of this round's stated scope. This is the obvious next slice and it is the single biggest remaining directive-shaped blocker. - [ ] **Not done — the one-line spelling** `` module m (a, `ifdef X b, `endif c); ``. The lexer captures a directive to end of line, so this is one token, not five. Shortening the capture for the five conditional directives (which take at most one argument) would fix it, but it changes what `ItemKind::Directive`/`StmtKind::Directive` hold for every file in the tree and would make code after a directive on the same line newly *parsed* rather than passed through — a lexer round of its own. No corpus file writes it; every one puts the directive on its own line. - [ ] **Not done — a directive between an element's own tokens.** Out of scope by design; see Assumptions. Clean parse error, never output. - [ ] **Known refusal, not corruption:** a directive with a trailing comment *and* a comma after it (`` `ifdef X // why`` ⏎ `, port`) prints the comment and the comma in the source's order only when the comment comes first; the reverse spelling is refused by the net. Nothing in the corpus writes either. ## Corpus results `./tools/corpus_check.sh corpus`, release build, script exit status **0**. Corpus verified unmodified afterwards (`git status --porcelain` clean in all four repos except the untracked `.vfmt-corpus-rev` stamp). Two runs, TSVs byte-identical (deterministic). | outcome | before (`3a503e1`, the tree this work started from) | after | |---|---|---| | ok-unchanged | 8 (1.0 %) | 8 (1.0 %) | | would-reformat | 460 (56.1 %) | **462 (56.3 %)** | | parse-error | 352 (42.9 %) | **350 (42.7 %)** | | verification-error | 0 | **0** | | other-error | 0 | 0 | | crash | 0 | 0 | | **parsed & formattable** | 460/820 (56.1 %) | **470/820 (57.3 %)** | TSV md5 `aa982463f68c1a3568c02a0fc5e0c455` → `31ffdb18c96d4e79057178f7de269756`. **By-path delta, diffed by file path rather than by count: 2 files moved `parse-error` → `would-reformat`, 0 files moved the other way, and no file that already parsed changed category.** The two: | file | before | after | |---|---|---| | `corpus/ibex/rtl/ibex_core.sv` | `parse-error` 127:1, `` `ifdef RVFI`` in the port list | `would-reformat`, round-trip idempotent | | `corpus/picorv32/scripts/csmith/testbench.v` | `parse-error` 4:1, `` `ifdef VERILATOR`` around the whole port list | `would-reformat`, round-trip idempotent | **Six more files advanced past this construct to a different, unrelated blocker** — the honest half of the ledger, and the reason the headline number is 2 and not 8: | file | was | now | |---|---|---| | `corpus/picorv32/picorv32.v` | 123:1 `` `ifdef RISCV_FORMAL`` (port list) | 2109:2 `restrict property` — roadmap item 7, concurrent assertions | | `corpus/ibex/rtl/ibex_top.sv` | 136:1 `` `ifdef RVFI`` (port list) | 456:1 `` `ifdef RVFI`` in an **instantiation connection list** | | `corpus/ibex/dv/formal/check/top.sv` | 49:3 `` `ifndef YOSYS`` (port list) | 143:1 `default clocking` — roadmap item 8 | | `corpus/ibex/vendor/lowrisc_ip/.../prim_sparse_fsm_flop.sv` | 14:1 `` `ifdef SIMULATION`` (parameter list) | 48:32 a `for` header declaring two variables | | `corpus/ibex/vendor/google_riscv-dv/src/riscv_instr_pkg.sv` | 651:5 `` `include`` (enum members) | 1214:41 `$`-bound in a range | | `corpus/picorv32/scripts/torture/testbench.v` | 2:1 `` `ifdef VERILATOR`` (port list) | 41:1 `` `include`` in an **instantiation parameter list** | Two of those six are the instantiation-list gap parked under Status/TODO. ### picorv32, stated plainly **`picorv32.v` still does not format**, and it will not until roadmap item 7 lands: its header now parses, and the file gets 1986 lines further before hitting `restrict property (...)` inside `` `ifdef FORMAL``. The brief named picorv32/picorv32_axi as the acceptance target because of what the *index* could not see, and that half is fully delivered — the index uses `parse_source_tolerant`, so a module whose header parses is indexed even when a later item does not: | unit | `HEAD` | after | |---|---|---| | `picorv32` | **0 defs** | 1 (`corpus/picorv32/picorv32.v`) | | `picorv32_axi` | **0 defs** | 1 (same file) | | `picorv32_wb` | **0 defs** | 1 (same file) | | `picorv32_pcpi_mul` | 1 | 1 (unchanged control — it has no directive in its header) | ### Workspace index / semantic resolution `cargo test -p vlog_semantic --test workspace -- --nocapture the_corpus_index_finishes_most_external_references`, same 860-file scan, run on a `HEAD` worktree and on this tree: | metric | `HEAD` | after | |---|---|---| | modules indexed | 521 | **530** | | packages | 63 | 63 | | file-scope typedefs | 38 | 37 | | exported members | 8 044 | **9 174** | | `` `define`` directives | 502 | 502 | | external candidates answered (every file) | 81.4 % | **86.9 %** | | external candidates answered (cleanly-parsed files) | 87.0 % | **93.6 %** | | unresolved-external rate, all references (every file) | 3.6 % | **2.6 %** | | unresolved-external rate, all references (clean files) | 2.6 % | **1.3 %** | The +1130 exported members are mostly picorv32's four modules' ports and parameters, which had never been indexed. The one *lost* file-scope typedef is a `riscv_instr_pkg.sv` enum that used to be recovered at file scope out of an error node and is now parsed inside its package, where it belongs — a correction, not a loss. ## Work log ### 2026-08-19 — dev agent - Read `CLAUDE.md`, `README.md`, and the `macro-items`, `workspace-index`, `comments-round-2` and `spans` READMEs before touching code. Baseline on this working tree: `cargo test --workspace` **547 passed** (the brief's 524 is the `comments-round-2` figure; the concurrent `server-lint` work, since committed as `2ba995d`, had already added tests to the same tree), clippy silent, fmt clean, corpus TSV md5 `aa982463f68c1a3568c02a0fc5e0c455`, exit 0. All before/after comparisons below are against `3a503e1`, the commit this work branched from; `2ba995d` landed alongside it and touches neither `vlog_parser` nor `vlog_formatter`. - **Measured the actual shapes before designing anything.** Ran the corpus check first and pulled every parse error whose "found" token starts with a backtick: 12 files, in four distinct shapes. That is what turned the comma problem from a hypothetical into a requirement — `prim_sparse_fsm_flop.sv` writes the comma *inside* the `` `ifdef`` arm, which no positional rule can reproduce, and `ibex/dv/formal/check/top.sv` writes an arm with no comma at all. - **Tried the cheap derivation first and rejected it with a counterexample, not a hunch.** "An element takes the gap's comma unless a directive in that gap carries it" handles `prim_sparse_fsm_flop` and still invents a comma between two `` `else`` arms. Storing the flag is three more struct fields and no reasoning at all at print time, so it won. - **Chose a parallel `Vec` over one entry enum because of the crates I am not allowed to touch.** `vlog_semantic::bind` and the `explicit_parameter_storage_type` lint iterate the element vectors directly; changing `Vec` to `Vec` would have required edits in two out-of-scope crates. `before: usize` preserves source order just as well. Recorded under Handshakes so the next reader does not re-litigate it. - **The `` `else``-arm case is what forced the second break condition.** The first draft continued the list only when a comma had been written (element's or directive's), which parses `picorv32` fine and dies on `` `ifdef X`` ⏎ `a` ⏎ `` `else`` ⏎ `b` ⏎ `` `endif``. The fix — keep reading unless the closing bracket is next — also makes the "list is one arm" shape work, which is what `picorv32/scripts/csmith/testbench.v` writes, and it is why `module m (a, );` is still a parse error: that break is only reachable when a directive was actually harvested. - **The sharpest hazard is a comma printed on a directive's line.** The lexer captures a directive to end of line, so `` `ifdef S, `` is *one* token: the comma would vanish into the condition. Handled by `ListItem::directive` forcing a break before the comma, and pinned by a rejection test rather than by prose. - **Extended the harvest to standalone macro invocations** because `riscv_instr_pkg.sv` writes `` `VECTOR_INCLUDE("...")`` between enum members, reusing `at_macro_item` rather than inventing a second disambiguation rule. That predicate already declines bare `` `TYPE name``, so macro-typed ports keep parsing as ports. - **Left the lexer alone**, deliberately, which costs the one-line spelling the brief used as its illustration. Shortening the directive capture is a cross-cutting change (it decides what every `ItemKind::Directive` in the tree holds and would newly *parse* code written after a directive on the same line); no corpus file needs it. Written up under Assumptions and Status/TODO instead of half-done. - **`verify.rs` was never opened.** The comma problem is a parser bookkeeping problem, and solving it by teaching the net to forgive a moved comma is precisely the move CLAUDE.md invariant #4 exists to stop. `git diff --quiet -- crates/vlog_formatter/src/verify.rs` exits 0; the eight rejection tests are there so a future round has to argue with them. - **Verified the corpus delta by path, not by count** (2 gained, 0 lost, 0 category changes among already-parsing files) and read all six still-failing files' new errors to confirm each is an unrelated construct. Ran the corpus check twice — byte-identical TSVs. All four corpus repos confirmed unmodified. - **Measured the index payoff against a real `HEAD` worktree**, not against memory: built a detached worktree at `3a503e1`, ran the same `WorkspaceIndex` probe in both, and confirmed `picorv32`/`picorv32_axi`/ `picorv32_wb` go from **0 defs to 1** while the control (`picorv32_pcpi_mul`, whose header has no directive) is 1 in both. The probe test was deleted from both trees afterwards; `git status` confirmed clean. - **Reported the picorv32 acceptance honestly**: the file still does not format, because of `restrict property`. The brief's stated payoff (the index) is delivered; the formatting half is blocked behind roadmap item 7 and saying otherwise would be a lie the numbers would catch. - Did not touch `crates/vfmt_server`, `crates/vlog_linter`, `crates/vlog_semantic`, `crates/vfmt*`, `tools/` or `corpus/`. Ran `cargo fmt -p vlog_parser -p vlog_formatter` rather than `--all` so the concurrent agent's files could not be rewritten. Did not run `git commit`/`git push`. **Results:** `cargo test --workspace` **563 passed, 0 failed** (547 baseline + 7 parser unit + 9 verification; the 20 new `.cases` entries run inside the existing `case_tables` test, which now covers 335 cases). `cargo clippy --workspace --all-targets` silent. `cargo fmt --all --check` clean. `tools/corpus_check.sh corpus` exit 0, 0 verification errors, 0 crashes. Files touched: `crates/vlog_parser/src/{ast,parser}.rs`, `crates/vlog_parser/tests/spans.rs`, `crates/vlog_formatter/src/format.rs`, `crates/vlog_formatter/tests/cases/directives_in_lists.cases` (new), `crates/vlog_formatter/tests/verification.rs`, `README.md` (roadmap item 6), `TODO.md` (§6 workspace-index annotation), this README. ## QA log ### 2026-08-19 — QA agent **Verdict: PASS. No blocking findings.** All five claims verified; two minor documentation nits filed below (non-blocking). **Gates.** `cargo test --workspace`: **563 passed, 0 failed** (exact match). `cargo clippy --workspace --all-targets`: silent. `cargo fmt --all -- --check`: clean. `git diff --quiet -- crates/vlog_formatter/src/verify.rs`: exit 0 (byte-identical to `HEAD`). Same for `fence.rs`, `tests/fences.rs`, `fences.cases`: all diff-clean. **Cross-crate untouched claim.** `git diff --stat crates/vlog_semantic crates/vlog_linter crates/vfmt crates/vfmt_core crates/vfmt_server` is empty. `crates/vfmt_server/` and `crates/vlog_linter/` are untracked (concurrent agent's work per the README) so nothing to diff there either; both compiled and their tests passed as part of the 563. **Corpus.** `tools/corpus_check.sh corpus`, release build, ran twice: byte-identical TSVs, md5 `31ffdb18c96d4e79057178f7de269756` both times, exit 0 both times. Table matches exactly: 8 ok-unchanged, 462 would-reformat, 350 parse-error, 0 verification-error, 0 crash, 470/820 formattable. Corpus repos confirmed clean afterwards (`git status --porcelain` in each of the four, only the untracked `.vfmt-corpus-rev` stamp). Spot-checked every by-path claim directly against the TSV and the source files: - `ibex_core.sv` → `would-reformat` ✓; `csmith/testbench.v` → `would-reformat` ✓. - `picorv32.v` → `parse-error 2109:2: expected declaration or instantiation (found "restrict")`; read the source at that line — it is `restrict property (...)` inside `` `ifdef FORMAL``, exactly as claimed. - `ibex_top.sv` → `456:1` `` `ifdef RVFI`` — read the source, it is inside an instantiation's connection list (`.rvfi_valid,` follows). `top.sv` → `143:1` `default clocking`. Both match. - Read all 6 "parked — instantiation lists" files at their cited locations (`ibex_lockstep.sv:518`, `ibex_top.sv:456`, `picorv32/testbench.v:164`, `picorv32/testbench_wb.v:110`, `picorv32/scripts/torture/testbench.v:41`, plus confirmed `spec_instance.sv` exists at the stated path) — every one genuinely has a directive inside `#( ... )` or `( ... )` of an instantiation, not a header. **Semantic re-measurement.** Ran `cargo test -p vlog_semantic --test workspace -- --nocapture the_corpus_index_finishes_most_external_references` on this tree: 530 modules, 63 packages, 37 file-scope typedefs, 9174 exported members, 502 defines, 86.9%/93.6% answered (every-file/clean-file), 2.6%/1.3% unresolved (every-file/clean-file) — **exact match** to every number in the README's "after" column. **Independently reproduced the `3a503e1` baseline** in a detached worktree (`git worktree add --detach 3a503e1`, corpus symlinked in) rather than trusting the README's "before" column: 521 modules, 38 typedefs, 8044 members, 87.0%/2.6% (clean-file answered/unresolved) — exact match to the claimed "before" figures, and `picorv32`/`ibex_top` show up in that tree's "still unresolved" list but not in the after-tree's. Also added a temporary probe test (`WorkspaceIndex::units(name).len()`) to both trees, ran it, then reverted (`git checkout --` in this tree; worktree deleted) — `picorv32`/`picorv32_axi`/`picorv32_wb`: **0 defs → 1 defs**, control `picorv32_pcpi_mul`: **1 → 1** (unchanged), confirming the index payoff directly rather than by proxy. `git status --porcelain` clean in this tree afterward; worktree removed. **Round-trip torture on the new construct.** Wrote 20 probe files covering every requested shape (ifdef at first/middle/last position in ports, params, and enums; an `` `elsif``/`` `else`` chain; 3-deep nesting; the `prim_sparse_fsm_flop` comma-inside-the-arm shape; a no-comma `` `else`` pair; a list that is one arm and nothing else — `PortList::Empty` with `port_directives`; a directive immediately before the closing paren; two adjacent directives (`` `ifdef``+`` `define``); a `` `define`` with a `\` continuation inside a parameter list; an arm element carrying a trailing comment; an enum with `` `include`` + a macro invocation between members; a non-ANSI header with directives). Ran each through the debug binary via `vfmt -` for 3 passes (`vfmt(vfmt(vfmt(x)))`); every pass exited 0 (which already means `format_source`'s internal `verify_equivalence` + `verify_convergence` accepted it — no corruption, no dropped comment/token possible on a 0 exit) and pass2==pass3 byte-for-byte on all 20. Eyeballed 6 of the trickier outputs directly (comma-inside-arm, no-comma-else, every-element-in-arm, define-continuation, enum-include+macro, non-ANSI) — all correct: no invented/lost comma anywhere, comment on the arm element survived, `` `define`` continuation stayed properly dedented/reindented, `` `include`` and the macro invocation both preserved in source order. **Sabotage round (both reverted, diff-verified clean afterward).** 1. Removed `|| item.directive` from the `ends_line` computation in `format.rs` (the forced-break that keeps a directive's comma off the directive's own line). Result: `cargo test -p vlog_formatter` immediately failed — not silently — inside `case_tables`, at exactly `directives_in_lists.cases:202` ("the comma written after the directive, not before it"), with diagnostic `token stream diverges at index 9: input has directive "`ifdef SIM" at 3:1, output has directive "`ifdef SIM," at 3:3`. This is `format_source`'s internal `verify_equivalence` catching the comma-fusion hazard live, exactly as the README's Design section predicts. The 8 hardcoded `verification.rs` rejection tests did **not** fail under this sabotage (expected — they exercise `verify.rs` directly with literal strings and don't touch the formatter's `list_entries`/`ListItem` plumbing; `verify.rs` was correctly never touched by this feature). Reverted the one line; `cases_tables`, clippy, and `git diff --stat format.rs` (109 insertions/19 deletions, matching the original) all confirm a clean revert. 2. Injected an invented comma into the `` `else``-arm case at `directives_in_lists.cases:56` ("neither arm's last port writes a comma"). `case_tables` failed immediately with a precise line diff. Reverted; `case_tables` green again. Re-ran the full corpus check after both sabotage/revert cycles: still byte-identical to `run1.tsv`, same md5, corpus repos still clean. **`module m (a, );` still a parse error** — confirmed directly: `./target/release/vfmt --check` on that exact input exits 2 with `expected identifier (found ")")`. **Findings (both non-blocking, documentation only):** - `README.md` roadmap item 6's strike-through text says picorv32/ picorv32_axi/picorv32_wb "now index" and lists the still-open instantiation gap, but never explicitly states that `picorv32.v` itself still fails to *format* (blocked on `restrict property`, roadmap item 7) — that fact only appears in this feature's own README ("picorv32, stated plainly"). Nothing in `README.md` is false, but a reader of just the top-level roadmap line could come away thinking picorv32 now formats. Did not fix (touches a file outside this agent's QA-log-only write scope); flagging for the lead. - No other findings. Design, parser loop, formatter forced-break, spans coverage, and every numeric claim (corpus, semantic, index) checked out exactly, including independent reproduction of the `3a503e1` baseline. ## Review **2026-08-19 — lead. Verdict: accepted and committed. The workspace index's biggest named gap closes: cross-file external resolution 93.6% on clean files, unresolved externals halved to 1.3%.** Points reviewed and accepted: 1. **The stored-comma decision is the round's load-bearing judgment**, and it was made the right way: two real corpus shapes (comma-inside-the-arm vs no-comma `else` alternatives) kill any derivation rule in opposite directions, so the parser records what was written and the formatter reproduces it. `Option` with `None` = positional is why all 315 pre-existing cases stayed byte-identical — the take_before_sep pattern's third successful application. 2. **Parallel ListDirective vectors over an entry enum** because the entry enum would have forced edits in two out-of-scope crates (vlog_semantic, vlog_linter) — QA confirmed both compile and pass unmodified. Choosing the shape by its blast radius is the architecture discipline working. 3. **The comma-on-directive-line hazard** (a printed comma the lexer would swallow into the condition) prevented structurally by a forced break, and QA's sabotage confirmed the net catches it at the exact case if the break is removed. 4. **No overclaim**: picorv32 parses 1986 lines further and its modules index (the actual payoff), but the file still refuses on `restrict property` — stated plainly, and the lead has added that caveat to the top-level roadmap per QA's nit. The parked follow-ups are the next round's shape: directives in instantiation `#()`/connection lists (6 named corpus files — the biggest remaining directive blocker), the one-line spelling (a lexer round of its own), and the shared fence helper filed by server-lint.