BridgeJS: Lower imported optional stack parameters fully on the stack - #19
Draft
krodak wants to merge 1 commit into
Draft
BridgeJS: Lower imported optional stack parameters fully on the stack#19krodak wants to merge 1 commit into
krodak wants to merge 1 commit into
Conversation
An imported optional whose payload is stack-only ([T]?, [String: V]?, @js struct?) used a hybrid convention: the isSome flag crossed as a wasm i32 parameter while the payload was conditionally pushed onto the shared stacks. Optional returns and optional array elements of the same types already travel entirely on the stacks: payload first, then a 0/1 flag on the i32 stack. This lowers those parameters the same way. The Swift thunk pushes the payload (if some) followed by the flag, the wasm signature carries no argument for the parameter, and the JS handler pops the flag before conditionally lifting the payload, through the same fragment already used for optional returns and elements. The hybrid shape was the last parameter category that both passed a wasm argument and pushed stack data, which is what enabled the argument transposition fixed in swiftwasm#794. Every stack-touching parameter is now flagless and reverse-ordered, matching returns and elements. All other optional parameter ABIs (scalars, strings, JSObject, closures, enums, heap objects) are unchanged.
krodak
force-pushed
the
kr/optional-param-stack-flag
branch
from
August 11, 2026 10:03
4d57e98 to
3f508a1
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.
Summary
Imported optional parameters with stack-only payloads (
[T]?,[String: V]?,@JS struct?) used a hybrid convention: theisSomeflag crossed as a wasmi32argument while the payload went on the shared stacks. Optional returns and optional array elements of the same types already put both on the stacks.This lowers those parameters the same way. The wasm signature carries no argument for them; JS pops the flag and conditionally lifts, through the same fragment as optional returns. Scalars, strings,
JSObject, closures, enums and heap objects keep their current optional ABIs, as do all exported signatures.The hybrid shape was the last parameter kind that both passed a wasm argument and pushed stack data, which is what enabled the argument transposition fixed in swiftwasm#794. After this, every stack-touching parameter is flagless and reverse-ordered.
Test plan
make unittest:ImportAPITests.testStackLoweredParameterOrder, optional round-trips with some and nilcheck:bridgejs-dts, formatter, no generated drift