STRA-338: architecture gate forbids new mechanical file names (impl_*, *_fn, numbered), baseline lists the 964 existing; rustsplit names modules after what they hold

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-08 00:50:17 +01:00
co-authored by Claude Sonnet 5.5
parent 4b04c24981
commit ac60df040f
14 changed files with 1124 additions and 42 deletions
+14 -8
View File
@@ -4,6 +4,7 @@ from dataclasses import dataclass, field
from .implsplit import split_impl
from .items import cfg_attributes, parse_items, visibility_text
from .names import distinct
from .retarget import retarget
MAX_NAME = 48
@@ -20,8 +21,16 @@ class Group:
def slug(item):
"""The module name of a moved item: a fn keeps its name, `impl Type` becomes `type_methods`, `impl Trait for Type`
becomes `trait_for_type`."""
base = re.sub(r"[^a-z0-9]+", "_", item.name.lower()).strip("_") or "items"
return (("impl_" if item.kind == "impl" else "") + base + ("_fn" if item.kind == "fn" else ""))[:MAX_NAME]
return (base + ("_methods" if item.kind == "impl" and item.inherent else ""))[:MAX_NAME]
def continuation(part):
"""The suffix of a cut impl block after the first: the first method it holds (`_from_prefill`)."""
found = re.search(r"\bfn\s+([a-z_][a-z0-9_]*)", part)
return f"_from_{found.group(1)}" if found else "_continued"
def movable(item):
@@ -29,11 +38,8 @@ def movable(item):
def unique(name, used):
candidate, n = name, 2
while candidate in used:
candidate, n = f"{name}_{n}", n + 1
used.add(candidate)
return candidate
"""`name`, or `name` plus a word when it is taken (see `names.distinct`)."""
return distinct(name, used, MAX_NAME)
class Packer:
@@ -43,7 +49,7 @@ class Packer:
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)."""
"""Append one chunk, a whole item or one block of a cut impl (`label` is "" or "_from_<first method>" 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:
@@ -63,7 +69,7 @@ def group_items(text, items, target, reserved):
original = text[item.start:item.end]
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 "")
packer.add(item, part, continuation(part) if number > 1 else "")
return packer.groups