BridgeJS: Lower imported optional stack parameters fully on the stack - #19
Closed
krodak wants to merge 3 commits into
Closed
BridgeJS: Lower imported optional stack parameters fully on the stack#19krodak wants to merge 3 commits into
krodak wants to merge 3 commits into
Conversation
krodak
force-pushed
the
kr/optional-param-stack-flag
branch
2 times, most recently
from
August 13, 2026 14:17
3f508a1 to
1087efe
Compare
krodak
marked this pull request as ready for review
August 13, 2026 14:17
krodak
force-pushed
the
kr/optional-param-stack-flag
branch
2 times, most recently
from
August 13, 2026 14:24
dbb07a2 to
f85d854
Compare
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 13, 2026 14:44
f85d854 to
129a15d
Compare
Collaborator
Author
|
Moved upstream: swiftwasm#802 |
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.This also removes the mixed parameter representation that caused the argument-order bug fixed in swiftwasm#794. Optional stack-based values now use the same stack-only representation as other stack-based parameters.
Test plan
make unittest:ImportAPITests.testStackLoweredParameterOrder, optional round-trips with some and nilcheck:bridgejs-dts, formatter, no generated drift