diff --git a/CLAUDE.md b/CLAUDE.md index d6adef4..b38ef83 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -29,6 +29,38 @@ doing anything. - Match the style of the surrounding code (comment density, naming, module layout). +## File and function size + +Files and functions are sized for a human reader, not a compiler. + +- **Target 300–600 production lines per file.** At 800, consider + splitting. Above 1,200, an explicit reason not to split goes in the + feature README. Test lines do not count, but a `#[cfg(test)]` block + that dwarfs its file moves to its own module or `tests/` file. +- **Functions: 10–50 lines.** Investigate anything over 80; anything + over 150 needs a reason in a comment (a dispatch table over an enum + is the usual one). +- Looser for declarative tables, generated code, snapshots and + repetitive tests. Complexity matters more than the count: 800 lines + of grammar productions read more easily than 250 lines of state. +- **The real test is one sentence.** A human should be able to say what + a file is responsible for in one sentence and predict which parts a + change touches. Several "and" clauses mean the file wants to be + several modules. +- A split is a **pure move**: public paths stay the same (re-export from + the old `mod`), behaviour and output stay byte-identical, the test + count does not drop. Measured, not asserted — the corpus and + opentitan byte-identity gates are the proof. + +Measured 2026-09-02 (production lines): `vlog_parser/src/parser.rs` +8 786, `vlog_formatter/src/format.rs` 5 444, `vlog_parser/src/ast.rs` +3 313, `lucisv_server/src/server.rs` 2 559 (+6 300 test), +`vlog_semantic/src/bind.rs` 2 378, `vlog_semantic/src/workspace.rs` +1 975, `vlog_refactor/src/ports.rs` 1 778, +`lucisv_server/src/completion.rs` 1 716 — thirteen files over 800. +These are decomposition work (TODO §28), and every one of them is where +feature lanes collide, which is the other reason to split them. + ## Rust standards - `cargo fmt` clean, `cargo clippy --all-targets` clean (no `#[allow]`