Skip to content

perf: static method literals, captured closure reuse, argument shape facts - #8796

Merged
proggeramlug merged 1 commit into
mainfrom
merge/b51
Aug 25, 2026
Merged

perf: static method literals, captured closure reuse, argument shape facts#8796
proggeramlug merged 1 commit into
mainfrom
merge/b51

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Lands #8793, #8792 and #8787.

Why these were showing red before

All three had pr-gate failing, but not because of anything they did: main itself was red on cargo-test (byob_readers_and_byte_length_strategy) until #8791 landed a few minutes ago. Re-gated against the fixed baseline, all three are clean.

Validation (on the merged result)

  • All 30 lint-job checkers pass
  • perry-runtime --lib (RUST_TEST_THREADS=1): 2677 passed, 0 failed (+2)
  • perry-codegen --lib: 1236 passed, 0 failed (+6)
  • perry-hir --lib: 335 passed, 0 failed (+1)
  • perry-codegen --tests (all integration suites): 0 failures
  • Squashed tree verified identical to the validated tree

All three carried their own changelog.d/ fragments. No version bump.

Summary by CodeRabbit

  • Performance

    • Improved optimized method calls when argument objects have known, compatible shapes.
    • Improved reuse of captured closures, reducing repeated allocations.
    • Added faster handling for eligible static-key object literals.
  • Reliability

    • Added safeguards so dynamic, aliased, reassigned, proxied, reshaped, or incompatible objects continue using safe fallback behavior.
    • Improved compatibility with garbage collection and moving-memory scenarios.
  • Testing

    • Added extensive regression coverage for optimized calls, object literals, closure reuse, fallback routing, and garbage-collection safety.

…facts

Lands #8793, #8792 and #8787.

#8793 lowers static method literals directly; #8792 indexes captured
closure reuse; #8787 propagates shape facts into argument positions.

All three were showing pr-gate red before #8791 landed, because main
itself was failing `cargo-test` on a Web Streams test. Re-gated against
the fixed baseline, all three are clean.

No version bump.
@coderabbitai

coderabbitai Bot commented Aug 25, 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: dbbda316-3564-4ecd-a9da-6dddd1be5621

📥 Commits

Reviewing files that changed from the base of the PR and between 98ecdc5 and 40ee8e8.

📒 Files selected for processing (32)
  • changelog.d/8787-argument-shape-clones.md
  • changelog.d/8792-captured-closure-cache-hints.md
  • changelog.d/8793-static-method-object-literals.md
  • crates/perry-codegen/src/codegen/argument_shape_clone_tests.rs
  • crates/perry-codegen/src/codegen/artifacts.rs
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/indexed_method_artifacts.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/codegen/opts.rs
  • crates/perry-codegen/src/codegen/ordinary_method_artifacts.rs
  • crates/perry-codegen/src/collectors/mod.rs
  • crates/perry-codegen/src/collectors/proven_args.rs
  • crates/perry-codegen/src/collectors/proven_this.rs
  • crates/perry-codegen/src/collectors/proven_this_routing_tests.rs
  • crates/perry-codegen/src/collectors/ptr_shape.rs
  • crates/perry-codegen/src/collectors/scalar_method_dispatch.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-codegen/src/lower_call/method_override.rs
  • crates/perry-codegen/src/lower_call/property_get/dynamic_dispatch.rs
  • crates/perry-hir/src/lower/expr_object.rs
  • crates/perry-hir/src/lower/tests.rs
  • crates/perry-runtime/src/closure/alloc.rs
  • crates/perry/tests/issue_8774_argument_shape_clones.rs
  • crates/perry/tests/static_method_object_literal.rs
  • test-files/fixtures/issue_8774_argument_shapes/barrel.ts
  • test-files/fixtures/issue_8774_argument_shapes/foreign.ts
  • test-files/fixtures/issue_8774_argument_shapes/main.ts
  • test-files/fixtures/issue_8774_argument_shapes/package.json
  • test-files/test_issue_8774_argument_shape_clones.ts

📝 Walkthrough

Walkthrough

The change adds exact-shape argument clones and guarded dispatch, reworks captured-closure caching, and directly lowers eligible static-key method object literals. Compiler, runtime, HIR, fixture, and regression tests cover these behaviors.

Changes

Exact-shape argument clones

Layer / File(s) Summary
Argument-shape planning and compiler facts
crates/perry-codegen/src/collectors/*, crates/perry-codegen/src/expr/mod.rs, crates/perry-codegen/src/codegen/{mod.rs,opts.rs}
The compiler identifies safe parameter shapes, records dispatch routes, and carries parameter-local shape proofs through FnCtx.
Ordinary method artifact compilation
crates/perry-codegen/src/codegen/{ordinary_method_artifacts.rs,artifacts.rs,method.rs,indexed_method_artifacts.rs}, crates/perry-codegen/src/codegen/{closure.rs,entry.rs,function.rs}
Method compilation emits the base method and applicable guarded, receiver, array-cache, and exact-shape argument clones.
Guarded argument dispatch
crates/perry-codegen/src/lower_call/*, crates/perry-codegen/src/collectors/{ptr_shape.rs,proven_this.rs,proven_this_routing_tests.rs}
Call lowering checks argument class and shape facts, calls $pshape_args clones on success, and preserves generic fallback routes.
Argument-shape regression coverage
crates/perry-codegen/src/codegen/argument_shape_clone_tests.rs, crates/perry/tests/issue_8774_argument_shape_clones.rs, test-files/fixtures/issue_8774_argument_shapes/*, crates/perry/tests/test_issue_8774_argument_shape_clones.ts, changelog.d/8787-argument-shape-clones.md
Tests verify direct field access, clone selection, fallback behavior, dynamic shapes, imported classes, and moving-GC execution.

Captured-closure cache hints

Layer / File(s) Summary
Fingerprint cache and allocation path
crates/perry-runtime/src/closure/alloc.rs, changelog.d/8792-captured-closure-cache-hints.md
The cache now uses fingerprint hints, exact capture matching, stable entries, and bounded LRU eviction.
GC scanning and cache validation
crates/perry-runtime/src/closure/alloc.rs
GC rewrites captured pointers, recomputes fingerprints, and clears stale hints. Collision and eviction tests cover the cache behavior.

Static method object literals

Layer / File(s) Summary
Direct object-literal lowering
crates/perry-hir/src/lower/expr_object.rs, changelog.d/8793-static-method-object-literals.md
Eligible static-key method-only literals now lower to direct object expressions. Home-object-dependent and source-ordered forms retain the IIFE builder path.
Object-literal semantic coverage
crates/perry-hir/src/lower/tests.rs, crates/perry/tests/static_method_object_literal.rs
Tests cover captured methods, dynamicThis, accessors, spreads, computed keys, super, and forced GC execution.

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

Sequence Diagram(s)

sequenceDiagram
  participant CallLowering
  participant ShapeFacts
  participant ExactShapeGuard
  participant PshapeArgsClone
  participant GenericMethod
  CallLowering->>ShapeFacts: resolve receiver and argument routes
  ShapeFacts->>ExactShapeGuard: provide expected class and ShapeId
  ExactShapeGuard->>PshapeArgsClone: all argument guards pass
  ExactShapeGuard->>GenericMethod: a guard fails
  PshapeArgsClone-->>CallLowering: specialized result
  GenericMethod-->>CallLowering: fallback result
Loading
✨ 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 merge/b51

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