Files
lucisv/docs/features/format-fences/README.md
T

568 lines
32 KiB
Markdown

# format-fences
## Goal
Let an author switch the formatter off for a stretch of code with
`// verilog_format: off` … `// verilog_format: on` (Verible's spelling, plus a
short `// lucisv: off` / `// lucisv: on` alias) and get those bytes back exactly
as they were written. Hand-aligned lookup tables, generated blocks, and
column-aligned instance connections are the cases every RTL codebase has;
without an escape hatch they are the reason a formatter never gets adopted.
The region is emitted as a raw slice of the original source — the AST inside
it is never consulted — so "verbatim" is true by construction rather than by
careful re-printing. This is the first consumer of the byte spans landed by
`docs/features/spans/README.md`.
## Fence grammar
A fence is a **line comment** whose text, after stripping the leading `//` and
trimming whitespace on both sides, is *exactly* one of:
```
verilog_format: off lucisv: off
verilog_format: on lucisv: on
```
Consequences, all deliberate and all tested:
- `//verilog_format: off` (no space) and `// lucisv: on ` are fences —
the text is trimmed. `// verilog_format:off` is **not** (no space after the
colon; the match is exact, not fuzzy).
- **A fence with trailing text is not a fence.** `// lucisv: off (for now)`
formats as an ordinary comment. Rationale: the alternative — prefix
matching — silently turns `// lucisv: off-by-one bug here` into a formatting
switch, and a fence that fires by accident is worse than one that does not
fire at all. If the author wants a note, it goes on its own line.
- **Block comments are not fences.** `/* verilog_format: off */` is an
ordinary comment. Restricting fences to `//` keeps a fence a whole-line
thing and keeps the region boundaries at line granularity.
- **A fence must be a leading comment**, i.e. it must start a line (nothing
but whitespace, or another comment, before it on that line). A comment on
the same line as preceding *code* is attached to that code as *trailing*
trivia, and `Meta.trailing` is an `Option<String>` with no span — there is
nothing to splice from. So `wire a; // lucisv: off` is an ordinary comment.
See Handshakes for the parser change that would lift this.
- The alias and the long form are interchangeable: an `off` in either
spelling is closed by an `on` in either spelling.
## Semantics
Fences select whole **items** (module items, package items, top-level items),
Verible-style. Think of an item list as a flat stream of *units*: each item's
leading comments, then the item's own code (its `(* … *)` attributes and
trailing comment included), and finally the scope's dangling comments.
- A region **opens** at the first `off` fence in that stream and **closes**
at the first `on` fence after it. The emitted byte range runs from the
first byte of the `off` fence's line through the last byte of the `on`
fence — the fence comments themselves are part of the region.
- Everything in between — items, their comments, their attributes — is
skipped by the formatter and comes out of the source slice instead.
- **Indentation is preserved, including on the region's first line.** The
region starts at the *start of the line* the `off` fence sits on (when only
whitespace precedes it there), and the printer emits the slice at column 0,
so every line of the region is byte-identical to the input. Normal
formatting, at the enclosing indent level, resumes on the line after the
region.
- **A second `off` inside an open region is a no-op**, as is an `on` with no
open `off`; both are just bytes inside the region, or an ordinary comment.
Fences do not nest and do not count.
- **An unmatched `off` runs to the end of its scope** — the last byte of the
containing item list, which is the end of the last item (its same-line
trailing comment included) or of the last dangling comment, whichever comes
last. At file scope that is the last byte of content in the file. It does
**not** leak into the enclosing scope: an `off` inside a module body is
closed by the module's `endmodule` at the latest, and an `on` written after
`endmodule` belongs to the file scope and cannot close it.
- **Fences never cross a scope boundary**, which is what keeps a region
aligned with item boundaries: a region can never end in the middle of an
item, so the formatter never has to print half of one.
### Out of scope this round: statement-level fences
A fence inside an item body — between two statements in an `always` block,
between two case items, inside a port list — **has no effect**. It is
formatted as an ordinary comment. Only `Item` lists are fenceable:
| fenceable scope | |
|---|---|
| file | `SourceFile.items` + `dangling` |
| package body | `ItemKind::Package` |
| module body | `Module.items` + `dangling` |
| `generate` region | `ItemKind::GenerateRegion` |
| generate `begin`…`end` | `GenBlock` with `is_block` |
Not fenceable: statement lists (`begin`/`end`, `fork`, function/task bodies),
case-item lists, port/parameter/connection lists, and the single-item body of
a bodyless `if (X) item;` in a generate (there is no list for a fence to end
in, and the formatter lays that item out inside a `Group`).
The interaction worth knowing: an `off` at item level whose matching `on` was
written inside a *statement* is an unmatched `off`, so it runs to the end of
the item list rather than stopping at the `on`. That errs toward *more*
verbatim text, never toward reformatting something the author fenced off.
## Splice mechanics
`fence::collect(src, &file)` walks the item scopes once, before any
formatting, and returns a sorted, non-overlapping `Vec<Region>`:
```rust
struct Region { fence: usize, start: usize, end: usize }
// ^ the `off` comment's own first byte (identity)
// ^ first byte emitted (start of that line)
// ^ one past the last byte emitted
```
Regions found inside an already-fenced range are dropped: the items holding
them are never formatted, so their fences never run. Because a region is
`[fence, end)` in a scope's own unit order and scopes nest, dropping any
region whose `fence` falls before the previous region's `end` leaves a list
that is sorted by both ends — so lookup is a `partition_point`.
During formatting, `Fmt` carries the source text and that list, and asks one
question per unit:
| unit | test | result |
|---|---|---|
| a comment | it *is* a region's `off` fence | emit `Doc::Verbatim(src[start..end])` |
| a comment | it starts inside a region | emit nothing |
| an item's code | `item.span.start` is inside a region | emit nothing |
`Doc::Verbatim` is a new printer instruction: it strips the indentation the
preceding line break just wrote and copies its string through untouched,
newlines and all. That is the whole of "emit the original bytes".
An item whose code is skipped but whose leading comments are not (a `doc`
comment above the `off` fence) still emits those comments — comments are
never dropped. An item that emits nothing at all contributes no separator
either, so no stray blank lines appear where the region swallowed items.
### Boundary / join decisions
- **Before the region**: the usual item separator, blank-line-aware, driven
by the `off` fence comment's own `blank_before` flag (which is also the
item's, since a `Meta`'s `blank_before` is its first leading comment's).
A blank line before `// lucisv: off` survives; two or more collapse to one,
as everywhere else.
- **First line of the region**: byte-exact, because the region starts at the
line start, not at the `//`. The exception is a fence preceded on its own
line by *another comment* (`/* a */ // lucisv: off`): there the region starts
at the `//`, and the other comment is formatted onto the line above. Still
idempotent — on the next pass the fence does start its line.
- **Inside the region**: nothing is touched, trailing whitespace on interior
lines included. `Doc::Verbatim` copies bytes; the printer's
trailing-space trimming only ever fires on line breaks *it* emits.
- **After the region**: a `HardLine` at the enclosing indent, so the next
item starts correctly indented on a fresh line. The blank line between the
`on` fence and the next item is dropped, which is exactly what already
happens between an item's last leading comment and the item itself.
- **Region ends at end of file**: the `format_once` tail normalization
(strip trailing blank space, add one `\n`) applies as usual, so the file
still ends in exactly one newline.
## Assumptions
- **Fence comments arrive as `Meta.leading` comments with correct spans.**
Guaranteed by the lexer's attachment phase (a comment not on the same line
as a preceding token becomes leading trivia) and by `docs/features/spans`.
- **A node's span is its code extent, attributes included, comments
excluded** — the `spans` convention. Both halves are load-bearing: the
attribute half is why splicing an item reproduces its `(* keep *)`, and the
comment half is why an item's leading comments can be emitted while its
code is skipped.
- **The formatter is only reachable through `format_source(&str)`**, so the
source text spliced from is always the exact text the spans were lexed
from. There is no AST-taking entry point that could pair a tree with a
different string.
- **A leading comment precedes its item's span.** One case can violate it —
an attribute followed by a comment (`(* x *)` newline `// c` newline
`wire a;`), where `Meta.leading` holds a comment positioned *after*
`item.span.start`. Fence detection skips such comments outright rather than
building a region that would double-emit the attribute.
- **Slicing is char-boundary safe** because every offset comes from a span or
from a scan over ASCII delimiters. The slice is still taken with `get()`:
if it were ever `None` the region comes out empty, `verify_equivalence`
rejects the output, and the file is left untouched — a failsafe, not a
panic.
## Handshakes
**Consumed from `vlog_parser`:**
- `Comment.span` / `Comment.text` / `Comment.blank_before` — the fence
matcher and the region boundaries.
- `Item.span` (code extent, attributes in, comments out) — region membership
for an item's code.
- The item-scope shapes: `SourceFile{items,dangling}`, `Module`,
`ItemKind::Package`, `ItemKind::GenerateRegion`, `GenBlock`, `GenIf`,
`GenFor`, `GenCase`.
Nothing in `crates/vlog_parser` was changed, and nothing new is required of
it for this feature to work as documented.
**Requested of `vlog_parser` (optional, not blocking):** a span on
`Meta.trailing`. ~~Today it is an `Option<String>`~~ **Delivered by the
comments-round feature (2026-08-19): `Meta.trailing` is now an
`Option<Comment>` carrying line/col/span.** Same-line fences remain
deliberately inert — this feature's matcher was not changed to use the
new data (confirmed by comments-round QA with live probes). Accepting
same-line fences (starting the region at the *following* line) is now
unblocked whenever someone wants it; until then the limitation stands
as documented above. — lead note
**Promised to `vlog_formatter` callers:** none of the public API changed.
`format_source` has the same signature and the same contract.
**`verify.rs` is untouched.** No normalization was added, broadened or
weakened, so CLAUDE.md hard invariant #4 does not apply to this round, and
none was needed: a fenced region is *source bytes*, so it re-lexes to exactly
the tokens and comments it came from, and the units it replaces are exactly
the ones whose bytes it contains. Equivalence therefore holds by
construction, and the check runs unchanged as the backstop that catches any
mistake in that reasoning (an off-by-one region end would drop or duplicate a
token and be rejected).
**Recursion budget (`docs/features/recursion-limit/README.md`):** unaffected.
`fence::collect` recurses only through nested *item* scopes, which is a
subset of the AST depth the parser already bounds at 320 layers, and it
builds no new tree. `Doc::Verbatim` is a leaf.
**`Doc` gained one variant.** `Doc::Verbatim(String)` — source bytes at
column 0, newlines included. It is treated as containing a hard line
(`contains_hard_line`, `Printer::fits`), so it can never be measured for a
flat layout. The one contract it relies on: it is only ever emitted right
after a line break or at the very start of the output, which is where the
"strip the indentation just written" step is correct. Both current emitters
(`Fmt::leading_comments`, `Fmt::dangling`) satisfy that.
## Status / TODO
- [x] `fence.rs`: `fence_of(&str) -> Option<Fence>` exact matcher, with unit
tests for every accept/reject spelling.
- [x] `fence.rs`: `collect(src, &SourceFile) -> Vec<Region>` over the five
fenceable scope shapes, nested-region drop, unmatched-to-end-of-scope.
- [x] `Doc::Verbatim` + printer support (`print`, `fits`,
`contains_hard_line`).
- [x] `format.rs`: `Fmt { src, regions }`, fence-aware `leading_comments` /
`dangling` / `item_seq` / `item_docs`; separators suppressed for units
the region swallowed.
- [x] `tests/cases/fences.cases` — 25 table cases (each also asserts
idempotency and, through `format_source`, equivalence).
- [x] `tests/fences.rs` — 6 tests: byte-exactness, own-indentation,
unmatched-off scoping, comment preservation, matcher/formatter
agreement, and five hand-built corrupted-region pairs the safety net
must reject.
- [x] README.md Style section mentions fences.
- [x] TODO.md §2 fences item checked.
- [ ] **Not done, deliberately:** statement-level fences (documented above).
- [ ] **Not done:** same-line (`trailing`-trivia) fences — blocked on a
parser change, see Handshakes.
## Work log
### 2026-08-19 — dev agent
- Read `CLAUDE.md`, `README.md`, TODO.md §2/§5, and the Handshakes of
`spans` and `recursion-limit` first. Baseline before touching anything:
`cargo test --workspace` **161 passed** (`vlog_formatter` 42), clippy
silent, fmt clean.
- **Chose "region = raw source slice" over "re-print the AST unchanged"**
without much deliberation — it is the only version where verbatim is a
fact rather than a claim, and it is what makes the safety net green by
construction instead of by argument.
- **Chose exact-match fence text over prefix matching.** A prefix match makes
`// lucisv: off-by-one` a formatting switch. Exact match's failure mode is a
fence that does not fire, which the author sees immediately in the diff.
- **Fences are leading comments only, and only line comments.** The leading
restriction is forced: `Meta.trailing` is an `Option<String>` and carries no
span, so there is no byte offset to start a region at, and `vlog_parser` is
owned by another agent this round. Recorded as a Handshake request rather
than worked around. The line-comment restriction is a choice: it keeps a
fence a whole-line thing.
- **Region starts at the line start, not at the `//`.** First version sliced
from `comment.span.start`, which left the region's first line re-indented by
the printer while every other line kept its source indentation — visibly
asymmetric on a mis-indented fence. Extending the start to the beginning of
the line (only when nothing but whitespace precedes) makes the whole region
byte-exact, and needed a new `Doc::Verbatim` so the printer would stop
prepending its own indent.
- **`Doc::Verbatim` rather than reusing `Doc::Text`.** `Text` is documented as
newline-free and the printer counts its width; a variant states the "bytes,
column 0, forces a break" contract instead of leaving it implicit. One
existing caller (`raw_text` on a string that crosses a line) still abuses
`Text` — left alone, out of scope.
- **Unmatched `off` needed a trailing-comment scan.** The scope end is the
last item's `span.end`, and an item's same-line trailing comment sits
*after* it with no span of its own. Without the scan, `wire a; // note`
inside an unmatched region dropped `// note` — hard invariant #3. Found by
reasoning about `Meta.trailing`'s missing span before writing the test, then
pinned by `unmatched_off_keeps_a_trailing_comment` and a `.cases` entry.
The matched case needs no scan: the `on` fence is later in the stream, so
the trailing comment is inside the range already.
- **Separator suppression was the second bug of construction.** An item whose
code is swallowed still emitted the `HardLine` its last leading comment
asked for, and then `item_seq` added the next item's separator on top —
a blank line after every region. `item_docs` now drops that dangling
`HardLine` when the code is skipped, and `item_seq`/`dangling`/`file`
separate on "did this unit emit anything" instead of on the index. With no
fences present the two formulations are identical, which is why the
existing suite shows zero churn.
- **Guarded the attribute-then-comment ordering case** (`(* x *)` on one line,
a comment on the next, then the item): `Meta.leading` can hold a comment
positioned after `item.span.start`, and a region opened there would emit the
attribute both inside the slice and again as formatted output. Fence
detection skips any leading comment that starts at or after its item's span.
- **Stress-tested against the corpus rather than trusting the unit tests.**
Injected an `off`/`on` pair at 1 868 random line positions across the 468
corpus files that parse, and compared the result against the same runs with
the fence text replaced by an ordinary comment of identical width:
- **0 new verification failures.** 112 of the 1 868 plain-comment runs fail
equivalence — a *pre-existing* bug class (a comment injected into a port
list or an expression gets moved or dropped; the safety net catches it and
the file is left untouched). The fenced runs fail on 94 of the same
trials and on **no others**; 18 are avoided precisely because the region
went verbatim.
- **Byte-exactness at corpus scale.** Restricting the injection so both
fences land at the same nesting level gives 294 honoured regions, of which
287 are reproduced byte-for-byte. The other 7 are all the documented
cross-scope case (the `on` landed in a different scope, so the `off` ran
to the end of its own): each preserves a verbatim *prefix* that stops
exactly at its scope's last item.
- **Two pre-existing bugs found in passing, both left alone** (out of scope,
reported to the lead): the comment-injection failures above, and a
double-blank-line bug — two leading comments separated by a blank line come
out separated by *two* blank lines, because `Fmt::leading` emits a
`HardLine` after each comment and then a `BlankLine` before the next.
Reproduced on the pre-change binary; not touched here because fixing it
churns snapshots.
- Did not touch `crates/vlog_parser`, `crates/lucisv`, `verify.rs`, or
`tools/`. Did not run `git commit`/`git push`.
**Results:** `cargo test -p vlog_formatter` **53 passed** (was 42: +5 matcher
unit tests in `fence.rs`, +6 in `tests/fences.rs`), plus **25 new
`.cases` entries** inside `case_tables`. No existing test changed and no
snapshot or `.cases` churn — the fence-aware separator logic is
byte-identical to the old index-based one when no fence is present, which is
what the untouched suite demonstrates. `cargo test --workspace` **194 passed,
0 failed** (that number also carries the concurrent error-tolerant-parsing
agent's new `vlog_parser` tests). `cargo clippy --workspace --all-targets`
silent (0 warnings). `cargo fmt --all --check` clean. Corpus:
`tools/corpus_check.sh corpus` (read-only) — 820 files, 2 ok-unchanged, 466
would-reformat, 352 parse-error, **0 verification errors, 0 crashes**, TSV md5
`3fab114f4f00626b254259e9dafe0ed7`, **byte-identical** to the `spans`
baseline. No `.sv`/`.v` corpus file contains a fence comment (`grep -rl` over
all 820: 0 hits; the only two `verilog_format` matches in the tree are a CI
YAML comment and a Verible build script), so the feature is inert there, as
expected. Corpus repos `git status --porcelain` clean apart from the
pre-existing untracked `.lucisv-corpus-rev` stamps.
Files touched: `crates/vlog_formatter/src/fence.rs` (new),
`crates/vlog_formatter/src/{lib,doc,printer,format}.rs`,
`crates/vlog_formatter/tests/fences.rs` (new),
`crates/vlog_formatter/tests/cases/fences.cases` (new), `README.md` (Style
section), `TODO.md` (§2 checkbox), this README.
## QA log
### 2026-08-19 — QA agent
Scope: `crates/vlog_formatter` only (a concurrent QA agent owns
`vlog_parser`/error-recovery this round; untouched here). No commit/push.
All work done via a scratch cargo project pointing at this crate by path
(`/private/tmp/.../scratchpad/qa_probe`) plus a disposable `git worktree` at
`HEAD` (901a78c, pre-fence) for baseline comparisons — both removed after
use, working tree left exactly as found (`git status --short` before/after
identical).
**Tool results.**
- `cargo test -p vlog_formatter`: **53 passed, 0 failed** (8 lib unit tests
— 5 in `fence.rs` + 3 pre-existing in `printer.rs` — 1+4+6+2+32 across
`cases.rs`/`deep_nesting.rs`/`fences.rs`/`fixtures.rs`/`verification.rs`).
Matches the claimed 42→53.
- `cargo test --workspace`: **194 passed, 0 failed** (40+21 in `lucisv`, 53 in
`vlog_formatter`, 49+19+12 in `vlog_parser` — the last three carry the
concurrent error-recovery agent's work, not this feature's).
- `cargo clippy -p vlog_formatter --all-targets`: 0 warnings.
`cargo clippy --workspace --all-targets`: 0 warnings. Confirmed the
earlier-flagged `fence.rs:58` nit is gone: it reads
`regions.last().is_none_or(|prev| ...)`, not `.map_or(true, ...)`.
- `cargo fmt --check` (workspace): clean, no output.
- `verify.rs` untouched: `git diff --quiet -- crates/vlog_formatter/src/verify.rs`
exits 0. `tests/verification.rs` likewise unchanged (`git diff --quiet`),
and its 32 tests still pass unmodified.
- `git status --short`: only `README.md`, `TODO.md`,
`crates/vlog_formatter/src/{doc,format,lib,printer}.rs` modified in this
feature's footprint, plus the four new files
(`fence.rs`, `tests/fences.rs`, `tests/cases/fences.cases`,
`docs/features/format-fences/README.md`) — matches the work log's "files
touched" list exactly. `crates/vlog_parser/**` changes present are the
concurrent feature's, not this one's.
- `tools/corpus_check.sh corpus`: 820 files, **0 verification errors, 0
crashes**, TSV md5 `3fab114f4f00626b254259e9dafe0ed7` — **matches** the
claimed baseline exactly (byte-identical results file). `grep -rl` for
`verilog_format|lucisv:` across all `.sv/.v/.svh/.vh` in `corpus/`: **0
hits**, confirming the feature is inert on the corpus as claimed.
**Claim 1 (fence grammar) — PASS.** Direct `fence_of()` probes:
`// lucisv: off ` (single trailing space) *is* a fence — correctly so, the
grammar trims surrounding whitespace and only disqualifies non-whitespace
trailing text; my first pass at this check used the wrong expectation and
was self-corrected. `// LUCISV: off` (case), `// lucisv: off` (inner double
space), `// verilog_format:off` (no space after colon) are all correctly
rejected — matches the documented grammar exactly, no drift between prose
and code. Block comments and same-line trailing comments confirmed inert
via both the `.cases` table and my own probes.
**Claim 2 (semantics) — PASS.** All items verified, including two not
explicitly in the `.cases` table: (a) a region nested inside another
region — outer `off`/`on` wrapping a module that has its own inner
`off`/`on` pair — is correctly collapsed to one region (`fence::collect`'s
dedup), the inner fence pair is inert text, output byte-exact,
second-pass idempotent. (b) unmatched-`off` correctly stops at
`endmodule`/`end` and never leaks into the next scope, confirmed at file,
module and generate-block granularity.
**Claim 3 (splice mechanics) — PASS.** Adversarial idempotency probes (24
targeted cases: fence at file start/end with and without trailing
newline, zero items between off/on, off right after `module m;` + on
right before `endmodule`, two adjacent regions, matched region whose last
item has a same-line trailing comment, interior tabs/trailing spaces,
multi-line macro + attribute inside a region, 1/2/3 blank lines in three
different positions around the fences, generate-block-final region
matched and unmatched, CRLF file variants including a fence sharing its
line with a block comment, a crammed one-line port/connection list inside
a region, and a 200-column line inside a region) — **all byte-exact and
idempotent, zero failures.** Region-content protection confirmed: the
200-col line and the crammed port list both survive verbatim, and
formatting resumes at the correct indent immediately after (`assign z = a
+ b;` at 2-space indent right after a verbatim block that was written at
column 0). CRLF interior bytes (`\r\n`) survive inside `Doc::Verbatim`
slices exactly; the formatter's own emitted lines around them use `\n` as
usual — pre-existing, general behavior, not fence-specific, and internally
consistent (idempotent).
Reviewed `printer.rs`'s `Doc::Verbatim` indent-stripping
(`while out.ends_with(' ') { out.pop(); }`) for a tabs-vs-spaces gap: the
printer's own indentation is generated exclusively via
`" ".repeat(...)`-style space writes (confirmed by reading `print()`), so
there is no path where the "indentation just written" contains a tab —
the space-only strip is correct as written, not a latent bug.
**Claim 4 (matcher) — PASS**, see Claim 1; the `tests/fences.rs`
`the_matcher_agrees_with_what_the_formatter_honours` test already pins the
matcher-vs-formatter agreement in both directions and I independently
reproduced every spelling in the task list against `fence_of` directly.
**Claim 5 (interaction with error-recovery arms) — PASS, and
strengthened.** The README's Handshakes section reasons that
`fence::collect` never sees `ItemKind::Error` in production because
`format_source` only calls the strict `parse_source`. I went further and
called `fence::collect` directly against a `parse_source_tolerant(...)`
tree containing an `ItemKind::Error` node (adjacent to, and also
overlapping the leading comments of, a fenced region) — no panic, and
`ItemKind::Error` is correctly ignored by `scan_nested`'s catch-all arm in
both configurations tried. This is dead code in today's product but is
now empirically confirmed safe, not just reasoned about.
**Claim: 1868-injection stress (evidence review, not reproduced at that
scale) — directionally confirmed.** I ran an independent ~200-trial
random injection harness against the same `corpus/` (118 trials usable
after skipping the 82 that don't parse, consistent with the corpus's
~43% parse rate). Initial naive comparison (fence pair vs. a *single*
plain padding comment) showed 1 "new" fence failure, but that comparison
was unfair — the fence variant inserts two lines (off+on), the plain
variant only one. Re-run with a fair **paired** control (plain padding
comments at the *same two* line positions): **0 new verification failures
attributable to fencing**, and the fence variant additionally *avoided* 2
failures the plain-pair control hit (regions the fence sent verbatim that
a plain comment injected at the same spot would have corrupted) — this
directly corroborates the dev's own "0 new verification failures" /
"18 avoided precisely because the region went verbatim" claim, on an
independent sample. I did not attempt to reproduce the dev's exact
1868/294/287/7 figures (no harness script was checked in to rerun
verbatim); treat those as the dev's own measurement, independently
corroborated in direction and magnitude but not bit-for-bit.
**Claim 7 (pre-existing bugs) — PASS, both reproduced on the pre-change
binary.** Using a disposable `git worktree` at `HEAD` (901a78c, before any
of this feature's changes):
- **Double-blank between leading comments**: `module m;\n // first\n\n //
second\n wire a;\nendmodule\n` reproduces the extra blank line
(`// first` then *two* blank lines then `// second`) identically on the
baseline binary. Confirmed pre-existing, not introduced.
- **Comment in a list dropped → refused**: reproduced the exact corpus
hit (`corpus/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_mubi16_dec.sv`,
padding comment inserted before line 16) on both the baseline worktree
and the current tree — byte-identical error message
(`token stream diverges at index 18: input has comment ... output has
symbol "#"`) on both. Confirmed pre-existing. Note for context (not a
correction of the dev's claim): this bug class is the same one already
tracked as open "refusals" in `docs/features/corpus-bugs/README.md`
("Comments inside a replication, inside a compactly-printed bracket
expression, ... remain refusals" — this feature's finding is another
instance of that same, already-known category, not a new one).
**Durability of the two open items — PASS with a minor, non-blocking
suggestion.** Both are recorded in this README's Work log, which is a
required, checked-in section per `CLAUDE.md`'s document-based-development
rules, so they are not silently lost by the letter of that requirement.
They are *not* mirrored as `TODO.md` §1 entries the way other QA-found
bugs in this repo are (e.g. the `@(* )` lexer bug, tagged "(bug-fix QA
find)"). Since `TODO.md` is described as the project's "curated backlog"
and is where a future agent would look first, I'd suggest the lead add
one line each there for discoverability — informational only, not
blocking.
**Claude.md compliance — PASS.** No `unwrap()`/`expect()`/`panic!` outside
`#[cfg(test)]` in `fence.rs` or the `format.rs` diff (checked by grep on
the diff and the file). All new `pub` items in `fence.rs` carry one-line
doc comments. No `unsafe`. `README.md`/`TODO.md` checkbox changes are
accurate to what shipped (statement-level and same-line fences correctly
left unchecked with a documented reason).
**Overall: no BLOCKING findings.** No byte change inside any fenced
region across two passes in any probe, no behavior change with zero
fences present beyond what the existing untouched test suite already
covers (byte-for-byte zero churn). The one apparent anomaly during
testing (the "1 new fence failure" in the naive injection comparison) was
a flaw in my own harness's methodology, not the feature — resolved with a
fair control, see above.
## Review
**2026-08-19 — lead. Verdict: accepted; commits jointly with
error-recovery (entangled in `format.rs` via the `Error` match arms).**
The user-facing rule this feature had to get right — *bytes inside a
fence are sacred* — survived 24 adversarial join probes and ~2000
combined corpus injections (dev's 1868 + QA's paired-control 118) with
zero region byte changes and zero new verification failures. Points
reviewed and accepted:
1. **Exact-match fence grammar** (trailing text disqualifies, no-space
`lucisv:off` disqualifies): strict grammars over lenient ones is the
config-discovery lesson applied again — a fence that half-matches
silently doing nothing would be the worst outcome, and the current
rule makes it at least predictable. Verible-compatible spelling plus
the short alias is the right pair.
2. **Item-level scope, statement level deferred** — the honest scope
line, documented and tested (an off-fence inside an item body is
inert). Same-line trailing fences are inert for a structural reason
(Meta.trailing has no span) — the Handshake filed on vlog_parser is
the right escalation instead of a hack. That handshake lands
naturally with the comments round.
3. **Doc::Verbatim as a first-class hard-line element** rather than
string surgery in the printer: right layer, and "with no fences the
output is byte-identical" held (corpus md5 exact).
4. Two construction-time bugs (dropped trailing comment on unmatched
off, stray separator from swallowed items) caught and fixed by the
dev's own tests — the invariant-test-first habit is now visibly the
house style.
QA's suggestion adopted at review: the two pre-existing bugs this
feature surfaced (comment-in-list refusal, quantified at 112/1868
trials; the double-blank leading-comment nit) are now TODO.md items
queued for a dedicated comments round — they were too big to ride
along here, and the refusal path means neither can corrupt.