BridgeJS: Move optional JSObject to stack ABI, enabling Optional<@JSClass>#738
Open
BridgeJS: Move optional JSObject to stack ABI, enabling Optional<@JSClass>#738
Conversation
19f9d4f to
c562383
Compare
Member
Author
|
@kateinoigakukun let me know if this aligns with your comment of revisiting side-channel ABI, I remembered that we've discussed moving this to stack ABI, but might be wrong 😅 🙏🏻 |
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
Fixes #666. Moves
Optional<JSObject>(and by extensionOptional<@JSClass>) from the side-channel ABI to the stack ABI, enabling optional custom types on both import and export sides.Previously,
@JSFunction func foo() -> Foo?whereFoois a@JSClassstruct would fail because the side-channel path forJSObjectoptionals lacked abridgeJSLiftReturnFromSideChannelimplementation. Rather than adding another per-type side-channel intrinsic, this switchesjsObjectoptionals to the stack ABI — the same convention already used by structs, arrays, and dictionaries.What changed:
1.
JSGlueGen.swift—optionalConventionfor.jsObject: changed from.sideChannelReturn(.retainedObject)to.stackABI. RemovedjsObjectfromnilSentinel(stack ABI uses the isSome flag instead).2.
BridgeJSSkeleton.swift—usesSideChannelForOptionalReturn(): moved.jsObjectfrom thetruebranch tofalse.3.
ImportTS.swift—liftingReturnInfofor.nullable: when the wrapped type no longer uses side-channel, returnsvalueToLift: nilso the extern returns void (values go through typed stacks).4.
BridgeJSIntrinsics.swift—Optional<JSObject>.bridgeJSLowerReturn(): changed from calling_swift_js_return_optional_object(global side-channel) toWrapped.bridgeJSStackPushAsOptional(stack ABI). JSObject already conforms to_BridgedSwiftStackType, and_JSBridgedClassinherits from it, soOptional<Foo>gets stack-based lifting/lowering for free through the protocol chain.Tests: Added
childOrNullgetter/setter/roundTrip forWithOptionalJSClass?to theOptionalstest fixture, covering the import-side@JSClassoptional pattern from the original issue.