Skip to content

jextract/jni: Add support for returning protocols#814

Merged
ktoso merged 5 commits into
swiftlang:mainfrom
madsodgaard:jni-return-protocols
Jul 6, 2026
Merged

jextract/jni: Add support for returning protocols#814
ktoso merged 5 commits into
swiftlang:mainfrom
madsodgaard:jni-return-protocols

Conversation

@madsodgaard

Copy link
Copy Markdown
Contributor

Adds support for returning any P / some P from a function, variable etc...

This is done by generating a <P>Box instance in Java, that makes downcalls by opening the existential and calling a cdecl. This box implements both all protocol requirements and any inherited protocol requirements.

One special thing is for setters, where we need to do a "load-mutate-store", because it might be a value type.

Closes #380

@madsodgaard madsodgaard requested a review from ktoso as a code owner July 2, 2026 10:47
@madsodgaard madsodgaard changed the title jextract/jin: Add support for returning protocols jextract/jni: Add support for returning protocols Jul 2, 2026
Comment thread Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift Outdated

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up the comments a bit; logic looks good, I'll want to do some restructuring since we're a bit repetetive sometimes.

LGTM tho

@ktoso ktoso merged commit ba6de8c into swiftlang:main Jul 6, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jextract][jni] Add support for returning protocol types

2 participants