TODO section 28, lane B (the file-size rule in CLAUDE.md).
format.rs (5 444 production lines) becomes format/{mod, verbatim,
comment, phrase, list, item, module, instance, decl, routine, class,
cover, sva, stmt, expr}.rs - no file over 600 production lines, the
three dispatch tables (stmt_kind, expr, prop_expr) left whole and
documented as such, sibling modules private with pub(super) entry
points, every public path unchanged (cargo doc item list identical).
Proof: per-binary test counts identical (31/1/5/6/2/22/208/0; workspace
3 215 / 48), 4 807 corpus + opentitan files byte-identical to the
v0.33.0 binary in stdout, exit code and stderr, and a line-multiset +
function-signature census showing only use lines, visibility keywords,
banners and doc comments differ - done by the dev and re-done from
scratch by QA. verify.rs untouched.
docs/features/decomposition-formatter/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
decomposition-formatter — TODO §28 Lane B: vlog_formatter/src/format.rs → format/
Goal
Split the 5 443-line crates/vlog_formatter/src/format.rs into a
format/ module directory a human can navigate: one file per grammar
domain (items, module boundary, instantiations, declarations, routines,
classes, covergroups, SVA, statements, expressions) on top of four files
of shared machinery (comments, verbatim bytes, recurring phrases, lists
and alignment), each describable in one sentence. A pure move: no
behaviour change, no renamed item, every public path preserved from
vlog_formatter::format, formatter output byte-identical over the corpus
and opentitan, test counts unchanged. The reason beyond the file-size rule
is the same as for the whole round: format.rs is where every formatter
feature lane collided, and after this lanes that touch different grammar
domains can run in parallel.
Assumptions
- The four public items (
Config,FormatError,format_source,format_range) stay informat/mod.rs, so the public pathvlog_formatter::format::*and the crate-root re-exports are unchanged by construction; the sibling modules are private (mod x;, notpub), so no new public path appears. Fmt's fields stay private; child modules read them because Rust lets a descendant see its ancestors' private items. Methods a sibling file calls arepub(super)— visible insideformat/and nowhere else — and that marking doubles as the reader's list of a module's entry points.verify.rsis not touched (hard invariant 4).lib.rsis not touched: itspub mod format;resolves toformat/mod.rsunchanged.- No
#[cfg(test)]block lives informat.rs; the crate's 31 unit tests are in the sibling modules (align,fence,printer,range,verify), so nothing moves in the test tree. - Byte-identity is measured over the Verilog files under
corpus/(.sv .svh .v .vh) andopentitan/hw,--stdoutonly, against/tmp/lucisv-0.33.0-baseline(a release build of159f6a0).
Handshakes
- Consumes (unchanged):
vlog_parser::ast::*,crate::doc,crate::align,crate::fence,crate::printer,crate::range,crate::verify. - Promises (unchanged):
vlog_formatter::format::{Config, FormatError, format_source, format_range}at the same paths with the same signatures;lib.rsre-exports untouched. - Requests: none. Nothing outside
crates/vlog_formatter/src/format/and this README (plus the Lane B line ofTODO.md) changes.
Status / TODO
- Baseline pinned: test counts, public item list (
cargo doc), longest-function census,/tmp/lucisv-0.33.0-baselinepresent git mv src/format.rs src/format/mod.rs- Sibling files carved;
cargo build -p vlog_formattergreen cargo test -p vlog_formattercounts equal to baseline (31/1/5/6/2/22/208/0 — identical)- Text-level purity: every non-blank line of the old file appears in the new tree (line multiset diff)
cargo fmt -p vlog_formatter(--checkclean),cargo clippy --all-targets --workspace0 warnings,cargo doc0 warnings,cargo test --workspace48 binaries / 3 215 passed / 0 failed- Byte-identity: corpus + opentitan
--stdoutvs baseline — 4 807 files, 0 differing (stdout, exit code and stderr all identical) - Public item list diffed: no path changed (46
cargo docpages,diffempty) TODO.mdLane B line ticked
Work log
2026-09-02 — baseline
Branch decomp-formatter at 159f6a0 (v0.33.0), worktree
.claude/worktrees/decomp-formatter.
Pinned cargo test -p vlog_formatter (per binary):
| binary | tests |
|---|---|
src/lib.rs unit tests |
31 |
tests/cases.rs |
1 (the snapshot + idempotency suite, 941 cases inside) |
tests/deep_nesting.rs |
5 |
tests/fences.rs |
6 |
tests/fixtures.rs |
2 |
tests/ranges.rs |
22 |
tests/verification.rs |
208 |
| doc-tests | 0 |
| sum | 275 |
Public items of vlog_formatter per cargo doc --no-deps: 46 HTML
pages, of which under format/: enum.FormatError, fn.format_range,
fn.format_source, struct.Config, index.
Longest functions in format.rs before (production lines, brace-matched):
| fn | lines | old line |
|---|---|---|
stmt_kind |
279 | 4413 |
expr |
233 | 4890 |
prop_expr |
168 | 3959 |
constraint_item_kind |
98 | 3079 |
item_kind |
96 | 1325 |
sens_list |
83 | 4329 |
module_head |
81 | 1463 |
cont_assign |
71 | 2093 |
select_expr |
66 | 3648 |
data_type |
65 | 1652 |
Three functions are over 150 lines and all three are dispatch tables over
an enum (StmtKind, ExprKind, PropKind): they stay whole, each with
a comment saying so. prop_expr was given the look §28 asks for: its
Paren and Call arms share a shape ((, comments, expr, match items,
comments, )) that a future lane could fold into one helper, but that is
a code change, not a move, and is left as a note.
2026-09-02 — the split (method)
git mv src/format.rs src/format/mod.rs first, so history follows the
file that keeps the public items. Every sibling file was then assembled
by copying line ranges out of the pristine mod.rs (a module doc
comment, the use lines, one impl<'a> Fmt<'a> { … } block, the free
functions), and mod.rs was rewritten through the Write tool to exactly
the items it keeps. No sed/Python deletion touched any source file. The
proof that nothing was lost is the line-multiset comparison below plus
the gates.
Deviations from a literal move, all documentation-only:
- Three doc comments in the old file were attached to the wrong item
(a blank-line slip):
ListItem's ("A list element ready for comma-list layout…") sat aboveBlockDoc;named's ("A name, plus the space…") ran straight intoholds_verbatim_value's;strip_blanks's one-liner ("Drop up tonleading spaces or tabs.") sat abovecrosses_line_inside_string. Each now sits on its own item. - Section banners (
// ---- Module ----) became module doc comments; the SVA banner's layout-rule paragraph is nowsva.rs's module doc. - Three doc comments said "this file" about a fact that now spans the
directory (
named's audit note twice,with_constraint_block's "the one thing this file already readssrcfor"); each now says "the formatter" or "format/". The three dispatch tables (stmt_kind,expr,prop_expr) each gained the one-line doc comment §28 asks for, saying why they stay whole. - Visibility:
Fmt, its fields and the free helpers inmod.rsstay private (children see them). Inside the siblings, exactly the methods, associated functions, theListItemstruct with four of its fields, theSlotenum anddrive_strengththat another sibling calls arepub(super); everything else stays private to its file. The set was taken from the compiler (E0624/E0603/E0616), not guessed, so it is the minimal cross-file interface.
The line-multiset check: git show HEAD:…/format.rs vs cat format/*.rs,
pub(super) stripped, blank lines dropped, both sorted, comm. Lines
only in the original: the fifteen // ---- Section ---- banner lines,
the SVA banner's six prose lines (now sva.rs's //!), and the three
reshuffled use lines. Lines only in the new tree: //! module docs,
use/mod lines, impl<'a> Fmt<'a> { / } wrappers. Nothing else.
2026-09-02 — module map
Old format.rs line ranges (159f6a0) → new file. "prod" is non-blank,
non-comment lines; "total" is wc -l. Old file: 5 443 total.
| new file | one sentence | prod | total | old format.rs lines |
|---|---|---|---|---|
mod.rs |
What the crate exports, the Fmt state, and the name helpers every module writes an identifier through. |
152 | 259 | 1–30, 43–161, 5279–5297 + 5314–5325, 5327–5354, 5414–5443 |
verbatim.rs |
Bytes copied rather than laid out: fences, --lines runs, directives, attributes, macro calls, and the re-indent rule for multi-line raw text. |
87 | 171 | 163–169, 236–278, 292–303, 310–330, 376–418, 5371–5388 |
comment.rs |
Where a comment prints relative to the tokens around it: leading/trailing, gap slots, inside parentheses, dangling. | 192 | 301 | 305–308, 420–557, 650–662, 690–695, 1027–1090, 1166–1178, 3185–3195, 5390–5393, 5404–5412 |
phrase.rs |
Recurring two/three-token phrases with comment gaps: keyword-then, = value, ;, end : label, [a:b], for punctuation, foreach [i,j]. |
188 | 257 | 332–370, 559–648, 664–688, 1015–1025, 2590–2599, 4231–4247, 5124–5153 |
list.rs |
Comma lists — bracketed, bare, with directives between elements — and the alignment planner that pads rows. | 226 | 335 | 179–180, 193–229, 697–827, 833–903, 1007–1013, 3235–3281 |
item.rs |
File/fragment, item sequences and blank lines, ItemKind dispatch, package, generate constructs, assign. |
436 | 535 | 1100–1153, 1184–1420, 1426–1443, 2074–2163, 2480–2588 |
module.rs |
A module or interface's boundary: header through ;, ANSI/non-ANSI ports and their alignment, modports, clocking. |
301 | 365 | 31–32, 905–924, 1445–1645, 2708–2829 |
instance.rs |
Instantiations: overrides, instance lists, named/ordered connections and their alignment, bind, gates. |
292 | 385 | 34–37, 926–942, 997–1005, 2165–2474, 5271–5277, 5298–5312 |
decl.rs |
Data types, dimensions, declarators, parameter/localparam and their alignment, typedef, enum/struct bodies. |
367 | 452 | 39–41, 944–995, 1651–1742, 1785–2068 |
routine.rs |
Functions, tasks, the argument list they share with covergroups and properties, let, DPI import/export. |
172 | 192 | 2605–2644, 2831–2857, 2859–2952, 5356–5369 |
class.rs |
Class headers/bodies and every constraint form, including dist. |
283 | 369 | 2646–2706, 2958–3183, 3197–3233, 3283–3306 |
cover.rs |
Covergroups: header, coverpoints/crosses, bins and their specs, options. | 369 | 414 | 3312–3713 |
sva.rs |
Assertions: property/sequence declarations, action blocks, disable iff, the property-expression grammar. |
448 | 519 | 3715–4221 |
stmt.rs |
Statements: blocks, body-of-header, StmtKind dispatch, if/case, timing controls and sensitivity lists. |
573 | 659 | 181–191, 1092–1098, 1155–1164, 4227–4229, 4249–4834, 5395–5402 |
expr.rs |
Expressions: ExprKind dispatch, binary chains, ternaries with comments, the compact […] spelling, postfix forms. |
387 | 481 | 171–177, 280–290, 1744–1783, 4840–5122, 5155–5268 |
Cut points that differ from §28's sketch, and why:
- §28 put instantiations, connections and
bindinmodule.rs. Together with the header, ports, modports and clocking that is ~800 lines, so the instantiation side isinstance.rs: a connection's(is the one column an instance list aligns on, and its cells, column spec and planner now sit in one file. - §28 put constraints and covergroups in
class.rs. That is ~820 lines and two sentences, so covergroups arecover.rs. - §28 had
directive.rs. What is actually directive-shaped in the code is "text reproduced rather than laid out" — directives, attributes, macro calls and fenced regions share oneraw_text/Doc::Inlinepath — so the file isverbatim.rsand says so. - §28 kept the comment-slot machinery in
mod.rs. With the entry points and name helpers that is ~1 000 lines, so the machinery is three files by what it does:comment.rs(placing comments),phrase.rs(the small phrases every construct spells the same way),list.rs(lists and alignment). Each construct's row — an ANSI port's cells, a connection's, aparameter's — lives beside the construct, not inlist.rs, so a change to how one construct aligns touches one file. routine.rs(functions/tasks/let/DPI) is under the 300-line target on purpose: folding it intodecl.rswould make that file's sentence grow an "and function bodies", andtf_argsis called from three domains (routine,cover,sva) so it wants a named home.
No file is over 600 production lines (stmt.rs at 573 is the largest;
280 of it is the stmt_kind dispatch table). The only functions over 150
lines are the three dispatch tables (stmt_kind 279, expr 233,
prop_expr 168), unchanged in length, each with a doc comment saying so.
No function was split.
2026-09-02 — gates
cargo fmt -p vlog_formatterapplied;-- --checkclean.cargo clippy --all-targets --workspace: 0 warnings. No#[allow]introduced.cargo doc -p vlog_formatter --no-deps: 0 warnings (one intra-doc link from the publicformatmodule doc to the privateFmtwas turned into plain code font to keep it so).cargo test -p vlog_formatter: 31 / 1 / 5 / 6 / 2 / 22 / 208 / 0 — identical to the pinned baseline, sum 275.cargo test --workspace: 48 binaries, 3 215 passed, 0 failed.- Public item list (
cargo docpage list, 46 pages):diffagainst the baseline list is empty. cargo build --release -p lucisvin the worktree for the byte-identity run (result in the next entry).
Git state note: the rename was staged by git mv at the start; a
pathspec git reset used while measuring the diff un-staged it, and it
was re-staged with git add. The index now shows D format.rs +
A format/mod.rs rather than R, because git labels a rename only while
the new file is ≥50 % similar and the 259-line mod.rs is not — the
git blame discontinuity §28 accepts. Nothing was committed.
2026-09-02 — byte-identity
target/release/lucisv (this worktree) vs /tmp/lucisv-0.33.0-baseline,
--stdout on every .sv/.svh/.v/.vh under
/Users/guoliangchen/repo/verilogrustformatter/corpus (860 files) and
/Users/guoliangchen/repo/opentitan/hw (3 947 files), stdout, stderr and
exit code captured per file and compared with cmp:
files=4807 stdout_differing=0 exit_code_differing=0 stderr_differing=0
exit0=4790 exit_nonzero=17
The 17 non-zero exits are the same 17 on both binaries (the files the
formatter refuses at 0.33.0). opentitan was touched with --stdout only;
git -C …/opentitan status --porcelain before and after shows exactly
hw/ip/aes/dv/tb/tb.sv, hw/top_darjeeling/ip/ast/rtl/ast.sv,
hw/top_earlgrey/ip/ast/rtl/ast.sv — the pre-existing modifications.
Handshake requests: none. Files changed: crates/vlog_formatter/src/ format.rs → format/{mod,verbatim,comment,phrase,list,item,module, instance,decl,routine,class,cover,sva,stmt,expr}.rs, this README, and
the Lane B line of TODO.md.
QA log
2026-09-02 — verification
Scope check first: git diff --stat 159f6a0 -- crates/vlog_formatter/src/verify.rs
empty, crates/vlog_formatter/src/lib.rs diff empty. git status --porcelain
touches only crates/vlog_formatter/src/, docs/features/ decomposition-formatter/, TODO.md; TODO.md's diff is exactly the
Lane B line flipped to [x].
Gates (all in the dev worktree):
cargo fmt -p vlog_formatter -- --check: clean.cargo clippy --all-targets --workspace(forced a rebuild withtouchfirst, since a cached run prints nothing): 0 warnings.git diff 159f6a0 -- crates/vlog_formatter/has no added+#[allowline anywhere.cargo doc -p vlog_formatter --no-deps: 0 warnings.cargo test -p vlog_formatter --no-fail-fast: per-binary 31 / 1 / 5 / 6 / 2 / 22 / 208 / 0 — identical to the pinned baseline.cargo test --workspace --no-fail-fast: 48 binaries, sum oftest result:lines = 3 215 passed, 0 failed — matches the claim exactly.
Pure-move, mechanically. Line-multiset check reproduced independently
(not from a throwaway worktree — none of this touches a tracked file):
git show 159f6a0:…/format.rs vs cat format/*.rs, both with leading/
trailing whitespace stripped, ^pub(super) stripped, blank lines
dropped, sorted, comm -23/comm -13. Old-only: 64 lines — the 28
banner/divider lines, 14 section-title lines, 5 SVA-banner prose lines,
3 "this file" doc-comment originals, 4 reshuffled use lines, and 8
single-line versions of function signatures that rustfmt rewrapped once
pub(super) pushed them past 100 columns. New-only: 300 lines — use/
mod/impl<'a> Fmt<'a> { structure, //! doc comments (including the
new "why it stays whole" lines on the three dispatch tables and the
three reworded "this file" → "the formatter"/format/ comments the work
log logs), and the wrapped continuation lines of those same 8
signatures. Every line on either side is accounted for by the dev's
logged deviations; nothing else differs.
Function-signature census (own script, not the dev's): extracted every
fn signature (name + params + return type, whitespace-normalized,
visibility keyword stripped) from old format.rs and from the new tree.
201 signatures on each side. The only 8 that don't match textually are
exactly the same 8 rustfmt-rewrapped ones above — same name, same
params in the same order and types, same return type; the only
difference is a trailing comma rustfmt inserts on a multi-line arg list.
No function added, removed, renamed, retyped, reordered, or split.
Public API. cargo doc -p vlog_formatter --no-deps in the dev
worktree: 46 HTML pages. Built independently at 159f6a0 in a throwaway
worktree (git worktree add .claude/worktrees/qa-baseline-b 159f6a0,
removed after): also 46 pages, diff of the sorted page-path lists is
empty — no path added, removed, or renamed. The workspace test run
above already proves every other crate compiles unchanged against the
new format/ tree.
Byte-identity, independently reproduced. Rebuilt
/tmp/lucisv-0.33.0-baseline myself from the 159f6a0 worktree
(cargo build --release -p lucisv) and shasum -a 256 matched the
dev's pinned baseline exactly, so the baseline binary is a genuine
159f6a0 build. Built target/release/lucisv in the dev worktree and
ran --stdout over every .sv/.svh/.v/.vh under corpus/ (860 files)
and opentitan/hw (3 947 files) against that baseline, comparing
stdout, stderr and exit code per file:
files=4807 stdout_differing=0 exit_code_differing=0 stderr_differing=0
exit0=4790 exit_nonzero=17
Identical to the dev's numbers. git -C opentitan status --porcelain
before and after the run shows exactly the same three pre-existing
modified files (hw/ip/aes/dv/tb/tb.sv, hw/top_darjeeling/ip/ast/rtl/ ast.sv, hw/top_earlgrey/ip/ast/rtl/ast.sv) — opentitan untouched by
the run itself.
Size rule. Recounted production/total lines per file with an
independent script (non-blank, non-/////////!-only lines; no
#[cfg(test)] block in any of the 15 files). All 15 files' production
counts match the README's table exactly. One discrepancy in the
total column: sva.rs is 519 lines by wc -l, not the 516 the
README's table states (the production count, 448, is correct on both
sides — this is a wc -l transcription slip in the "total" column
only, not a content or size-rule problem). Longest-function census
(brace-matched, independent script) over all 15 files: only stmt_kind
(279), expr (233) and prop_expr (168) exceed 150 lines, matching
the claim exactly; each carries a one-line doc comment saying it is a
dispatch table over an enum and stays whole. No file exceeds 800
production lines (stmt.rs at 573 is the largest).
One-sentence test, read fresh off each file's contents and //!
doc, not the README's table:
mod.rs,verbatim.rs,comment.rs,phrase.rs,list.rs,item.rs,module.rs,instance.rs,decl.rs,routine.rs,class.rs,stmt.rs,expr.rs,sva.rs: each describable in one sentence whose "and" clauses enumerate forms inside a single grammar domain or a single piece of shared machinery (not two unrelated responsibilities) — no MEDIUM here.mod.rs's sentence joins three things (exports,Fmtstate, name helpers), but that is the ordinary shape of a directory'smod.rsand stays small (152 prod lines); not flagged.- Every file's
//!states why the cut is where it is (a shared boundary, a dispatch-table rationale, a "this belongs to the sibling that already owns X" note) exceptcover.rs: its doc comment is purely descriptive (header/coverpoint/cross/bins/options) with no sentence saying why covergroups are their own file. The rationale exists — one sentence, inclass.rs's doc ("Covergroups, the other DV construct a class holds, are large enough to be a sibling module") and in the work log — butcover.rsitself doesn't carry it. LOW: add one clause tocover.rs's//!(or leave as is; it is discoverable fromclass.rsand the README).
Docs. README has all seven required sections in order. Module-map
spot-check, five ranges read out of git show 159f6a0:…/format.rs and
matched against file contents: verbatim.rs 163–169 (the Slot enum
doc + body), routine.rs 2605–2644 (tf_args — confirmed only in
routine.rs by grep -l), cover.rs 3312–3713 (covergroup doc comment
at the start; the range end lands inside select_expr, at first glance
an odd fit for a "covergroup" file, but SelectExpr (vlog_parser::ast
line 2886) is the bin-select-expression AST node from IEEE 1800 §19 —
binsof/with/select — so it is covergroup-only and correctly
carved into cover.rs; confirmed select_expr exists only in
cover.rs by grep -l), sva.rs 3715–4221 (SVA section banner at the
start, slot_comments_tight's body at the end, both present verbatim in
sva.rs), instance.rs 5271–5277 + 5298–5312 (drive_strength and
holds_verbatim_value, both confirmed only in instance.rs). All five
check out.
TODO.md: only the Lane B line changed, [ ] → [x], text otherwise
identical — confirmed by git diff 159f6a0 -- TODO.md.
Findings summary
- LOW:
sva.rstable "total" column says 516, actualwc -lis 519 (production count 448 is correct both places). - LOW:
cover.rs's//!doc doesn't itself say why covergroups are a separate file (rationale lives inclass.rs's doc and the work log instead).
No HIGH or CRITICAL findings: no changed code line, no dropped or altered content, no public path change, no test-count drop, no output or exit-code difference, opentitan untouched beyond its pre-existing diffs.
Verdict: PASS — three LOW doc nits, no forcing findings.
Review
2026-09-02 — lead. Accepted; merged fast-forward as the first lane of
§28. This is what a pure move should look like: fifteen files a reader
can name in one sentence each, the three dispatch tables left whole and
saying so, pub(super) entry points taken from the compiler rather than
guessed, and the proof done twice — the dev's line-multiset and
signature census, then QA's from scratch — on top of the gates
(per-binary counts identical, 4 807 files byte-identical, public item
list unchanged). The cuts that differ from the plan are better than the
plan: instance out of module, cover out of class, verbatim
instead of directive, and the comment machinery out of mod.rs, which
would otherwise have been the thousand-line file the round exists to
remove. The wholesale Write of mod.rs is acceptable because the
multiset check exists; it would not be without it. QA's two LOW nits
fixed at review: the sva.rs total and a why-sentence in cover.rs's
module doc.