Skip to content

chore(codegen): split crates/perry-codegen/src/lower_call.rs (11.8k lines, lower_call + extract_options_fields) #1099

Closed

Description

@proggeramlug

Part of #1097.

Current state

crates/perry-codegen/src/lower_call.rs is 11,796 lines with only ~19 top-level functions. A sibling lower_call/ subdir already exists with builtin.rs, native.rs, ui_styling.rs — so the precedent is set, the trunk just hasn't kept moving.

Distribution of the largest functions:

  • lower_call — lines 642 → 3693 (~3.0k)
  • lower_new — lines 3693 → 4480 (~787)
  • apply_field_initializers_recursive — 4480 → 4759
  • extract_options_fields — 4759 → 11366 (~6.6k) — by far the worst
  • Native-module-table iteration helpers — 11439 → end

extract_options_fields is doing far more than its name suggests — it's the "look at this options object literal and decide what to do" mega-helper.

Proposed split

Continue populating crates/perry-codegen/src/lower_call/:

  • lower_call/mod.rs — keep pub(crate) fn lower_call dispatcher only; each major branch delegates
  • lower_call/new.rs — lower_new + apply_field_initializers_recursive
  • lower_call/options.rs — extract_options_fields (split internally; see below)
  • lower_call/buffer_intrinsic.rs — classify_buffer_numeric_read, try_emit_buffer_read_intrinsic, BufferNumericReadSpec (lines 70–297)
  • lower_call/method_override.rs — emit_own_method_override_check
  • lower_call/jsx.rs — decode_jsx_intrinsic_sentinel, split_children_from_props, try_rewrite_perry_tui_jsx_intrinsic, rewrite_jsx_box, rewrite_jsx_text, is_jsx_call_callee, fold_string_concat (lines 419–642)
  • lower_call/native_table.rs — iter_native_module_table, arg_kinds_for, arg_kind_tag, ret_kind_tag, find_outer_writes_expr (lines 11366–end)

extract_options_fields (6.6k lines)

Open in a fresh file and look for the natural seams — almost certainly one branch per native API surface (fastify, ws, redis, mysql2, fs, http, child_process, etc.). Each can become a dedicated lower_call/options/<surface>.rs with a small dispatch table in lower_call/options/mod.rs. This is the largest single win on the file and the most subjective — leave room for the author to discover the right seams when they get into it.

Acceptance

Same conventions as the umbrella (#1097): pure moves, re-exports for stability, full test + parity suite green.

Activity

  1. added
    toolingDeveloper tooling, CI, tests, or release infrastructure
    on May 19, 2026
  2. self-assigned this
    on May 19, 2026
  3. added 2 commits that reference this issue on May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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