Skip to content

fix(hir): preserve computed field key scope - #10909

Closed
proggeramlug wants to merge 1 commit into
mainfrom
fix/10889-undici-wasm-link
Closed

proggeramlug wants to merge 1 commit into
mainfrom
fix/10889-undici-wasm-link

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10889

Root cause

Class capture synthesis treated computed instance-field key expressions as constructor-time work. In nested and CommonJS-wrapped classes it remapped those expressions to synthetic constructor capture parameters, but ClassDefinitionEvaluation executes the key snapshots outside the constructor, where those parameters are unbound.

In undici's PoolBase, [kClients] = [] was consequently installed under the wrong key. Pool later read the real kClients symbol and failed at this[kClients].length (pool.js:101).

Fix

  • keep computed field-key expressions in their class-definition scope
  • exclude definition-time keys from constructor capture synthesis
  • retain constructor capture rewriting for field initializer values, which do run during construction
  • add a regression where an unrelated method capture still synthesizes a constructor without capturing/remapping the computed key

Validation

  • cargo test -p perry-hir lower::tests --lib (102 passed, 1 ignored)
  • python3 scripts/check_test_registration.py
  • git diff --check
  • symbolized real undici@8.9.0 public-entry fixture: the reported Pool[kClients] failure at pool.js:101 is gone

The fixture advances to a separate Node stream contract failure: Socket.read() returns undefined instead of null, causing a later chunk.length failure at client-h1.js:323. That next blocker is tracked independently in #10908.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed computed instance-field keys in nested and CommonJS-wrapped classes so they are resolved correctly when the class is defined.
    • Symbol-keyed fields now retain their resolved keys when creating class instances, preventing initialization failures in affected request-handling scenarios.
  • Tests

    • Added coverage to ensure computed field keys are not incorrectly treated as constructor captures.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b6db2441-4ada-48ec-920f-aa1cf365bdd9

📥 Commits

Reviewing files that changed from the base of the PR and between 841b605 and 7a0d63a.

📒 Files selected for processing (4)
  • changelog.d/10889-computed-field-key-captures.md
  • crates/perry-hir/src/ir/decl.rs
  • crates/perry-hir/src/lower/tests.rs
  • crates/perry-hir/src/lower_decl/class_captures.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change prevents computed instance-field keys from being collected or rewritten as constructor captures. The HIR documentation describes definition-time key storage. A regression test verifies capture behavior for nested classes with symbol-keyed fields.

Changes

Computed Field Capture Handling

Layer / File(s) Summary
Computed key evaluation contract
crates/perry-hir/src/ir/decl.rs, crates/perry-hir/src/lower_decl/class_captures.rs
The HIR documentation states that computed keys resolve during class definition evaluation. Capture analysis no longer collects references from computed keys.
Constructor rewrite and regression coverage
crates/perry-hir/src/lower_decl/class_captures.rs, crates/perry-hir/src/lower/tests.rs, changelog.d/10889-computed-field-key-captures.md
Constructor rewriting remaps only field initializers. The regression test verifies that a computed key does not create a constructor capture while an unrelated method capture remains. The changelog records the fix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving computed field key scope during HIR lowering.
Description check ✅ Passed The description provides the root cause, fix, related issue, validation commands, regression-test coverage, and the remaining independent fixture failure. It does not use every template heading or che…
Linked Issues check ✅ Passed The PR addresses #10889's reported computed-instance-field failure. synthesize_class_captures no longer collects or constructor-remaps key_expr, while field initializer expressions still receive c…
Out of Scope Changes check ✅ Passed The changes stay within #10889. The implementation changes computed-field capture synthesis, the test covers the regression, the IR comment documents the corrected scope, and the changelog records the…
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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

Copy link
Copy Markdown
Contributor Author

Landed via merge train 253 (#10918) as v0.5.1633 — merge commit 0fa3915293.

Expedited at the owner's request. Carried with nine other PRs; the stacked ones (#10899/#10900 on #10886, #10901 on #10885) had only their unique commits taken.

Evidence on the assembled tree: perry-runtime full suite 4233 passed / 0 failed / 0 SIGABRT, perry-hir 471 / 0, cargo check --workspace --all-targets under -D warnings clean, cargo fmt --check clean, and all eight ratchets rc=0. The gap sweep and compiler-output suites were not run.

Closing here rather than merging — a train lands the commits directly.

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.

undici: public request crashes reading length from undefined after llhttp loads

1 participant