BridgeJS: Unify thunk argument preparation - #22
Draft
krodak wants to merge 1 commit into
Draft
Conversation
krodak
force-pushed
the
fix/struct-self-stack-order
branch
from
September 8, 2026 13:15
fecb9bf to
f8e6dec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Prepare Swift arguments before invoking user code instead of embedding their lifting expressions in calls. JavaScript pushes stack-backed values in parameter order, so Swift must lift them in reverse order, including a struct receiver. Those lifts must also finish before an async task is scheduled.
The previous code only hoisted synchronous arguments when more than one used the stack. A struct method with one such argument could therefore pop
selfbefore the argument. Separate closure handlers had the same ordering problem and left async argument lifts inside the deferred task.1. One parameter preparation step
Emit local bindings for all parameters in reverse order, then call the function using those values. Remove the parameter-count guard, receiver flag, and stack-type classification. Type conversion and async scheduling continue to use the existing BridgeJS intrinsics.
2. Reuse the thunk builders
Generate Swift closure invocation handlers through the same builder as exported functions and methods. Generate struct JavaScript wrappers through the normal JS thunk builder, which also fixes their missing Promise lifting and exception checks.
3. Disambiguate continuation callbacks
Generate named
JSTypedClosure.sending(...)factories for internal continuation callbacks instead of additional initializers. Ordinary(Int) -> Voidcallbacks can then coexist with generated(sending Int) -> Voidcallbacks without ambiguous initializer errors. The callback ABI is unchanged.Test Plan
Int-returning async array regression in both directions, and enabled the existing integer-array callback round-trip test../Utilities/format.swift./Utilities/bridge-js-generate.shnpm run check:bridgejs-dtsmake unittest SWIFT_SDK_ID=swift-6.3-RELEASE_wasm BUILD_SYSTEM=nativegit diff --check