Skip to content

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

Description

@proggeramlug

Part of #1097.

Current state

crates/perry-codegen/src/expr.rs is 15,044 lines. The single function lower_expr spans roughly lines 1212 → 13483 (~12k lines) — one match arm per Expr::* variant, several of which are 500+ lines each. Helpers (lower_object_literal, lower_array_literal, lower_index_set_fast, lower_channel_reduction, try_lower_flat_const_index_get, the NaN-box inline helpers, the V8-export-call helpers, etc.) sit on either side.

The problem isn't conceptual — it's mechanical. Adding a new variant means scrolling past 10k+ lines, and ripgrep'ping for a helper named lower_object_literal returns the right hit instantly but you still land in a sea of unrelated arms.

Proposed split

Move the file into a directory module crates/perry-codegen/src/expr/ with:

  • expr/mod.rs — keeps lower_expr as the entry point + the trivial arms (literals, LocalGet/LocalSet, Update, Undefined, Null, Bool, DateNow, etc.). Maybe ~1k–1.5k lines.
  • expr/typeof_void.rsExpr::TypeOf, Expr::Void
  • expr/binary.rsExpr::Binary arm (lines ~1732–2028)
  • expr/unary.rsExpr::Unary arm (~2028–2084)
  • expr/compare.rsExpr::Compare arm (~2084–2437)
  • expr/object_literal.rsExpr::Object arm + lower_object_literal helper (~14072–14260)
  • expr/array_literal.rsExpr::Array, Expr::ArraySpread arms + lower_array_literal (~14260–14439)
  • expr/index.rsExpr::IndexGet, lower_index_set_fast, try_lower_flat_const_index_get (~2507–2983, ~13518–13614, ~14439–14591)
  • expr/property_get.rs — the cluster of Expr::PropertyGet arms (~2983–3200+, several distinct shapes)
  • expr/v8_interop.rsemit_v8_export_call, emit_v8_member_method_call, try_static_class_name, import_origin_suffix (lines 62–328)
  • expr/nanbox_inline.rsnanbox_pointer_inline, nanbox_bigint_inline, nanbox_string_inline, i32_bool_to_nanbox, unbox_to_i64, unbox_str_handle (~35–388, 13937–14046)
  • expr/strings.rsemit_string_literal_global, Expr::String, Expr::WtfString arms
  • expr/channel.rstry_match_channel_reduction, lower_channel_reduction, extract_array_of_object_shape (~14611–end)
  • expr/i32_fast_path.rsis_known_finite, can_lower_expr_as_i32, lower_expr_as_i32, try_flat_const_2d_int (~13483–13860)
  • expr/url_helpers.rslower_url_string_getter
  • expr/write_barrier.rsemit_write_barrier, lower_stream_super_init

Each submodule re-exports its pub(crate) helpers; expr/mod.rs keeps pub(crate) fn lower_expr as the single dispatch entry point that delegates each variant to its module.

Acceptance

  • Pure file moves: git diff -M -C90% shows ≥95% rename detection
  • cargo test --release --workspace --exclude perry-ui-* green
  • ./run_parity_tests.sh shows no regression vs. main
  • Public surface (anything pub(crate) consumed outside expr.rs) preserved via re-exports

Metadata

Metadata

Assignees

Labels

toolingDeveloper tooling, CI, tests, or release infrastructure

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions