Two budgets, both measured rather than guessed: MAX_NESTING_DEPTH=64
gates the five recursion cycles in the parser (debug frames run to
~50KB; 64 peaks at ~3.9MiB against the 8MiB stack), and
MAX_CHAIN_LENGTH=256 charges postfix segments and binary/inside
operators, whose loops deepen the AST without parser recursion.
Restore-by-assignment makes the chain budget correct on every early
return. Invariant: AST depth on any root-to-leaf path <= 64+256,
so the formatter's structural recursion is bounded too.
Deep or chain-heavy inputs now get a clean "nesting too deep" /
"expression chain too long" parse error with position, exit 2, batch
unaffected -- replacing an uncatchable stack-overflow abort that
killed whole runs (3KiB of a.b.b... sufficed before).
Round 1 was rejected in review: QA found postfix chains ungated and
the leak test unable to detect missing releases (proven by sabotage).
The rework widened the finding to binary/inside chains, added the
second budget, and made leak tests sabotage-complete (7/7); re-QA
attacked the additive-composition invariant and found no hole, with
no acceptance regressions (128-term sums, 10k statements still fine).
Dev + rework: Opus agent; QA + re-QA: Sonnet agent; full history in
docs/features/recursion-limit/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
Item's Display printed raw comment text, so a comment containing a
tab or spanning lines embedded raw control bytes in the diagnostic,
splitting one logical error across stderr lines/TSV fields (found by
corpus-check QA via tools/corpus_check.sh). Use {:?} like parser.rs
does for its "found" token, keeping one diagnostic = one line.
Co-Authored-By: Claude Fable 5 <[email protected]>
tools/corpus_fetch.sh pins picorv32, ibex, common_cells and two
OpenTitan IPs by exact SHA; tools/corpus_check.sh buckets per-file
outcomes (parse/format/verification-error/crash) into a summary,
a deduped error histogram, and a TSV diffable between commits.
Baseline at 9f1a6cf: 35.2% parsed, zero crashes, zero corruption;
24 safety-net refusals reducing to four formatter bugs (event-list
comma -> or, dropped comments in port lists and always blocks,
merged header imports, dropped empty #()) — queued as the next
bug-fix round with corpus files as acceptance inputs.
The corpus proved the README roadmap order wrong: macro invocation
at item/statement position blocks ~60% of RTL parse errors (it
wasn't listed), interfaces (was #1) blocked one file. README
roadmap re-ordered by measured impact.
Dev: Opus agent; QA: Sonnet agent (all claims pass, re-run
byte-identical; fixed a TSV tab-splitting bug); review in
docs/features/corpus-check/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
All five briefed bugs fixed, plus a sixth found during the work:
1. Block-comment continuation drift: token::Comment gained line/col;
continuation lines are dedented by the comment's original column
before re-indenting, making reformatting a true fixed point while
preserving the author's relative indentation inside the comment.
2. Comments inside expression groups (concat, parens, call args,
assignment patterns, binary operands) now force the group to break
instead of being lifted out.
3. Closing block labels preserved for end/join*/endfunction/endtask/
endpackage, matching endmodule.
4. Multi-instance declarations fit on one line when they fit and
indent their continuations when they break.
5. @( /* c */ * ) keeps its comments (SensList::Star before/after).
6. Multi-line `define/attribute bodies no longer drift (RawText.col).
verify.rs comparison logic untouched (diagnostic positions only) —
QA audited the diff to confirm the safety net was not weakened.
All four #SKIP cases un-skipped verbatim as spec; 17 cases added
(183 -> 200, 0 skipped). QA triple-formatted 204 inputs with zero
regressions. Clippy is now fully silent workspace-wide.
Remaining comment-placement refusals (4) and a pre-existing @(* )
lexer limitation are documented as open items, not hacked around.
Dev: Opus agent; QA: Sonnet agent; review in
docs/features/formatter-bug-fixes/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
main.rs split into args/walk/diff modules, all std-only. --diff emits
a patch-applicable unified diff (bounded-resync hunks, GNU-style
missing-newline marker); --exclude is a small component-glob matcher
that prunes directory walks; --stdin-filename names stdin buffers in
messages; per-file catch_unwind turns formatter panics into ordinary
errors. Exit-code contract (0/1/2) frozen and documented in --help
and README. 12 CLI integration tests + 18 unit tests.
Known gap found by QA, queued in TODO §1: deep nesting overflows the
parser stack (uncatchable), needs an explicit recursion-depth limit.
Dev: Opus agent; QA: Sonnet agent; review in
docs/features/cli-polish/README.md (includes one lead fix: the
no-final-newline marker is now emitted the way patch(1) expects).
Co-Authored-By: Claude Fable 5 <[email protected]>
One-time mechanical pass; no behavior change (full test suite green
before and after). From here on, cargo fmt --check is the standard.
Co-Authored-By: Claude Fable 5 <[email protected]>
format_source now verifies every result before returning it, per
Verible's practice: the output must re-lex to the same token stream
as the input (comments included, whitespace ignored) and formatting
it a second time must be a fixed point. Any failure returns
FormatError::Verification and the caller keeps the original text —
"never corrupt code" and idempotency are now runtime guarantees.
Normalizations (documented in the feature README): multi-line
comments/directives/attributes compare line-trimmed since the
formatter re-indents them; @(*)/@* is a whitelisted canonicalization.
The net already catches three real pre-existing bugs (closing-label
drop, block-comment re-indent drift, sens-list comment drop), which
now refuse output with exit 2 instead of corrupting files. Fixes
queued as the next feature. Checks off TODO.md §1 items 1-3.
Dev: Opus agent; QA: Sonnet agent (17 adversarial pairs, all caught);
review in docs/features/safety-net/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
183 {input, expected} cases across 10 construct files under
tests/cases/, driven by a ~180-line std-only harness (==== / ----
format). Each case asserts formatting and idempotency; #SKIP parks
known formatter bugs and fails the suite once they start passing.
Documents four real formatter bugs found while deriving expected
output (block-comment re-indent non-idempotency, comment lifted out
of expression groups, closing block labels dropped, multi-instance
declaration layout) — parked as #SKIP, to be fixed in a follow-up
feature. Also adds rustfmt.toml matching the codebase style.
Dev: Opus agent; QA: Sonnet agent; review in
docs/features/case-tables/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
Simplicity-first rules, Rust standards, and document-based development:
every feature gets docs/features/<name>/README.md with assumptions,
handshakes, work/QA logs, and a lead review section.
Co-Authored-By: Claude Fable 5 <[email protected]>
Workspace with comment-preserving parser (vlog_parser), prettier-style
document IR + formatting rules (vlog_formatter), and CLI (vfmt).
Includes snapshot/idempotency tests and a TODO backlog of practices
adopted from ruff and Verible.
Co-Authored-By: Claude Fable 5 <[email protected]>