Skip to content

Conversation

@madsodgaard
Copy link
Contributor

Adds support for optional return types and parameters in JNI mode of JExtract.

The overall idea for the conversion is that we use a "discriminator", which is a byte :0or1` indicating whether the parameter or return value is present.

For parameters we pass in the discriminator as an additional parameter.

Returning Integral types

Returning any type that can fit inside a bigger primitive integer type, we widen that type and store the discriminator at the end.
So for example, returning Optional<Int8>, the underlying JNI would return a short, which is byte || byte. The above means that this method is used for (U)Int8, (U)Int16, (U)Int32.

Other types

For any other types we do an indirect return to return the value of the discriminator.

@ktoso ktoso requested review from ktoso and rintaro July 31, 2025 13:09
@madsodgaard madsodgaard changed the title WIP: [JExtract/JNI] Support optionals in JNI mode [JExtract/JNI] Support optionals in JNI mode Aug 1, 2025
@madsodgaard madsodgaard marked this pull request as ready for review August 1, 2025 14:47
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Very nice! Looks great, I skimmed the outputs earlier, looks all good

@ktoso ktoso merged commit b2f42a1 into swiftlang:main Aug 1, 2025
57 of 58 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.

2 participants