Skip to content

codegen(calls): pad under-applied same-module direct calls with undefined (#8770) - #8852

Closed
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix-8770-underapplied-call-padding-main
Closed

codegen(calls): pad under-applied same-module direct calls with undefined (#8770)#8852
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix-8770-underapplied-call-padding-main

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

The bug

A same-module direct call with fewer arguments than the callee's declared parameter count lowered only the provided args, leaving the remaining FP argument registers holding caller-saved garbage — which the callee then read as JS values.

The cross-module twin (extern_func.rs, the issue #608 arm) has always padded missing trailing args with TAG_UNDEFINED. The same-module plain arm in func_ref.rs sat "one else away" (#7154's own comment about this exact file-pair pattern) unpadded. The three rest-parameter arms pad via lower_rest_call_args_rooted; only the plain arm was missed.

Impact (this is the #8770 Claude Code crash family)

The Claude Code bundle is one giant module, so every direct call resolves through the same-module arm — and minified JS under-applies constantly. aP([q]) for function aP(q, K = !1, _) handed K/_ whatever d1/d2 held after js_array_from_values: impossible-NaN bit patterns (0xffffffffffffffff) that flowed into truthiness tests (if (_)) and method receivers (_.get(A)) and faulted in shape_is_url_search_params / js_is_truthy (~60% of cc -p runs SEGV), or silently corrupted the async iteration (Detected unsettled top-level await, most of the rest).

The GC-knob correlations the long #8770 investigation chased (scavenge pacing, PERRY_CONSERVATIVE_STACK_SCAN=Full "fixing" it) were register-content side effects of the missing padding — different collector paths leave different residue in the never-written argument registers — not collector bugs.

The fix

In try_lower_func_ref_call's plain (non-rest) arm, after lowering the provided args, pad lowered with the TAG_UNDEFINED literal up to declared_count — mirroring the cross-module twin. declared_count is the full f.params.len() from the function registry (includes default and trailing params, which is what the callee's compiled signature and its default-parameter undefined tests expect).

Validation

  • Claude Code cli_2.1.112.js (68 MB bundle): cc -p 30/30 clean — 0 SEGV, 0 hangs, 0 unsettled awaits, node-identical output on every run (baseline: ~60% SEGV, ~73% corrupted async).
  • --version / --help unchanged-clean.
  • New regression test (underapply_pad_tests.rs): an under-applied direct call to a 3-param callee must emit all three double args, the omitted two as the TAG_UNDEFINED literal.
  • Full perry-codegen suite: 1223 passed, 0 failed.

https://claude.ai/code/session_01Ay8VyLkKbm8Hkc1xmvTEsP

Summary by CodeRabbit

  • Bug Fixes

    • Fixed same-module function calls with omitted trailing arguments.
    • Missing arguments are now correctly treated as undefined, matching calls across modules.
  • Tests

    • Added regression coverage to verify that under-applied calls pass all declared parameters with appropriate undefined values.

…ined (PerryTS#8770)

A same-module direct call with fewer arguments than the callee's declared
parameter count lowered only the provided args, leaving the remaining FP
argument registers holding caller-saved garbage — which the callee then
read as JS values. The cross-module twin (extern_func.rs, the issue PerryTS#608
arm) has always padded missing trailing args with TAG_UNDEFINED; the
same-module plain arm sat "one else away" (PerryTS#7154's own words) unpadded.

On the Claude Code bundle — one giant module, so EVERY direct call
resolves through the same-module arm — `aP([q])` for
`function aP(q, K = !1, _)` handed K/_ whatever d1/d2 held after
js_array_from_values: impossible-NaN bit patterns (0xffffffffffffffff)
that flowed into truthiness tests and method receivers (`_.get(A)`) and
faulted in shape_is_url_search_params / js_is_truthy (~60% of `cc -p`
runs SEGV), or silently corrupted the async iteration ("Detected
unsettled top-level await", most of the rest).

With the padding, `cc -p` runs 30/30 clean: 0 SEGV, 0 hangs, 0 unsettled
awaits, node-identical output on every run. The GC-knob correlations the
long PerryTS#8770 investigation chased (scavenge pacing, conservative-scan
"fixes") were register-content side effects of the missing padding, not
collector bugs.

Regression test: an under-applied direct call to a 3-param callee must
emit all three double args, the omitted two as the TAG_UNDEFINED literal.

Claude-Session: https://claude.ai/code/session_01Ay8VyLkKbm8Hkc1xmvTEsP
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 99e08acd-267b-4365-8445-73e000757504

📥 Commits

Reviewing files that changed from the base of the PR and between d9d39a6 and 2405719.

📒 Files selected for processing (3)
  • crates/perry-codegen/src/lower_call/func_ref.rs
  • crates/perry-codegen/src/lower_call/mod.rs
  • crates/perry-codegen/src/lower_call/underapply_pad_tests.rs

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


📝 Walkthrough

Walkthrough

Same-module direct calls now pad omitted trailing arguments with NaN-boxed undefined values. New IR regression coverage verifies padding for a three-parameter callee called with one argument.

Changes

Same-module under-application

Layer / File(s) Summary
Pad omitted call arguments
crates/perry-codegen/src/lower_call/func_ref.rs
Non-rest same-module calls append TAG_UNDEFINED for missing declared parameters.
Validate generated call arguments
crates/perry-codegen/src/lower_call/mod.rs, crates/perry-codegen/src/lower_call/underapply_pad_tests.rs
The test module builds an under-applied direct call and verifies that omitted arguments are encoded as undefined.

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

Merge Risk: ⚪ Minimal · up to 24057

This localized code-generation change pads omitted direct-call arguments with undefined and includes regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, impact, fix, and validation, but it does not follow the repository template. It omits the required Summary, Changes, Related issue, Test plan, Screenshots / output, a… Reformat the description using the repository template. Add the required headings, include the related issue or state "n/a", list concrete changes, provide test commands and completed test-plan items, and complete the checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: padding under-applied same-module direct calls with undefined values.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the bug, impact, fix, and validation, but it does not follow the repository template. It omits the required Summary, Changes, Related issue, Test plan, Screenshots / output, and Checklist sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 added a commit that referenced this pull request Aug 26, 2026
* perf: cache owning Uint32Array admissions

* perf: fast-path Array subclass length misses

* perf(codegen): route proven Array length writes

* perf(runtime): bulk-truncate ordinary dense arrays

* chore: add array truncation changelog

* runtime: add Node-API host core

* docs: add Node-API host changelog fragment

* runtime: harden Node-API host contracts

* runtime: bound Node-API UTF-16 encoding

* codegen(calls): pad under-applied same-module direct calls with undefined (#8770)

A same-module direct call with fewer arguments than the callee's declared
parameter count lowered only the provided args, leaving the remaining FP
argument registers holding caller-saved garbage — which the callee then
read as JS values. The cross-module twin (extern_func.rs, the issue #608
arm) has always padded missing trailing args with TAG_UNDEFINED; the
same-module plain arm sat "one else away" (#7154's own words) unpadded.

On the Claude Code bundle — one giant module, so EVERY direct call
resolves through the same-module arm — `aP([q])` for
`function aP(q, K = !1, _)` handed K/_ whatever d1/d2 held after
js_array_from_values: impossible-NaN bit patterns (0xffffffffffffffff)
that flowed into truthiness tests and method receivers (`_.get(A)`) and
faulted in shape_is_url_search_params / js_is_truthy (~60% of `cc -p`
runs SEGV), or silently corrupted the async iteration ("Detected
unsettled top-level await", most of the rest).

With the padding, `cc -p` runs 30/30 clean: 0 SEGV, 0 hangs, 0 unsettled
awaits, node-identical output on every run. The GC-knob correlations the
long #8770 investigation chased (scavenge pacing, conservative-scan
"fixes") were register-content side effects of the missing padding, not
collector bugs.

Regression test: an under-applied direct call to a 3-param callee must
emit all three double args, the omitted two as the TAG_UNDEFINED literal.

Claude-Session: https://claude.ai/code/session_01Ay8VyLkKbm8Hkc1xmvTEsP

* fix(async_hooks): complete node suite parity

* chore: batch-landing fixes (node-api scoped ptrs, header/ic_miss splits, fmt)

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via the #8857 batch.

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