Skip to content

jextract/jni: Add nativeJavaType to TranslatedResult for explicit type handling#722

Merged
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:use_nativeResult
Apr 24, 2026
Merged

jextract/jni: Add nativeJavaType to TranslatedResult for explicit type handling#722
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:use_nativeResult

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

This PR is a refactoring effort to address the architectural concerns proposed in #720.

Previously, the return types of native functions were handled implicitly within JavaTranslation.
This PR changes that to an explicit exchange using the newly added nativeJavaType in TranslatedResult.

This change resolves existing // FIXME: comments in the tuple generation logic.

To ensure that JavaTranslation and NativeJavaTranslation generate identical signatures for native functions, I have added an assertion to validate the correctness of nativeJavaType.

@sidepelican sidepelican requested a review from ktoso as a code owner April 24, 2026 07:03
} else {
return TranslatedResult(
javaType: javaType,
nativeJavaType: .long,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't a new concern; it just makes an existing assumption explicit.
For example, using .wrapMemoryAddressUnsafe already implies we know the native return type is long.

}

let translatedResult = try translate(swiftResult: SwiftResult(convention: .direct, type: swiftType.resultType), methodName: name)
let translatedResult = try translateResult(swiftType: swiftType.resultType, methodName: name)
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.

Ok change thx

Copy link
Copy Markdown
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.

Looks good I think, thanks

@ktoso ktoso merged commit de257ec into swiftlang:main Apr 24, 2026
64 checks passed
@sidepelican sidepelican deleted the use_nativeResult branch April 24, 2026 08:49
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