Expand description
Array-splitting mode for SplitRS.
Some Rust source files are dominated by a single oversized static (or
const) item whose initializer is one enormous array / slice literal — a
large data table, for example a unit catalogue or a force-field parameter
set. The default item-granularity splitter cannot break such a file up:
the whole table is one AST item, so it always lands intact in a single
generated module that remains over the line budget.
This module implements a dedicated pass that splits the elements of such
literals across several chunk files, then reconstructs the original
pub static NAME: &[T] in a generated mod.rs using compile-time slice
concatenation. The reconstruction preserves the exact public type
(&'static [T]), so no downstream consumer needs to change.
§Generated layout
For an input units_base.rs containing
pub static ALL_BASE_UNITS: &[UcumAtom] = &[ /* thousands of entries */ ];the pass produces a directory units_base/ containing:
chunk_0.rs,chunk_1.rs, … — each exportingpub(super) static ALL_BASE_UNITS_PART_0: &[UcumAtom] = &[ … ];mod.rs— re-declares the chunk modules, keeps any other top-level items verbatim, and rebuildspub static ALL_BASE_UNITS: &[UcumAtom]from the parts via aconst fnconcatenation.
The original units_base.rs is removed. Because the parent module declared
pub mod units_base;, the directory module is a drop-in replacement and
super::units_base::ALL_BASE_UNITS keeps resolving to the same type.
§Reconstruction technique
Compile-time concatenation of &'static [T] into a single &'static [T]
is performed with a const fn that copies every element into a backing
[T; N] array. T must be Copy (true for every plain data-table element
type — structs of scalars / &'static str, or tuples thereof). The const
filler value reuses the first element of the first chunk, so no synthetic
default value is required and the technique is fully type-agnostic.
Structs§
- Array
Analysis - Result of analysing a file for splittable array items.
- Array
Item - A top-level array/slice
staticorconstthat is a candidate for element-level splitting.
Functions§
- analyse_
arrays - Analyse
file, classifying its top-level items. Arraystatic/constitems whose rendered element list exceedsmax_linesare collected as splittable; everything else is preserved. - run_
split_ arrays - Core entry point: split oversized array literals in
input_fileinto a sub-directory named after the file stem.