Expand description
Tier 2 step 1 — the cohesion clusterer.
This is not a bin-packer. The objective is to put related items
together and unrelated items apart. The number of output files is a
consequence of how related the code is, never something to minimise: if a
file genuinely contains ten unrelated 50-line items, ten 50-line files is the
correct answer, and merging any of them to “save a file” or “fill a bin”
makes the split worse. max_loc is only a ceiling, never a packing
target: a transitively related group bigger than half the ceiling is
partitioned into roughly equal cohesive parts (strongest reference edges
bond first, so the cuts fall on the weakest edges), leaning toward more
files rather than files that graze the ceiling.
Section banners bound responsibilities: references never join different
sections. Inside a section, relation is a sibling reference (the manifest’s
adjacency_hint). Local types with inherent impls stay in the parent;
their shared ownership does not bond otherwise independent impl blocks.
Clustering is greedy agglomerative on those reference edges, heaviest edge
first, capped at the component’s balanced share; leftover clusters of the
same component are then consolidated in source order up to the same share.
Items with no edges stay alone. Imports/preamble are pulled out as a shared
header (the reassembler copies into each module only the imports it
references); an item that is itself >= max_loc is reported oversized.
These chunk classes never enter clustering:
- local structs, enums and unions with inherent impls stay in the parent, preserving private fields for the implementation modules below them;
- owner-local impls and lexical macro dependencies/consumers stay in their original scope and source order rather than changing restricted visibility or textual macro resolution;
- visibility-qualified
use/extern crate(pub use ...) are re-exports — the file’s API surface — and stay at the root verbatim (root_items); - content-less
mod name;declarations bind files relative to the root’s directory and stay at the root verbatim (root_items); - body-carrying
mod name { ... }items are already module boundaries and are handled separately (mods). Unconditional modules are extracted; conditional modules retain their braced scopes inline.
Structs§
- Oversized
- An item whose own LOC is at or above the ceiling.
- Part
- One cohesive module: a cluster of related items.
- Split
Plan - The result of planning a split.
Functions§
- plan_
split - Cluster
exploded’s items into cohesive modules, each< max_loc.