Skip to content

refactor: split the 16 files over the 2000-line lint gate - #7256

Merged
proggeramlug merged 2 commits into
mainfrom
chore/split-large-files-lint
Aug 2, 2026
Merged

refactor: split the 16 files over the 2000-line lint gate#7256
proggeramlug merged 2 commits into
mainfrom
chore/split-large-files-lint

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Splits the 16 tracked Rust files that had drifted past scripts/check_file_size.sh's 2,000-line cap. bash scripts/check_file_size.sh now exits 0 with no new allowlist entries — every file was split, none was deferred.

This does NOT turn lint green on its own — please read

lint has been red on main for weeks, but not because of the file-size gate. The job dies two steps earlier and never reaches it. Verified against the last four nightly runs:

run date step that failed
30735945650 08-02 Public benchmark evidence freshness
30687607155 08-01 Audit workspace architecture
30610234977 07-31 Audit workspace architecture
30519299737 07-30 Public benchmark evidence freshness

Running every lint step locally at origin/main (cdb3934) gives the true blocker set — four independent failures, of which this PR fixes one:

# step at origin/main after this PR
1 cargo fmt --all -- --check PASS PASS
2 workspace_architecture.py --check PASS PASS
3 ci_public_baseline_check.py FAIL (2) FAIL (2) — untouched
4 check_file_size.sh FAIL (1) PASS
5 binding_pins.mjs --check PASS PASS
6 gc_store_site_inventory.py FAIL (1) FAIL (1) — untouched
7 addr_class_inventory.py FAIL (1) FAIL (1) — untouched
8 gap_snapshot.py --self-test PASS PASS
9 parity_known_failures.py --self-test PASS PASS
10 gc_gate_wiring_check.py PASS PASS

Because the steps run in order and the job stops at the first failure, #3 must be fixed before this PR's effect is even observable in CI.

The splits

All 16 under the cap, most well under 1,900 to leave headroom.

file before after seam
perry-runtime/.../native_module/callable_exports.rs 2596 1851 CALLABLE_EXPORT_ARITY_TABLE + lookup + tests -> callable_export_arity_table.rs
perry-runtime/.../native_module/constants.rs 2427 1410 zlib/crypto/os_errno/os_signal const groups -> constants_tables.rs
perry-runtime/.../native_module/callable_export_check.rs 2218 1106 CALLABLE_EXPORT_TABLE static -> callable_export_table.rs
perry-codegen/src/expr/index_get.rs 2164 1387 guarded-array + inline-dyn-typed-array emitters -> index_get/
perry-stdlib/src/worker_threads.rs 2157 1508 MessagePort / BroadcastChannel / pump -> worker_threads/
perry/src/commands/compile/library_search.rs 2155 1823 7 inline #[cfg(test)] mod -> library_search/
perry-runtime/src/gc/tests/layout_trace.rs 2152 425 4 topical test groups -> layout_trace/
perry-codegen/src/codegen/typed_abi.rs 2092 1358 body lowering + tests -> typed_abi/
perry-runtime/src/process/env_misc.rs 2064 1503 exec_env.rs + attributes.rs
perry-hir/src/lower_decl/block.rs 2047 1394 closure-ident scan + var-name collection -> block/
perry-hir/src/lower/expr_call/native_module.rs 2046 716 5 receiver-dispatch blocks -> native_module/
perry-runtime/src/gc/tests/runtime_roots.rs 2035 604 3 topical test groups -> runtime_roots/
perry-runtime/src/array/generic.rs 2021 1577 object-mutator block -> generic_object.rs
perry-stdlib/src/tls.rs 2019 1116 secure-context / module-api / dispatch -> tls/
perry-runtime/src/node_submodules/test.rs 2018 1722 test_snapshot.rs + test_reporters.rs
perry-ext-net/src/lib.rs 2010 1788 Transport -> transport.rs; tests -> tests.rs

The only non-move edits are visibility widenings forced by a move (fn -> pub(super) fn), mod/use plumbing, and removal of imports left unused in a trunk.

Two subtleties that would have caused silent behaviour changes

1. Self-harvesting oracle tests. Three native_module files contain tests that harvest every string literal in their own source text via include_str!("<self>.rs") and cross-product them — callable_export_check.rs even asserts checked > 100_000. Splitting a file silently shrinks that literal universe, weakening the test while it still passes. Those sites now read

let source = concat!(include_str!("constants.rs"), include_str!("constants_tables.rs"));

so the harvested set is exactly what it was.

2. Order-sensitive tables. CALLABLE_EXPORT_ARITY_TABLE and CALLABLE_EXPORT_TABLE are binary_search targets — element order is load-bearing. Each moved as one intact item; no table was partitioned. The BUFFER_* / SQLITE_* / ASSERT_* slices are for-iterated (installation order is observable in for...in), so they were not moved at all.

Evidence of no behaviour change

  • cargo check --tests clean (exit 0) on all six crates: perry, perry-runtime, perry-stdlib, perry-codegen, perry-hir, perry-ext-net.
  • Warning set unchanged. A clean-target cargo check -p perry-runtime --tests emits the same 4 warnings at origin/main and on this branch — all in files this PR never touches.
  • Crate-wide token conservation. Multiset of Rust tokens (comments/whitespace stripped, raw strings handled) over all .rs files per crate, origin/main vs branch: 5,392,125 -> 5,394,082 tokens, zero non-plumbing losses. The only two flagged differences were backslash-line-continuation string literals whose continuation indentation changed; Rust strips that whitespace at compile time, and the resulting runtime values were verified byte-identical.
  • GC test files reassemble byte-identically. Parent + children concatenated reproduces the original file exactly. Test names diffed before/after: empty diff. And they were run: gc::tests::layout_trace 47 passed, gc::tests::runtime_roots 77 passed, matching pre-split. (The naive grep count of 79 differs because callback_scanners.rs has two #[cfg(feature = "ohos-napi")]-gated tests the runner correctly excludes.)
  • Test counts per touched file, preserved: library_search 21->21, ext-net 4->4, typed_abi 6->6, native_module (hir) 8->8, constants 12->12, callable_exports 3->3, callable_export_check 2->2, env_misc 3->3, layout_trace 47->47, runtime_roots 40->40.
  • FFI surface unchanged. pub extern "C" fn symbol lists diffed empty: perry-stdlib 68->68 (60 #[no_mangle] attributes before and after), perry-ext-net 23->23. Moving a #[no_mangle] fn between modules cannot change its exported symbol, and none was made private.
  • Gate inventories unchanged. addr_class_inventory.py and gc_store_site_inventory.py produce byte-identical finding sets to origin/main (3 and 19 findings respectively, same files, same counts). No allowlist or ratchet-baseline edit was needed — this PR touches crates/ only.

Byte-identical compiler output (differential codegen A/B)

Two perry binaries built from origin/main and this branch (perry-dev profile, one target dir each), then run over a 40-file TypeScript corpus with --trace llvm, comparing the emitted LLVM IR.

IDENTICAL: 42   DIFFERENT: 0   MISSING: 0
base IR lines:   164219
branch IR lines: 164219
call instructions  base: 7835   branch: 7835

All 42 emitted IR modules are byte-identical. The two binaries themselves are not identical (43M vs 44M, differing md5), so this is not a vacuous comparison of one build against itself.

Per CLAUDE.md's hazard #4"a gate must assert its subject was live" — the corpus was checked to actually exercise the restructured code, counting real call instructions (not extern declarations) in the emitted IR:

restructured module evidence it was live
hir .../native_module/process_module.rs js_nm_install_process x14, js_process_emit_before_exit x40, js_process_argv x3, js_process_cwd x3
hir .../native_module/buffer_statics.rs js_buffer_validate_size x9, js_buffer_alloc x3, js_uint8array_new x11
hir .../native_module/reflect_statics.rs js_reflect_get_metadata x16, js_reflect_define_metadata x16
hir .../native_module/object_statics.rs js_object_alloc_class_inline_keys x10, js_build_class_keys_array x25
codegen/expr/index_get/ js_dyn_index_get x8, js_typed_array_get x1, js_array_push_f64_temp_rooted x250
codegen/codegen/typed_abi/ js_typed_feedback_object_get_field_by_name_f64 x52

This matters most for perry-hir/.../native_module.rs, where five dispatch blocks were extracted into helpers chained in the original order — the one change whose arm-ordering could not be proven by token conservation alone.

The addr-class trap, and how it was avoided

The ratchet baseline is path-keyed with exact counts, and a new file gaining a ratcheted site has baseline 0 — a hard failure. Four of the 16 files carried baseline entries (array/generic.rs 4, node_submodules/test.rs 2, process/env_misc.rs 3+1, perry-stdlib/src/{tls,worker_threads}.rs 1 each). The whole-file allowlist entries (array/generic.rs | *) are path-keyed too, so allowlisted code moving to a sibling loses its suppression.

Both traps fired during the work and were resolved by re-picking seams so every ratcheted and allowlisted site stays in its original fileproto_chain_contains_real_array, non_array_object_receiver, and plain_object_value were deliberately kept in generic.rs for exactly this reason. Hence zero gate-file edits.

What this PR does NOT verify

  • CI is backlogged ~46 deep, so nothing here has been confirmed by CI. Everything above is local, on macOS/aarch64 only.
  • Not run locally: the full cargo test suite, the parity/gap suites, conformance-smoke, and any Linux-only behaviour.
  • The codegen A/B covers 40 files / 42 IR modules, not the whole 1,168-file test-files/ corpus, and it compares compiler output — it therefore says nothing about perry-runtime / perry-stdlib runtime behaviour, which is only covered here by cargo check, the GC test runs, and the unchanged #[no_mangle] export lists.

Follow-ups for the other three lint blockers

In short: the public-baseline artifact's source_fingerprint and harness_fingerprint have both been stale for 40+ commits and can only be cleared by regenerating the artifact with the full Node/Bun/Perry suite on the pinned host; the gc_store_site_inventory failure is 19 store sites needing per-site audit-class judgement; the addr_class_inventory failure is 2 ratchet regressions plus one allowlist entry whose line-substring no longer matches the code it was written for.

Summary by CodeRabbit

  • New Features
    • Added support for array methods on array-like objects, including sorting, concatenation, and splicing.
    • Expanded process APIs with environment-file loading, directory changes, executable replacement, resource usage, title, and umask support.
    • Added TLS certificate, secure-context, cipher, and ALPN APIs.
    • Added BroadcastChannel and expanded MessagePort and worker event handling.
    • Added node:test snapshot assertions and reporter support.
  • Tests
    • Expanded coverage for garbage collection, networking, compilation, TLS, workers, and native APIs.

`scripts/check_file_size.sh` is a required step of the `lint` job and 16
tracked Rust files had drifted past the 2,000-line cap. Split each along an
existing topical seam into sibling modules, re-exporting so every existing
path resolves unchanged.

Pure refactor: no renames, no signature changes, no behaviour change. The only
non-move edits are visibility widenings forced by a move (`fn` ->
`pub(super) fn`), the `mod`/`use` plumbing, and removal of imports left unused
in a trunk.

Two subtleties worth recording:

- The `native_module` oracle tests harvest every string literal in their own
  source via `include_str!("<self>.rs")` and assert a coverage floor. Splitting
  a file silently shrinks that literal universe, so those sites now
  `concat!(include_str!(a), include_str!(b))` to keep it exactly as it was.

- `CALLABLE_EXPORT_ARITY_TABLE` and `CALLABLE_EXPORT_TABLE` are `binary_search`
  targets, so element order is load-bearing. Each table moved as one intact
  item; no table was partitioned.

Evidence: `cargo check --tests` clean on all six crates; crate-wide token
multisets conserved (5.39M tokens, zero non-plumbing losses); GC test files
reassemble byte-identically and `cargo test` reports the same 47 / 77 passing;
`#[no_mangle]` export lists unchanged in the FFI-heavy files. The
`addr_class_inventory.py` and `gc_store_site_inventory.py` finding sets are
byte-identical to origin/main, so no gate-script or allowlist edit was needed.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: de80aac4-eae1-4051-967d-938f73038ca4

📥 Commits

Reviewing files that changed from the base of the PR and between cdb3934 and 709d887.

📒 Files selected for processing (61)
  • changelog.d/7256-split-large-files-lint.md
  • crates/perry-codegen/src/codegen/typed_abi.rs
  • crates/perry-codegen/src/codegen/typed_abi/lower.rs
  • crates/perry-codegen/src/codegen/typed_abi/tests.rs
  • crates/perry-codegen/src/expr/index_get.rs
  • crates/perry-codegen/src/expr/index_get/guarded_array.rs
  • crates/perry-codegen/src/expr/index_get/inline_dyn_typed_array.rs
  • crates/perry-ext-net/src/lib.rs
  • crates/perry-ext-net/src/tests.rs
  • crates/perry-ext-net/src/transport.rs
  • crates/perry-hir/src/lower/expr_call/native_module.rs
  • crates/perry-hir/src/lower/expr_call/native_module/buffer_statics.rs
  • crates/perry-hir/src/lower/expr_call/native_module/imported_module_dispatch.rs
  • crates/perry-hir/src/lower/expr_call/native_module/object_statics.rs
  • crates/perry-hir/src/lower/expr_call/native_module/process_module.rs
  • crates/perry-hir/src/lower/expr_call/native_module/reflect_statics.rs
  • crates/perry-hir/src/lower_decl/block.rs
  • crates/perry-hir/src/lower_decl/block/closure_ident_scan.rs
  • crates/perry-hir/src/lower_decl/block/var_names.rs
  • crates/perry-runtime/src/array/generic.rs
  • crates/perry-runtime/src/array/generic_object.rs
  • crates/perry-runtime/src/array/mod.rs
  • crates/perry-runtime/src/gc/tests/layout_trace.rs
  • crates/perry-runtime/src/gc/tests/layout_trace/array_layout.rs
  • crates/perry-runtime/src/gc/tests/layout_trace/object_closure_slots.rs
  • crates/perry-runtime/src/gc/tests/layout_trace/typed_shape.rs
  • crates/perry-runtime/src/gc/tests/layout_trace/unboxed_object.rs
  • crates/perry-runtime/src/gc/tests/runtime_roots.rs
  • crates/perry-runtime/src/gc/tests/runtime_roots/hook_dispatch_handles.rs
  • crates/perry-runtime/src/gc/tests/runtime_roots/side_table_scanners.rs
  • crates/perry-runtime/src/gc/tests/runtime_roots/transient_handles.rs
  • crates/perry-runtime/src/node_submodules/test.rs
  • crates/perry-runtime/src/node_submodules/test_reporters.rs
  • crates/perry-runtime/src/node_submodules/test_snapshot.rs
  • crates/perry-runtime/src/object/native_module.rs
  • crates/perry-runtime/src/object/native_module/callable_export_arity_table.rs
  • crates/perry-runtime/src/object/native_module/callable_export_check.rs
  • crates/perry-runtime/src/object/native_module/callable_export_table.rs
  • crates/perry-runtime/src/object/native_module/callable_exports.rs
  • crates/perry-runtime/src/object/native_module/constants.rs
  • crates/perry-runtime/src/object/native_module/constants_tables.rs
  • crates/perry-runtime/src/process.rs
  • crates/perry-runtime/src/process/attributes.rs
  • crates/perry-runtime/src/process/env_misc.rs
  • crates/perry-runtime/src/process/exec_env.rs
  • crates/perry-stdlib/src/tls.rs
  • crates/perry-stdlib/src/tls/dispatch.rs
  • crates/perry-stdlib/src/tls/module_api.rs
  • crates/perry-stdlib/src/tls/secure_context.rs
  • crates/perry-stdlib/src/worker_threads.rs
  • crates/perry-stdlib/src/worker_threads/broadcast_channel.rs
  • crates/perry-stdlib/src/worker_threads/message_port.rs
  • crates/perry-stdlib/src/worker_threads/worker_pump.rs
  • crates/perry/src/commands/compile/library_search.rs
  • crates/perry/src/commands/compile/library_search/android_cross_env_tests.rs
  • crates/perry/src/commands/compile/library_search/apple_lib_name_tests.rs
  • crates/perry/src/commands/compile/library_search/harmonyos_sdk_tests.rs
  • crates/perry/src/commands/compile/library_search/llvm_tool_discovery_tests.rs
  • crates/perry/src/commands/compile/library_search/macos_host_candidate_tests.rs
  • crates/perry/src/commands/compile/library_search/native_lib_artifact_tests.rs
  • crates/perry/src/commands/compile/library_search/windows_toolchain_tests.rs

📝 Walkthrough

Walkthrough

This PR splits 16 oversized Rust files into sibling modules across the compiler, runtime, network extension, stdlib, and CLI crates. Existing implementations, tests, and public paths are preserved through re-exports; the changelog documents the refactor and remaining unrelated lint failures.

Changes

Compiler code generation

Layer / File(s) Summary
Typed ABI lowering extraction
crates/perry-codegen/src/codegen/typed_abi.rs, crates/perry-codegen/src/codegen/typed_abi/lower.rs, crates/perry-codegen/src/codegen/typed_abi/tests.rs
Typed f64, i32, i1, string, and receiver-field lowering move into lower.rs; the parent file re-exports the entry points; tests cover safe/unsafe mixed representations and closures.
Guarded index-read lowering
crates/perry-codegen/src/expr/index_get.rs, crates/perry-codegen/src/expr/index_get/guarded_array.rs, crates/perry-codegen/src/expr/index_get/inline_dyn_typed_array.rs
Guarded array index-get, packed-f64 loop, and inline dynamic typed-array reads move into new submodules; call sites use imported helpers.

Network extension decomposition

Layer / File(s) Summary
Transport module and network validation
crates/perry-ext-net/src/lib.rs, crates/perry-ext-net/src/transport.rs, crates/perry-ext-net/src/tests.rs
The Transport enum and async read/write implementations move into transport.rs; network GC, socket, and listener tests move into an external tests module.

HIR lowering decomposition

Layer / File(s) Summary
Native-call dispatcher wiring
crates/perry-hir/src/lower/expr_call/native_module.rs
The dispatcher delegates process, Buffer/Uint8Array, Object, Reflect, and imported-module handling to new helper modules, forwarding unconsumed arguments.
Specialized native-call handlers
crates/perry-hir/src/lower/expr_call/native_module/{buffer_statics,object_statics,process_module,reflect_statics,imported_module_dispatch}.rs
New modules lower Buffer/Uint8Array statics, Object statics, process methods, Reflect statics, and imported-module dispatch, each falling through to caller handling when unmatched.
Block declaration scanners
crates/perry-hir/src/lower_decl/block.rs, crates/perry-hir/src/lower_decl/block/{closure_ident_scan,var_names}.rs
Closure identifier scanning and var/lexical/Annex B name collection move into dedicated modules, re-exported from the parent.

Array and garbage-collection runtime

Layer / File(s) Summary
Array-like mutator dispatch
crates/perry-runtime/src/array/{generic,generic_object,mod}.rs
Generic array-like pop/shift/push/unshift/reverse/splice/sort/concat move into generic_object.rs with new FFI entry points; mod.rs re-exports them.
GC layout and tracing test suites
crates/perry-runtime/src/gc/tests/layout_trace.rs, .../layout_trace/{array_layout,object_closure_slots,typed_shape,unboxed_object}.rs
Layout-tracing tests split into array, closure-slot, typed-shape, and unboxed-object suites covering descriptor transfer, invalidation, and relocation.
GC runtime-root test suites
crates/perry-runtime/src/gc/tests/runtime_roots.rs, .../runtime_roots/{hook_dispatch_handles,side_table_scanners,transient_handles}.rs
Runtime-root tests split into hook-dispatch, side-table, and transient-handle suites covering marking, forwarding, and GC-triggered operations.

Runtime API module decomposition

Layer / File(s) Summary
Test reporter and snapshot modules
crates/perry-runtime/src/node_submodules/{test,test_reporters,test_snapshot}.rs
Reporter formatting (spec/TAP/dot/JUnit/LCOV) and snapshot assertions move into dedicated modules re-exported from test.rs.
Native export and constant tables
crates/perry-runtime/src/object/native_module/{native_module,callable_export_arity_table,callable_export_check,callable_export_table,callable_exports,constants,constants_tables}.rs
Callable-export arity and lookup tables and constant tables (zlib, crypto, errno, signal) move into sorted, binary-searched modules with exhaustive oracle tests.
Process runtime modules
crates/perry-runtime/src/process.rs, crates/perry-runtime/src/process/{attributes,env_misc,exec_env}.rs
Resource usage, title, and umask move into attributes.rs; loadEnvFile, chdir, and execve move into exec_env.rs.
TLS runtime modules
crates/perry-stdlib/src/tls.rs, crates/perry-stdlib/src/tls/{dispatch,module_api,secure_context}.rs
Handle/property dispatch, module-level TLS APIs, and SecureContext construction move into separate modules with re-exported entry points.
Worker-thread modules
crates/perry-stdlib/src/worker_threads.rs, crates/perry-stdlib/src/worker_threads/{broadcast_channel,message_port,worker_pump}.rs
BroadcastChannel, MessagePort, and the worker event pump move into sibling modules with re-exported public entry points.

Compiler tooling tests

Layer / File(s) Summary
Library-search test extraction
crates/perry/src/commands/compile/library_search.rs, .../library_search/*_tests.rs
Android, Apple, HarmonyOS, LLVM, macOS, native-artifact, and Windows toolchain tests move into external test modules.

Changelog

Layer / File(s) Summary
Refactor changelog entry
changelog.d/7256-split-large-files-lint.md
Documents the 16-file split, preserved public paths, safeguards for literal-harvesting tests, and remaining unrelated lint failures.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • PerryTS/perry#6937: Directly continues the callable-export table refactoring, moving the same lookup table and tests into dedicated modules.
  • PerryTS/perry#6940: Directly continues the constant-ladder tableization by relocating the same lookup tables into constants_tables.rs.
  • PerryTS/perry#7223: Addresses the same modularization goal for crates/perry-codegen/src/expr/index_get.rs.

Suggested labels: tooling

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/split-large-files-lint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant