Files
lucisv/docs/features/directives-in-instances/README.md
T

563 lines
32 KiB
Markdown

# directives-in-instances
## Goal
Accept `` `ifdef``/`` `ifndef``/`` `else``/`` `elsif``/`` `endif``, `` `define``,
`` `undef``, `` `include`` — and standalone macro invocations — written *between
the elements* of a module **instantiation**'s parameter override list `#( ... )`
and of an instance's connection list `( ... )`. This is the slice the
`directives-in-lists` round parked under Status/TODO and its Review named as the
next round's shape: same construct, same solution, different parse loops. Six
corpus files were blocked on exactly this, and it is the single biggest
remaining directive-shaped blocker.
## Assumptions
Everything `directives-in-lists` assumed still holds and is not re-argued here;
read that README's Assumptions first. The ones specific to this round:
- **A directive is line-oriented.** Inherited. So the one-line spelling
``u #(.A(1), `ifdef X .B(2), `endif .C(3)) i ();`` is still unsupported — the
lexer reads from `` `ifdef`` to end of line as one token. No corpus file
writes it.
- **Both arms contribute.** `` `ifdef``/`` `else`` arms are both ordinary
entries of the one list, in source order. lucisv does not evaluate conditions.
- **A *comment* may share a directive's line, but a comma may not.** The
lexer's directive capture stops before a `//` or `/*`
(`crates/vlog_parser/src/lexer.rs:182`), so `` `endif // why`` round-trips as
two pieces, while `` `endif,`` would come back as one token whose condition
is `,`. This asymmetry is what lets a before-`)` comment print inline on the
directive's line while the directive's comma is forced onto a new one.
- **The comma is data, not a formatting choice.** Same two directions as last
round, and instantiations write both: `picorv32/testbench.v` puts the comma
*inside* the arm (`.ENABLE_REGS_DUALPORT(0),` ⏎ `` `endif``), and
`ibex_lockstep.sv` ends an arm with no comma at all before `` `endif``.
- **A connection list that is nothing but a directive is still a list.**
`picorv32/scripts/torture/testbench.v` writes ``#(`` ⏎ `` `include "config.vh"``
⏎ ``)`` — zero elements, one directive. That is why the directive vector
cannot live inside `Connections`, whose "no elements" spelling is
`Connections::Ordered(vec![])`.
- **Gate instantiations are out of scope, by measurement.** No corpus file
writes a directive between the arguments of a gate instance; see
Status/TODO for the grep that says so, and why the shape would need a
different vehicle (`ExprItem`, shared with every other expression list).
- **A directive between an instance *name* and its `(`, or between two
instances of one declaration, is still a parse error.** Out of scope; the
construct this feature accepts is a directive standing where a list
*element* would start.
## Handshakes
**New in `vlog_parser::ast` (consumed by `vlog_formatter::format`), all
additive — no variant grew, no vector changed type:**
| carrier | new field |
|---|---|
| `Instantiation` | `param_directives: Vec<ListDirective>` |
| `Instance` | `conn_directives: Vec<ListDirective>` — on the instance, not inside `Connections`, because a list whose every element sits in an arm is still an empty `Connections::Ordered` |
| `Connection`, `OrderedConn` | `comma: bool` — whether a `,` followed this element in the source |
`ListDirective` itself is reused verbatim from `directives-in-lists`
(`raw`/`meta`/`before`/`comma`); no field was added and its meaning is
unchanged. So is `Parser::take_list_directives`, whose no-op-unless-on-a-
directive contract is what keeps every pre-existing case byte-identical.
**Why the connection-list vector lives on `Instance` and not on
`Connections`** — the same blast-radius argument the last round made, checked
again rather than assumed:
- `vlog_semantic::bind` (`crates/vlog_semantic/src/bind.rs:412,417`) matches
`Connections::Named(conns)`/`Connections::Ordered(conns)` and iterates the
vector. `crates/vlog_parser/tests/spans.rs:485,492` does the same.
- Nothing outside `vlog_parser::parser` **constructs** a `Connection`,
`OrderedConn`, `Instance` or `Instantiation`, so new struct fields cost those
readers nothing — verified by grep before the change and by
`cargo test --workspace` after it.
- Folding directives into the element vector (`enum ConnEntry { Conn, Directive }`)
would have forced edits in `vlog_semantic`, which is outside this feature's
scope. A parallel vector keyed by `before` preserves source order just as
well.
- Putting the vector *inside* `Connections` would need a third variant or a
field on each — and the directive-only list has no variant to hang it on.
`Instance.conn_directives` sits next to `Instance.conns` and needs neither.
`Instantiation.param_directives` has no such choice to make: `params` is an
`Option<Vec<Connection>>` on `Instantiation` already, so its directive vector
goes beside it, exactly as `Module.param_directives` sits beside
`Module.param_ports`.
**Consumed from `verify.rs`: nothing new. `crates/vlog_formatter/src/verify.rs`
is byte-identical to `HEAD`** (`git diff --quiet` exits 0), so CLAUDE.md hard
invariant #4 does not bind this round either. Rejection tests for the new
shapes were added to `tests/verification.rs` anyway, so that a future round
tempted to widen `normalize` has to argue with them.
**Format fences: untouched.** `crates/vlog_formatter/src/fence.rs`,
`tests/fences.rs` and `fences.cases` are diff-clean. `fence::scan_scope` walks
item-level leading comments, and `format.rs`'s fence interaction points
(`Fmt::item_seq`, `Fmt::verbatim`) were not edited — the two functions this
round changed (`Fmt::instantiation`, `Fmt::connections`) do not call into
`fence`. A second agent is refactoring `fence.rs` concurrently; `format.rs` was
re-read immediately before each edit.
**Recursion/chain budgets:** unaffected and nothing charged. A `ListDirective`
is an AST leaf (a `String`, not a `Box<Expr>`), and `take_list_directives` is a
flat `while` over already-lexed tokens. A nested `` `ifdef`` costs no depth: the
arms are consecutive entries of one flat list, not nested nodes.
**Spans:** `ListDirective.raw.span` is the directive's own token range, nesting
inside the enclosing item's span. `crates/vlog_parser/tests/spans.rs` now walks
`inst.param_directives` and each `instance.conn_directives`, and two sources
holding them were added to `SOURCES`.
**Not touched, by scope:** `crates/lucisv`, `crates/lucisv_core`,
`crates/lucisv_server`, `crates/vlog_linter`, `crates/vlog_semantic`,
`crates/vlog_formatter/src/verify.rs`, `crates/vlog_formatter/src/fence.rs`,
`editors/`, `tools/`, `corpus/`. `cargo fmt` was run per-package
(`-p vlog_parser -p vlog_formatter`), never `--all`, so it could not rewrite the
concurrent agent's files.
## Design
### Parser — the same loop shape, two more lists
`directives-in-lists` established the shape; this round instantiates it twice
more:
```rust
self.take_list_directives(&mut directives, 0); // before the first element
if !self.cur().is_sym(CLOSE) {
loop {
list.push(self.parse_connection()?);
self.take_before_sep(&mut last.meta, ",");
let comma = self.eat_sym(",");
last.comma = comma;
let dirs = self.take_list_directives(&mut directives, list.len());
if (!comma && !dirs.any) || (dirs.any && self.cur().is_sym(CLOSE)) {
break;
}
}
}
```
The two break conditions are unchanged and load-bearing for the same two
reasons: an arm may end without a comma and still be followed by an `` `else``
arm, and an arm may have been the tail of the list.
The pre-loop harvest is what makes `picorv32/testbench.v` (`#(` ⏎
`` `ifndef SYNTH_TEST``) and `torture/testbench.v` (`#(` ⏎ `` `include``) work,
and in `parse_connections` it must happen **before** the `.`-peek that chooses
named vs ordered connections — otherwise `u (` ⏎ `` `ifdef X`` ⏎ `.a(x)` reads
the backtick as a positional expression, which is precisely today's error.
### The comments written before the closing `)`
The parameter-override list and the connection list have no `dangling` bucket:
comments before their `)` ride the last element's `before_sep`. With a
directive after the last element, "the last element" is no longer the last
thing in source order, so the comments would move *backwards* across the
directive. `Parser::take_last_entry_before_close` picks the last entry in
source order instead — the trailing directive when there is one, otherwise the
last element, and nothing at all when the list is empty and has no directive
(unchanged from before). Choosing the trailing directive is why a
directive-only list keeps its comments inside the parens at all.
This is deliberately *not* a new `dangling` field: adding one would move every
existing before-`)` comment in every instantiation in the corpus from the
element's line onto its own line, a formatting change for files this feature is
not about. Recorded here so the next reader does not re-litigate it.
### Formatter — nothing new, two more call sites
`Fmt::list_entries` and `Fmt::directive_entry` are reused unchanged.
`Fmt::instantiation` merges `inst.param_directives` into the override list and
`Fmt::connections` takes `&[ListDirective]` and merges them into whichever
`Connections` variant it was given. Both set `delimited`'s `force_break`
whenever the merged list holds a directive — not cosmetic: a single-line
directive is a plain `Doc::Text`, so nothing else would force the group open,
and a flat ``(.a(x), `ifdef X, .b(y))`` would fuse three tokens into one and be
refused by the net.
Every element now carries `with_comma(c.comma)` instead of letting the position
decide. For a list with no directive the parser records exactly `i < last` — the
loop only continues past a comma — which is why no pre-existing case moved.
## Status / TODO
- [x] `param_directives` on `Instantiation`, `conn_directives` on `Instance`,
`comma` on `Connection` and `OrderedConn`; every change additive, so
`vlog_semantic` and `vlog_linter` compile unmodified.
- [x] `take_list_directives` wired into the `#( ... )` override loop and into
both branches of `parse_connections` (named and ordered), plus the
pre-loop harvest in each.
- [x] Directive-only lists (`#(` ⏎ `` `include "config.vh"`` ⏎ `)`), directives
before the first / between / after the last element, nested `` `ifdef``,
`` `else``/`` `elsif``, both comma placements, `.*` beside a directive,
`` `define``/`` `undef``/standalone macro invocation between connections.
- [x] `Parser::take_last_entry_before_close` so a comment before the `)` stays
on the source's side of a trailing directive.
- [x] 24 cases appended to
`crates/vlog_formatter/tests/cases/directives_in_lists.cases`
(20 → 44 in that file, 335 → 359 overall); idempotency asserted by the
harness.
- [x] 8 parser unit tests, 7 `tests/verification.rs` tests (6 of them rejection
tests for the new shapes), 2 new `spans.rs` sources + walker coverage of
both new vectors.
- [x] `verify.rs` byte-identical to `HEAD`.
- [x] `cargo test --workspace` 589 passed / 0 failed, clippy silent, fmt clean,
`tools/corpus_check.sh` exit 0 with 0 verification errors and 0 crashes.
- [x] **All six named corpus targets format**, 0 regressions by path, and no
corpus file is blocked on a compiler directive any more.
- [ ] **Not done — gate instantiations.** No corpus file demands it. Measured
rather than assumed: a `grep -rE` over all 820 corpus files for a gate
keyword (`and`/`or`/`nand`/…/`tranif1`) opening a line without a `;` on
it — i.e. any gate instantiation spread over more than one line, which is
the only way a line-oriented directive could stand inside one — matches
exactly one line, and that line is English prose in a comment
(`corpus/ibex/dv/formal/check/peek/follower.sv:11`). It would also need a
different vehicle: gate arguments are
`Vec<ExprItem>` parsed by the shared `parse_expr_list`, which every
concatenation and call-argument list in the language also uses, so
adding a directive vector there is a much larger blast radius than two
instantiation-local loops. Filed rather than guessed.
- [ ] **Not done — the one-line spelling.** Inherited from
`directives-in-lists`; a lexer round of its own.
- [ ] **Not done — a directive between an element's own tokens**, e.g.
`.a(` ⏎ `` `ifdef X`` ⏎ `y` ⏎ `` `endif`` ⏎ `)`. Out of scope by design;
clean parse error, never output. Pinned by
`a_directive_inside_a_connection_is_still_a_parse_error`.
- [ ] **Not done — a directive between two instances of one declaration**
(`sub u0 (...),` ⏎ `` `ifdef X`` ⏎ `u1 (...);`). No corpus file writes
it; clean parse error.
## Corpus results
`./tools/corpus_check.sh corpus`, release build, script exit status **0**.
Three runs, TSVs byte-identical (md5 `0a3dad76ad648af8494dca637dbba52b` each
time).
Corpus repos verified unmodified afterwards (`git status --porcelain` clean in
all four except the untracked `.lucisv-corpus-rev` stamp).
The "before" column is **not** the previous round's published table: a second
agent's work (`shared-fence-filter`, `server-lint`) landed in this working tree
mid-session. It was re-measured on *this* tree with only this feature's three
source files stashed out, and came back byte-identical to the previous round's
TSV (md5 `31ffdb18c96d4e79057178f7de269756`) — so the delta below is entirely
this feature's.
| outcome | before | after |
|---|---|---|
| ok-unchanged | 8 (1.0 %) | 8 (1.0 %) |
| would-reformat | 462 (56.3 %) | **468 (57.1 %)** |
| parse-error | 350 (42.7 %) | **344 (42.0 %)** |
| verification-error | 0 | **0** |
| other-error | 0 | 0 |
| crash | 0 | 0 |
| **parsed & formattable** | 470/820 (57.3 %) | **476/820 (58.0 %)** |
**By-path delta, diffed by file path rather than by count: 6 files moved
`parse-error` → `would-reformat`, 0 files moved the other way, 0 files that
already parsed changed category, and 0 files advanced to a merely *different*
error.** The six are exactly the six named targets:
| file | before | after |
|---|---|---|
| `corpus/ibex/rtl/ibex_lockstep.sv` | `parse-error` 518:1 `` `ifdef RVFI`` | **would-reformat** |
| `corpus/ibex/rtl/ibex_top.sv` | `parse-error` 456:1 `` `ifdef RVFI`` | **would-reformat** |
| `corpus/ibex/dv/formal/check/spec_instance.sv` | `parse-error` 65:5 `` `define X(n) …`` | **would-reformat** |
| `corpus/picorv32/testbench.v` | `parse-error` 164:1 `` `ifndef SYNTH_TEST`` | **would-reformat** |
| `corpus/picorv32/testbench_wb.v` | `parse-error` 110:1 `` `ifndef SYNTH_TEST`` | **would-reformat** |
| `corpus/picorv32/scripts/torture/testbench.v` | `parse-error` 41:1 `` `include "config.vh"`` | **would-reformat** |
All six were re-run through `lucisv -` for three passes; every pass exited 0
(which already means `format_source`'s internal `verify_equivalence` +
`verify_convergence` accepted it) and pass1 == pass2 == pass3 byte-for-byte.
**No corpus file is blocked on a compiler directive any more.** Before this
round 6 of the 350 parse errors had a backtick as their "found" token; after it
`grep -c 'found "`' ` over the results TSV is **0**.
### Workspace index / semantic resolution
`cargo test -p vlog_semantic --test workspace -- --nocapture
the_corpus_index_finishes_most_external_references`, same 860-file scan:
| metric | before | after |
|---|---|---|
| modules indexed | 530 | 530 (unchanged) |
| packages / file-scope typedefs | 63 / 37 | 63 / 37 (unchanged) |
| exported members | 9 174 | 9 174 (unchanged) |
| `` `define`` directives | 502 | 502 (unchanged) |
| external candidates answered (every file) | 86.9 % | **87.3 %** |
| external candidates answered (clean files) | 93.6 % | **94.0 %** |
| unresolved-external rate (clean files) | 1.3 % | **1.2 %** |
Stated plainly: **the index counts did not move, and were not expected to.**
The six unblocked files are testbenches, a lockstep wrapper and a formal
harness whose module *headers* already parsed, so `parse_source_tolerant`
already indexed their modules; only their bodies were failing. The resolution
percentages move only because six more files joined the "parses cleanly"
bucket. The payoff of this round is six files that format, not a bigger index.
## Work log
### 2026-08-19 — dev agent
- Read `CLAUDE.md`, `README.md`, `TODO.md` and the whole
`directives-in-lists` README before touching code, then read all six named
corpus targets at their cited lines. They are the spec, and reading them
first is what produced the two shapes a design-from-first-principles would
have missed: a `#( ... )` whose *entire* body is one `` `include``
(`torture/testbench.v`) and a `` `define``/macro-invocation/`` `undef``
triplet standing between connections with no commas anywhere
(`spec_instance.sv:65`).
- **Baseline measured on this working tree, not taken from the last round's
README.** `cargo test --workspace` was 568 (not the 563 the brief quotes —
a second agent's `server-lint` tests had already landed), and the corpus TSV
was md5 `31ffdb18c96d4e79057178f7de269756`, matching the previous round's
published "after". One `lucisv_server` e2e test
(`fix_all_edits_exactly_what_lucisv_check_fix_edits_inside_a_fence`) was
failing mid-session; **verified it fails identically with this feature's
three files stashed out**, so it was the other agent's in-flight
`shared-fence-filter` work, not mine. It is green again in the final run.
- **Chose the vector homes by blast radius, and checked rather than assumed.**
`grep` for every construction site of `Connection`/`OrderedConn`/`Instance`/
`Instantiation` outside `parser.rs` came back empty — only pattern matches in
`vlog_semantic::bind` and `spans.rs` — so purely additive struct fields cost
the out-of-scope crates nothing. `conn_directives` went on `Instance` rather
than into `Connections` for the reason the last round put `port_directives`
on `Module`: the element-less spelling (`Connections::Ordered(vec![])`) has
no variant to hang a vector on, and `torture/testbench.v` proves that
spelling is real.
- **The pre-loop harvest in `parse_connections` must precede the `.`-peek.**
That peek is what chooses named over ordered connections; run after it, a
directive standing before the first connection is read as a positional
expression — which is verbatim today's error message
(`expected expression (found "`ifdef RVFI")`). Pinned by
`a_directive_before_the_first_connection_does_not_hide_the_dot`.
- **Found and fixed a real comment-drop while writing the cases.** The
override list has no `dangling` bucket, so comments before its `)` ride the
last element's `before_sep`; with a *trailing directive* there is no such
element. Added `Parser::take_last_entry_before_close` to pick the last entry
in source order — and then discovered `Fmt::directive_entry` **overwrote**
`before_sep` with the directive's `trailing` comment instead of appending,
so the comment vanished. The safety net caught it (`verification failed:
token stream diverges … input has comment "// nothing else"`), i.e. the file
was refused rather than corrupted — invariant #3 held — but it is now fixed
and pinned by
`a_dropped_comment_before_a_directive_only_override_lists_paren_is_rejected`.
- **Tried the wrong fix first and let a test kill it.** My first instinct was
that a comment printed on a directive's line would be swallowed by the
lexer's end-of-line capture, so I made a directive's `before_sep` comments
each start a new line. `case_tables` failed immediately at
`directives_in_lists.cases:253`, and reading `lexer.rs:182` explained why:
the capture **stops before a `//` or `/*`**. The inline placement is correct
and round-trips; the change was reverted and the comment in
`delimited_dangling` now records the fact instead of the guess.
- **Every element now records the comma it was written with**
(`with_comma(c.comma)`), replacing the positional rule, for both connection
variants and the override list. For a list with no directive the parser
records exactly `i < last`, which is why all 335 pre-existing cases and every
snapshot were green on the first run of the parser + formatter change (the
one later `case_tables` failure came from the reverted experiment above, not
from the comma).
- **Gate instantiations were measured, not guessed, before being parked.**
No corpus file writes a multi-line gate instantiation at all, so none can
hold a directive between gate arguments; and gate args are the shared
`Vec<ExprItem>`/`parse_expr_list` used by every concatenation and call in the
language, so adding a directive vector there is a far larger blast radius
than two instantiation-local loops. Filed under Status/TODO with that
reasoning rather than half-implemented.
- **`verify.rs` was never opened.** `git diff --quiet --
crates/vlog_formatter/src/verify.rs` exits 0, so hard invariant #4 does not
bind; the seven `tests/verification.rs` tests (six rejection, one
legitimate-re-indent) were added anyway so a future widening has to argue
with them.
- **Corpus delta verified by path against a same-tree baseline**, because the
tree moved under me mid-session: stashed only this feature's three source
files, rebuilt release, re-ran the corpus, and got a byte-identical TSV to
the previous round's — so every one of the 6 gains is attributable here. Ran
the final corpus twice; identical md5. All four corpus repos confirmed
unmodified.
- **Did not touch** `crates/lucisv`, `crates/lucisv_core`, `crates/lucisv_server`,
`crates/vlog_linter`, `crates/vlog_semantic`, `verify.rs`, `fence.rs`,
`tools/`, `corpus/`. Ran `cargo fmt -p vlog_parser -p vlog_formatter`, never
`--all`, so the concurrent agent's files could not be rewritten. Re-read
`format.rs` immediately before each edit; its diff contains only this
feature's hunks. Did not run `git commit`/`git push`.
**Results:** `cargo test --workspace` **589 passed, 0 failed** (568 baseline +
8 parser unit + 7 verification, plus 6 from the concurrent agent's crates; the
24 new `.cases` entries run inside `case_tables`, now 359 cases).
`cargo clippy --workspace --all-targets` silent. `cargo fmt -p vlog_parser
-p vlog_formatter -- --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`,
`crates/vlog_formatter/tests/verification.rs`, `README.md` (supported-syntax
list + roadmap item 6), `TODO.md` (§ workspace-index annotation), this README.
## QA log
### 2026-08-19 — QA agent
**Verdict: PASS, no blocking findings.**
**Scope check.** `git diff --stat` on `crates/vlog_semantic`, `crates/vlog_linter`
and `crates/vlog_formatter/src/verify.rs` all empty — additive-only claim
holds. `crates/vlog_formatter/src/fence.rs` (148 insertions) is the concurrent
`shared-fence-filter` agent's work, correctly attributed and left untouched;
did not read or write anything under `docs/features/shared-fence-filter/`.
**Design claims (1).** Confirmed by reading the diffs directly:
`Instantiation.param_directives`, `Instance.conn_directives`,
`comma: bool` on `Connection`/`OrderedConn` are all new fields (not present at
`HEAD`, i.e. not inherited from `directives-in-lists`). The pre-loop harvest
(`self.take_list_directives(directives, 0);`) in `parse_connections` sits
before the `.`-peek (`crates/vlog_parser/src/parser.rs`, the
`if self.cur().is_sym(...)` name check) — read the function directly, matches
the README's claim. Reproduced the failure the harvest prevents: with the
harvest removed conceptually (verified via the dedicated unit test
`a_directive_before_the_first_connection_does_not_hide_the_dot`, which passes
under the current code), a directive before the first connection would read
as a positional expression per the work log's cited error text.
**Round-trip torture (2, 3-pass).** 20 hand-written probe files in
`/private/tmp/.../scratchpad/torture/`: directive around first/middle/last
connection (both named and ordered), `#( ... )` with and without trailing
params, else/elsif chains, nested `` `ifdef``, comma-in-arm and no-comma-arm
both directions, connection-list-is-only-a-directive
(`Connections::Ordered(vec![])` case), params-list-is-only-a-directive,
`.*` beside a directive, directive + trailing `//` comment, directive +
comment before the closing `)` (the fixed bug's exact shape), multi-instance
with a directive in one instance's list. All 18 in-scope shapes: pass1 == pass2
== pass3 byte-for-byte, exit 0/0/0 (three separate `lucisv -` invocations via the
debug binary, not just one `--check`). The two out-of-scope shapes (gate
instance with a directive between arguments; a directive between two instances
of one declaration) both give a clean parse error and never emit output —
matches Status/TODO's documented behavior exactly, no silent misparse.
**Six named targets (3).** All six `would-reformat`, 0 backtick-blocked parse
errors corpus-wide
(`grep -c 'found "`'` over the results TSV → 0, matches). Verified the
directive lines survive formatting *by line number*: read each target at its
originally-cited line (`ibex_lockstep.sv:518`, `ibex_top.sv:456`,
`spec_instance.sv:65`, `testbench.v:164`, `testbench_wb.v:110`,
`torture/testbench.v:41`) and grepped the same directive text in
`lucisv --stdout` output — present verbatim (only re-indented) in all six.
**Corpus (3).** `tools/corpus_check.sh corpus` release build, run twice:
byte-identical TSVs, md5 `0a3dad76ad648af8494dca637dbba52b` both times —
exact match to the claim. Counts: 8 ok-unchanged / 468 would-reformat / 344
parse-error / 820 total, 476/820 = 58.0%, 0 verification-error, 0 crash — all
exact. Re-derived the "before" baseline independently rather than trusting the
README's number: stashed the six feature source files
(`ast.rs`/`parser.rs`/`format.rs`/`directives_in_lists.cases`/
`verification.rs`/`spans.rs`), rebuilt release, re-ran the corpus — md5
`31ffdb18c96d4e79057178f7de269756`, exact match to the claimed "before" hash,
8/462/350. By-path join of before vs. after: exactly 6 rows differ, all
`parse-error` → `would-reformat`, and all six are exactly the six named
targets, 0 rows moved the other direction, 0 other-category changes. Restored
the stash and rebuilt afterward; `git status --porcelain` matched the
pre-stash state exactly.
**The found-and-fixed bug (4).** Confirmed the shape: old `directive_entry`
set `before_sep: d.meta.trailing.clone().into_iter().collect()` (pure
overwrite, discarding whatever `take_last_entry_before_close` had already put
into `d.meta.before_sep`); new code clones `d.meta.before_sep` first and
`.extend()`s the trailing comment onto it. Sabotage: reverted `format.rs`'s
`directive_entry` to the overwrite form (`git diff --stat` afterward showed
identical line counts to the pre-sabotage diff, so the sabotage was a faithful
inverse). Two things worth recording precisely:
- The specific test named in the work log,
`a_dropped_comment_before_a_directive_only_override_lists_paren_is_rejected`
in `tests/verification.rs`, **does not actually pin the bug** — it calls
`verify_equivalence(input, output)` directly on a hand-authored
`(input, corrupted-output)` pair and never touches `format.rs`, so it passed
unchanged under the sabotage. This is by design per CLAUDE.md invariant #4
(an attack test on `verify.rs`'s forgiveness), just not an integration pin —
the work log's phrasing ("pinned by ... `a_dropped_comment_before...`")
slightly overstates what that specific test covers.
Not a blocking finding since the *actual* pin exists and does its job (next
bullet); recorded so the phrasing can be tightened.
- The real pin is `directives_in_lists.cases:780`
(`a comment written before the `)` of a directive-only override list`),
exercised by `cargo test -p vlog_formatter case_tables`. Under sabotage it
failed exactly as the work log describes:
`format failed: verification failed: token stream diverges at index 7: input
has comment "// nothing else" at 4:5, output has symbol ")" at 4:3` — safety
net rejects, does not corrupt, invariant #3 holds even in the sabotaged
state. Reverted the sabotage; `cargo test -p vlog_formatter -p vlog_parser`
green again, `git diff --stat -- crates/vlog_formatter/src/format.rs`
identical to before the sabotage (65 changed lines, same shape).
**Gates (5).** `cargo test --workspace`: 27+48+31+109+5+13+1+4+6+2+63+71+30+72+
24+19+17+6+1+19+20+1 = **589 passed, 0 failed** — exact match to the dev's
snapshot, no drift from the concurrent round at time of this QA pass.
`cargo clippy --workspace --all-targets`: silent, 0 warnings.
`cargo fmt -p vlog_parser -p vlog_formatter -- --check`: exit 0.
`crates/vlog_formatter/src/verify.rs`: `git diff --quiet` exits 0, byte-
identical to `HEAD`. `vlog_semantic` workspace-index re-run
(`the_corpus_index_finishes_most_external_references`): 530 modules /
63 packages / 37 typedefs / 9174 exported members / 502 defines (all
unchanged, as claimed), external-candidates-answered 87.3% (every file) /
94.0% (clean files) — exact match — unresolved-external rate on clean files
1.2% (from the printed "External-candidate rate after the workspace layer:
1.2%"), exact match. README.md and TODO.md diffs read in full: both describe
exactly this round's delta, no overstatement found (TODO.md is explicit that
the index *counts* didn't move and only the resolution percentages did,
matching the actual numbers).
**Compliance.** No `unwrap()`/`expect()`/`panic!()` in non-test code added by
this diff — all ten occurrences found in `parser.rs`'s diff are inside
`#[cfg(test)]` (`instantiation_of` helper and the eight new unit tests), which
CLAUDE.md permits. No `unsafe` introduced. New public struct fields
(`param_directives`, `conn_directives`, `comma` x2) each carry a one-line doc
comment. README has all seven required sections, all current; Work log entries
are dated and specific (file:line citations throughout). Did not touch Review.
No commit/push performed.
**Files touched by this QA pass:** none outside this README's QA log (this
section). Scratch artifacts (probe files, corpus TSVs, join diffs) live under
`/private/tmp/claude-501/-Users-guoliangchen-repo-verilogrustformatter/9ecac3b9-8a0e-4065-85de-23cc2a396bad/scratchpad/`,
not in the repo.
## Review
**2026-08-19 — lead. Verdict: accepted; commits with round 15. No corpus
file is blocked on a compiler directive any more — the directive story
is complete for every list kind real RTL exercises.**
Points reviewed and accepted:
1. **All six named targets format**, verified by QA down to the
directive lines surviving verbatim in output, with the before-
baseline independently re-derived by stashing the feature files —
the cleanest attribution method available and now the house
standard for concurrent-round deltas.
2. **The harvest-before-dot-peek ordering** is the kind of one-line
subtlety these READMEs exist to record: run after the peek, a
leading directive parses as a positional expression. Documented,
and the design reuses the prior round's machinery verbatim rather
than growing a second pattern.
3. **The en-route bug** (directive_entry overwriting before_sep,
dropping a comment — net-caught as a refusal, invariant 3 held) was
fixed with the wrong-fix-first honesty this project rewards: the
attempted own-line placement was killed by the case table, and the
lexer's own capture rule proved inline correct.
4. **QA's attribution correction adopted as a lead note**: the
integration pin for that fix is `directives_in_lists.cases:780`
(which fails under sabotage), not the similarly-named rejection
test in verification.rs (which pins verify.rs strictness on a
literal pair and passes regardless). The work log's wording stands
as written; readers should trust the case table for the fix path —
the same two-layer division comments-round-2's review already
described.
Clean-file external resolution now 94.0%, unresolved externals 1.2%.
The remaining directive-shaped work is the one-line spelling (a lexer
round of its own, no corpus demand) — parked where it was.