BridgeJS: Unify optional stack encoding to presence-flag form#16
Closed
krodak wants to merge 1 commit into
Closed
Conversation
292c088 to
bc356b5
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
Unifies the stack encoding of
Optionalvalues to a single presence-flag form. Previously, associated-value enums were the one type with a specialized optional stack encoding: the presence signal was merged into the case-ID slot, with-1meaningnil. Every other type uses a0/1presence flag followed by the value. After this change, associated-value enums use the same flag form as everything else when crossing in stack positions (array elements, struct fields, dictionary values, nested enum payloads).1. Swift runtime. The
bridgeJSStackPop/PushAsOptionaloverride on_BridgedSwiftAssociatedValueEnumis removed; the protocol defaults now serve every type. The direct return slot keeps the mergedcaseId/-1convention (it is a separate ABI position, shared with other enum returns); the previous implementation delegated to the stack helper, so the merged form is now inlined there with a comment.2. JS glue. The associated-value enum special cases in
optionalElementRaiseFragment/optionalElementLowerFragmentare removed; associated-value enums flow through the same general path as all other wrapped types, which composes the existing per-type element fragments behind a presence flag.Cost
Optional associated-value enums in stack positions carry one extra
i32(the flag) per crossing. Direct parameter and return conventions are unchanged.Motivation
This removes the only optional stack encoding that cannot be decoded without knowing the wrapped type: a popped
0meantnilfor most types but "case 0, payload follows" for associated-value enums. A type-agnostic consumer of the stack encoding needs one uniform optional form; this prepares for generic function support (swiftwasm#398), where a runtime codec decodes optionals without static knowledge ofT. A follow-up PR adds that support.Test plan
npm run check:bridgejs-dtspass; only two.jssnapshots change, showing the flag-form encoding.testRoundTripOptionalAssociatedValueEnumandasyncRoundTripOptionalAssociatedValueEnum, which exercise the changed encoding end to end.