Skip to content

chore(codegen): #1098 — split expr.rs (pure refactor, no behavior change) - #1147

Merged
proggeramlug merged 4 commits into
mainfrom
chore/1098-split-codegen-expr
May 20, 2026
Merged

chore(codegen): #1098 — split expr.rs (pure refactor, no behavior change)#1147
proggeramlug merged 4 commits into
mainfrom
chore/1098-split-codegen-expr

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Closes #1098. Part of #1097.

Pure mechanical split of the 15.3k-line LLVM expr lowering into expr/ submodules. expr.rs is now expr/mod.rs (renamed; git detects with -M at 88% similarity), with self-contained helper clusters extracted into 11 submodules. lower_expr itself stays in mod.rs as the single dispatch entry point — its match body is byte-for-byte identical to origin/main.

Final module list

Module Contents
expr/mod.rs (~13,260 lines) lower_expr + FnCtx struct/impl + FlatConstInfo
expr/nanbox_inline.rs nanbox_pointer_inline, nanbox_bigint_inline, nanbox_pointer_inline_pub, nanbox_string_inline, i32_bool_to_nanbox
expr/v8_interop.rs import_origin_suffix, emit_v8_export_call, emit_v8_member_method_call, try_static_class_name
expr/strings.rs emit_string_literal_global
expr/write_barrier.rs emit_write_barrier, emit_write_barrier_slot_on_block, lower_stream_super_init
expr/helpers.rs proxy_build_args_array, buffer_alias_metadata_suffix, lower_js_args_array, unbox_to_i64, unbox_str_handle, is_global_this_builtin_name, is_global_this_builtin_function_name
expr/url_helpers.rs lower_url_string_getter
expr/object_literal.rs lower_object_literal
expr/array_literal.rs lower_array_literal
expr/index.rs lower_index_set_fast
expr/i32_fast_path.rs is_known_finite, try_lower_flat_const_index_get, try_flat_const_2d_int, can_lower_expr_as_i32, lower_expr_as_i32
expr/channel.rs variant_name, extract_array_of_object_shape, ChannelReduction, try_match_channel_reduction, lower_channel_reduction

Scope deviation from the issue's proposed map

The issue suggested also splitting each Expr::* arm of the giant lower_expr match into its own submodule (binary.rs, unary.rs, compare.rs, property_get.rs, typeof_void.rs). I did not do this. Those arms share lower_expr's recursion and a large amount of local context, and extracting them safely would require careful per-arm context threading — a risk multiplier on a hot codegen path that the issue itself explicitly accepts ("a partial-but-substantial split is acceptable if a full split risks correctness"). What landed:

  • All standalone helper clusters that live OUTSIDE the match (the head of the file at lines 35-434 originally, and the tail at lines 13745-15310 originally) are extracted. That's 12k → 2k lines outside the match.
  • The match itself (lines 1240-13602 in current mod.rs) is untouched and byte-identical to origin/main, including the lower_expr signature and every arm body.
  • Per-variant extraction of match arms is deferred to a follow-up if Ralph still wants it — the helpers are now isolated, so future arm extraction has cleaner per-module homes to dispatch into.

Public surface preservation

Every pub(crate) item that was used outside expr.rs is re-exported from expr/mod.rs via pub(crate) use submodule::* blocks, so existing crate::expr::X paths (in stmt.rs, codegen.rs, lower_call.rs, lower_call/*.rs, lower_array_method.rs, lower_string_method.rs, lower_conditional.rs, type_analysis.rs, runtime_decls.rs) resolve unchanged. FnCtx, FlatConstInfo, and ChannelReduction types remain at their original crate::expr:: paths. No external imports needed updating.

Verification

  • cargo build --release -p perry-codegen — clean, 4 warnings (all pre-existing baseline)
  • cargo build --release (full workspace) — clean, Finished release profile in 5m 13s
  • cargo test --release --workspace --exclude perry-ui-{ios,tvos,watchos,visionos,android,windows,gtk4}1304 passed, 0 failed, no panics, no errors
  • ./run_parity_tests.sh (LLVM backend) — 438 pass / 35 known-fail / 13 known-compile-fail / 13 skipped → 92.6% pass rate
  • ✅ Zero parity regressions vs origin/main: every output mismatch on this branch is in test-parity/known_failures.json, except test_node_http_client_request and test_parity_cron — both verified to fail identically on origin/main (rebuilt + re-ran origin/main parity on these two tests; they're pre-existing known-failure-list gaps tracked by test-parity: audit known_failures.json — every entry needs an issue # and date #797, not regressions).
  • ✅ Byte-identity check: extracted lower_expr (619 KB body), FnCtx struct, impl FnCtx, FlatConstInfo, and 7 spot-checked moved helpers (lower_channel_reduction, lower_expr_as_i32, lower_object_literal, lower_array_literal, lower_index_set_fast, emit_v8_member_method_call, lower_stream_super_init) are byte-for-byte identical between this branch and origin/main.
  • git diff origin/main -M -C --summary: rename crates/perry-codegen/src/{expr.rs => expr/mod.rs} (88%) — well above the 90% issue threshold isn't quite met because so much code moved out, but the rename is detected and every submodule is a verbatim extraction.

Commits

3 pure-move commits, each builds cleanly on its own:

  1. 0c192b2c extract channel + i32_fast_path submodules
  2. 1220d255 extract write_barrier, helpers, url_helpers, object_literal, array_literal, index submodules
  3. a9f16bbd extract nanbox_inline, strings, v8_interop submodules

No version bump / changelog per external-contributor convention.

proggeramlug and others added 4 commits May 19, 2026 21:19
… url_helpers, object_literal, array_literal, index submodules (behavior-preserving)
… v8_interop submodules (behavior-preserving)
@proggeramlug
proggeramlug merged commit f448ca4 into main May 20, 2026
8 of 9 checks passed
@proggeramlug
proggeramlug deleted the chore/1098-split-codegen-expr branch May 20, 2026 05:50
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.

chore(codegen): split crates/perry-codegen/src/expr.rs (15k lines, one giant lower_expr match)

1 participant