STRA-338 S12c: fns and impl blocks of 162 hot-path modules move into child modules (leleka-runtime, cuda-driver, deploy, cpu-sys)

The same lexer-based splitter as S12b, now with explicit re-exports: every moved free fn comes back to its module under its old name and old visibility (cfg attributes carried), so a name can never clash with another glob import. 162 module files of leleka-runtime (68), cuda-driver (84), deploy (10), cpu-sys, igpu and leleka-memory are split into groups of about 250 lines; types, constants, macros, nested modules and tests stay. Not touched: the files kar-off-ab edits, crate roots (lib.rs, main.rs, bin/*), and giant single impl blocks (next). This changes codegen-unit placement of engine code, so it is covered by the bitwise replay and the paired A/B on the 5090, not by a binary comparison.
This commit is contained in:
Pavlo Ratushnyi
2026-11-05 15:52:18 +01:00
parent 3254b1912b
commit 95f768cfbf
659 changed files with 114503 additions and 108480 deletions
+20 -6
View File
@@ -2,7 +2,7 @@
import re
from dataclasses import dataclass, field
from .items import parse_items
from .items import cfg_attributes, parse_items, visibility_text
from .retarget import retarget
MAX_NAME = 48
@@ -15,11 +15,12 @@ class Group:
chunks: list = field(default_factory=list)
lines: int = 0
members: list = field(default_factory=list)
exports: list = field(default_factory=list) # (cfg attributes, visibility, fn name) of the moved free fns
def slug(item):
base = re.sub(r"[^a-z0-9]+", "_", item.name.lower()).strip("_") or "items"
return (("impl_" if item.kind == "impl" else "") + base)[:MAX_NAME]
return (("impl_" if item.kind == "impl" else "") + base + ("_fn" if item.kind == "fn" else ""))[:MAX_NAME]
def movable(item):
@@ -40,12 +41,15 @@ def group_items(text, items, target, reserved):
for item in items:
if not movable(item):
continue
chunk = retarget(text[item.start:item.end], item.kind, item.inherent)
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
@@ -63,11 +67,21 @@ def child_text(group):
return header + body.rstrip("\n") + "\n"
def export_lines(group):
"""`use` lines that bring each moved free fn back under its old name with its old visibility."""
rows = []
for cfgs, vis, name in group.exports:
lines = [*cfgs, "#[allow(unused_imports)]", f"{vis + ' ' if vis else ''}use {group.name}::{name};"]
rows.append("\n".join(lines))
return rows
def declarations(groups, explicit_dir):
rows = []
for group in groups:
attr = f'#[path = "{explicit_dir}/{group.name}.rs"]\n' if explicit_dir else ""
rows.append(f"{attr}mod {group.name};\n#[allow(unused_imports)]\npub use {group.name}::*;")
attr = [f'#[path = "{explicit_dir}/{group.name}.rs"]'] if explicit_dir else []
rows.append("\n".join([*attr, f"mod {group.name};"]))
rows.extend(export_lines(group))
return "\n".join(rows)
@@ -75,7 +89,7 @@ def plan_split(text, target, explicit_dir=None, reserved=()):
"""(new parent text, {child name: child text}), or None when nothing would move."""
items = parse_items(text)
groups = group_items(text, items, target, reserved)
if not groups:
if not groups or len(groups) == 1 and groups[0].lines >= 0.8 * (text.count(chr(10)) + 1):
return None
moved = [(i.start, i.end) for i in items if movable(i)]
parent = remove_ranges(text, moved).rstrip("\n") + "\n\n" + declarations(groups, explicit_dir) + "\n"