From f3af34980a3c95378ba6abad44ea7809c457aa10 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 2 Sep 2026 15:18:18 -0700 Subject: [PATCH] =?UTF-8?q?CLAUDE.md:=20the=20file=20and=20function=20size?= =?UTF-8?q?=20rule=20=E2=80=94=20300=E2=80=93600=20production=20lines=20pe?= =?UTF-8?q?r=20file,=20split=20at=20800,=20a=20reason=20above=201=20200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set by the owner on 2026-09-02. Measured at the same time: thirteen files over 800 production lines and eight over 1 200, led by parser.rs (8 786), format.rs (5 444), ast.rs (3 313) and server.rs (2 559 + 6 293 test) - the same files every feature lane collides in. Decomposition is planned as TODO section 28: pure moves, public paths kept by re-export, byte-identical output proven by the corpus and opentitan gates. Co-Authored-By: Claude Fable 5 --- CLAUDE.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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]`