Skip to main content

Module fn_length

Module fn_length 

Source
Expand description

The ratcheted maximum function length (#3167).

A very long function is a place where shape and hygiene go unchecked: the 2026-10-01 review measured emit_agent at 2,064 lines and lower_method_call at 1,118. This module measures every non-test function in the workspace and compares the ones over THRESHOLD lines against the committed ceilings in xtask/fn-length-ceilings.txt.

The rule is a ratchet, not a target: a function over the threshold may not grow past its ceiling, no function may newly cross the threshold, and a ceiling whose function has since shrunk below the threshold (or gone) must be removed. A function that shrinks but stays over the threshold keeps its looser ceiling until someone lowers it with cargo xtask fn-lengths --apply, which rewrites the file from the tree. Lowering a ceiling is always allowed; raising one is the review conversation this probe exists to force.

A method name repeated in one file (fn emit in two impl blocks) is keyed name, name#2, … in source order, so each over-threshold one has its own ceiling.

The measurement reuses the greenfield probes’ scanner, which skips braces inside strings, character literals and comments, and the extents of #[cfg(test)] modules. What is counted: every function in a workspace crate’s src/. What is not: #[cfg(test)] modules and anything under a crate’s tests/ (or benches/), and, because none is checked in, generated Rust (the files that write generated docs are ordinary source and are counted). A generated source file added later should be excluded here deliberately, with the reason.

Structs§

FnLen
One measured function.

Constants§

CEILINGS_FILE
The committed ceilings, relative to the repository root.
THRESHOLD
Functions of at least this many lines (signature to closing brace) are tracked.

Functions§

measure
Every non-test function in the workspace over THRESHOLD lines, longest first.
measure_source
Every function in source (non-test), as (name, lines).
read_ceilings
The committed ceilings: file::name = lines, one per line; # starts a comment.
render_ceilings
The ceilings file’s text for a measurement: every function over the threshold, at its current length.
violations
What is wrong, if anything: a function that grew past its ceiling, one that newly crossed the threshold, and a ceiling that no longer names a function over it.