Skip to content

fix(hir): scope class-expression capture refreshes per evaluation (#6654) - #7087

Merged
proggeramlug merged 2 commits into
mainfrom
fix/6654-class-expression-refresh
Jul 30, 2026
Merged

fix(hir): scope class-expression capture refreshes per evaluation (#6654)#7087
proggeramlug merged 2 commits into
mainfrom
fix/6654-class-expression-refresh

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • attach class-expression capture refreshes to each evaluated heap class object instead of a shared template-name snapshot
  • retain and place refresh owners across parameter defaults, expression-bodied arrows, nested function forms, and module-level blocks
  • make static capture reads prefer the actual fresh class receiver and add Node parity coverage for repeated evaluations and assignment timing

Closes #6654

Tests

  • cargo check -p perry-hir -p perry-codegen -p perry-runtime
  • cargo test -p perry-hir --lib
  • cargo test -p perry-codegen --lib
  • PERRY=$PWD/target/debug/perry tests/test_class_expr_capture_refresh_6654.sh
  • tests/test_class_expr_capture_refresh_6604.sh
  • shellcheck tests/test_class_expr_capture_refresh_6654.sh

Full cargo test -p perry-runtime --lib is currently interrupted by the unrelated existing GC test gc::tests::shadow_stack_ops::out_of_range_frame_pop_is_ignored aborting the process.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed class expressions so captured values remain correctly associated with each evaluated class object.
    • Improved capture behavior across factories, parameter defaults, arrow functions, static getters, and top-level blocks.
  • Tests

    • Added regression coverage comparing compiled output with Node.js behavior across multiple class-expression scenarios.

@coderabbitai

coderabbitai Bot commented Jul 30, 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: 4921ce2f-19aa-4757-a31e-6c1639b9bd7e

📥 Commits

Reviewing files that changed from the base of the PR and between 404c1c9 and 1e6dffb.

📒 Files selected for processing (22)
  • changelog.d/7087-class-expression-capture-refresh.md
  • crates/perry-codegen/src/expr/dispatch.rs
  • crates/perry-codegen/src/expr/static_field_meta.rs
  • crates/perry-codegen/src/runtime_decls/strings.rs
  • crates/perry-hir/src/ir/expr.rs
  • crates/perry-hir/src/lower/expr_function.rs
  • crates/perry-hir/src/lower/expr_object.rs
  • crates/perry-hir/src/lower/lower_expr/arm_class.rs
  • crates/perry-hir/src/lower/lower_module_fn.rs
  • crates/perry-hir/src/lower/lowering_context.rs
  • crates/perry-hir/src/lower_decl/block.rs
  • crates/perry-hir/src/lower_decl/body_stmt/nested_fn_decl.rs
  • crates/perry-hir/src/lower_decl/class_members.rs
  • crates/perry-hir/src/lower_decl/fn_decl.rs
  • crates/perry-hir/src/lower_decl/private_members.rs
  • crates/perry-hir/src/lower_patterns.rs
  • crates/perry-hir/src/stable_hash/expr.rs
  • crates/perry-hir/src/walker/expr_mut.rs
  • crates/perry-hir/src/walker/expr_ref.rs
  • crates/perry-runtime/src/object/class_constructors.rs
  • test-parity/node-suite/object/class-expr-capture-refresh-edge.js
  • tests/test_class_expr_capture_refresh_6654.sh

📝 Walkthrough

Walkthrough

Class-expression capture refreshes are now scoped to each evaluated class object. HIR tracks per-evaluation owners, codegen lowers refresh expressions, runtime helpers update and read object capture arrays, and parity tests cover parameter defaults, factories, arrows, accessors, and blocks.

Changes

Class capture refresh

Layer / File(s) Summary
Capture ownership and HIR contract
crates/perry-hir/src/ir/expr.rs, crates/perry-hir/src/lower/lowering_context.rs, crates/perry-hir/src/lower/lower_expr/arm_class.rs, crates/perry-hir/src/stable_hash/*, crates/perry-hir/src/walker/*
Adds RefreshClassExprCaptures, changes tracking to evaluation-owner locals, and updates expression traversal and hashing.
HIR refresh insertion
crates/perry-hir/src/lower/expr_function.rs, crates/perry-hir/src/lower/expr_object.rs, crates/perry-hir/src/lower_decl/*, crates/perry-hir/src/lower/lower_module_fn.rs, crates/perry-hir/src/lower_patterns.rs
Centralizes refresh generation and applies it across function, method, accessor, nested-function, module, block, and parameter lowering paths.
Codegen and runtime execution
crates/perry-codegen/src/expr/*, crates/perry-codegen/src/runtime_decls/strings.rs, crates/perry-runtime/src/object/class_constructors.rs
Lowers refresh expressions, declares the new runtime functions, and refreshes or reads capture arrays on evaluated class objects.
Parity regression coverage
test-parity/node-suite/object/class-expr-capture-refresh-edge.js, tests/test_class_expr_capture_refresh_6654.sh, changelog.d/7087-class-expression-capture-refresh.md
Adds edge-case parity scenarios, byte-for-byte Node comparison, and changelog documentation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • PerryTS/perry#6633: Changes the same HIR class-expression capture-refresh plumbing and related lowering paths.
  • PerryTS/perry#6650: Earlier class-expression capture-refresh fixes involving capture scoping and truncation.

Suggested reviewers: thehypnoo, andrewtdiz

✨ 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 fix/6654-class-expression-refresh

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.

@proggeramlug
proggeramlug merged commit 56a7a56 into main Jul 30, 2026
6 of 7 checks passed
@proggeramlug
proggeramlug deleted the fix/6654-class-expression-refresh branch July 30, 2026 18:51
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.

hir: class-expression capture-refresh edge cases — param defaults, multi-eval name-keying, top-level-block/arrow refresh owners (#6604 follow-up)

1 participant