STRA-338 S12d: long impl blocks are cut between methods and the remaining oversize modules split (53 files)

The splitter now cuts an inherent impl longer than its target into several impl blocks of the same type between associated items (the generics and where clause repeated, the doc comment kept on the first block), so the giant impls left by S12b/S12c (up to 2,000 lines) split too. 53 further module files of the cold and hot crates are split; the baseline drops to 127 oversize files holding 109,000 lines (329 files and 303,000 lines on main). Types, constants, macros, tests and the files kar-off-ab edits stay; crate roots and bins are untouched.
This commit is contained in:
Pavlo Ratushnyi
2026-11-05 16:16:36 +01:00
parent 95f768cfbf
commit cb790da36b
251 changed files with 41622 additions and 39736 deletions
+27 -14
View File
@@ -2,6 +2,7 @@
import re
from dataclasses import dataclass, field
from .implsplit import split_impl
from .items import cfg_attributes, parse_items, visibility_text
from .retarget import retarget
@@ -35,23 +36,35 @@ def unique(name, used):
return candidate
class Packer:
"""Fills groups of about `target` lines with chunks, in order."""
def __init__(self, target, reserved):
self.target, self.used, self.groups = target, set(reserved), []
def add(self, item, part, label):
"""Append one chunk, a whole item or one block of a cut impl (`label` is "" or "_2", "_3" ... for cut blocks)."""
chunk = retarget(part, item.kind, item.inherent)
lines = chunk.count("\n") + 1
if not self.groups or self.groups[-1].lines + lines > self.target:
self.groups.append(Group(unique(slug(item) + label, self.used)))
group = self.groups[-1]
group.chunks.append(chunk)
group.members.append(f"{item.kind} {item.name}" + (f" ({label.strip('_')})" if label else ""))
if item.kind == "fn":
group.exports.append((cfg_attributes(item.attrs), visibility_text(part), item.name))
group.lines += lines
def group_items(text, items, target, reserved):
"""Pack the movable items, in file order, into groups of about `target` lines."""
groups, used = [], set(reserved)
for item in items:
if not movable(item):
continue
packer = Packer(target, reserved)
for item in (i for i in items if movable(i)):
original = text[item.start:item.end]
chunk = retarget(original, item.kind, item.inherent)
lines = chunk.count("\n") + 1
if not groups or groups[-1].lines + lines > target:
groups.append(Group(unique(slug(item), used)))
groups[-1].chunks.append(chunk)
groups[-1].members.append(f"{item.kind} {item.name}")
if item.kind == "fn":
groups[-1].exports.append((cfg_attributes(item.attrs), visibility_text(original), item.name))
groups[-1].lines += lines
return groups
parts = split_impl(original, target) if item.kind == "impl" and item.inherent else [original]
for number, part in enumerate(parts, 1):
packer.add(item, part, f"_{number}" if number > 1 else "")
return packer.groups
def remove_ranges(text, ranges):