Skip to content

fix(codegen): #1008 — recognize post-#973 globalThis.Promise shape#1009

Merged
proggeramlug merged 1 commit into
mainfrom
fix/1008-promise-then-globalThis-shape
May 18, 2026
Merged

fix(codegen): #1008 — recognize post-#973 globalThis.Promise shape#1009
proggeramlug merged 1 commit into
mainfrom
fix/1008-promise-then-globalThis-shape

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Closes #1008.

Summary

PR #973 changed bare built-in idents (Promise, Array, Date, ...)
to lower as PropertyGet { GlobalGet(0), <name> } so they route through
the globalThis singleton closure path. Two codegen call sites that
specialize .then() dispatch were still pattern-matching the legacy
Expr::GlobalGet(_) shape only:

  • type_analysis::is_promise_expr for Promise.resolve/reject/all/race/ allSettled/any(...) and Array.fromAsync(...).
  • lower_call.rs's fused Promise.resolve(x).then(cb) fast path that
    routes to js_promise_resolved_then.

When is_promise_expr returned false, .then(cb) fell through to the
generic native method dispatch which doesn't enqueue the callback —
microtask-02..07 and edge-promises went silent in compile-smoke's
Native no-fallback gate, and on Linux V8 surfaced the same shape as
TypeError: then is not a function. The Native gate has been red on
every PR since #973 (admin-bypassed for #997 / #1000 / #1003 / #1004).

Fix

Extract type_analysis::is_global_builtin_named(expr, name) that
matches both shapes:

Route both is_promise_expr and the lower_call.rs fused fast path
through it. Two-line widening of the predicate; behavior is otherwise
unchanged.

Test plan

cargo build --release -p perry-runtime -p perry-stdlib -p perry
PERRY_BIN=./target/release/perry scripts/run_native_no_fallback_tests.sh
  • Before fix: native-no-fallback-tests: 28 passed, 7 failed (microtask-02..07 + edge-promises FAIL).
  • After fix: native-no-fallback-tests: 35 passed, 0 failed.
  • node --experimental-strip-types test-files/test_microtask_inv_02_then_vs_await_fifo.ts and the perry binary now produce the same output.

Why merge fast

This unblocks every PR currently sitting behind a red compile-smoke. It
is also the third stale-on-main blocker today after #958 (cargo-test
crypto rejection) and #1003 (api-docs-drift).

PR #973 lowered bare built-in idents (`Promise`, `Array`, `Date`, ...)
as `PropertyGet { GlobalGet(0), name }` so they route through the
globalThis singleton closure path. Two codegen call sites that
specialize `.then()` dispatch were still pattern-matching the legacy
`Expr::GlobalGet(_)` shape only:

- `type_analysis::is_promise_expr` for `Promise.resolve/reject/all/race/
  allSettled/any(...)` and `Array.fromAsync(...)`.
- `lower_call.rs`'s fused `Promise.resolve(x).then(cb)` fast path that
  routes to `js_promise_resolved_then`.

When `is_promise_expr` returned false, `.then(cb)` fell through to the
generic native method dispatch which doesn't enqueue the callback —
microtask-02..07 and edge-promises went silent in compile-smoke's
Native no-fallback gate, and on Linux V8 surfaced the same shape as
`TypeError: then is not a function`. The Native gate had been red on
every PR since #973 (admin-bypassed on #997 / #1000 / #1003 / #1004).

Extract `type_analysis::is_global_builtin_named(expr, name)` that
matches both shapes (legacy `GlobalGet(_)` and the post-#973
`PropertyGet { GlobalGet(0), name }`) and route both call sites
through it.

Validation: `scripts/run_native_no_fallback_tests.sh` — 35 passed, 0
failed (was 28/7 pre-fix).
@proggeramlug proggeramlug merged commit 9924f3b into main May 18, 2026
5 of 9 checks passed
@proggeramlug proggeramlug deleted the fix/1008-promise-then-globalThis-shape branch May 18, 2026 09:00
proggeramlug added a commit that referenced this pull request May 18, 2026
Both PRs were admin-merged with lint red. Land the trivial fmt cleanup
so subsequent PRs don't inherit the lint failure on top of their own
diffs.
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.

compile-smoke: native promise .then() broken in microtask-02..07 + edge-promises (regressed by #1000 or #1004)

1 participant