Skip to content

Conversation

ktoso
Copy link
Collaborator

@ktoso ktoso commented Jul 29, 2025

Resolves #307

This introduces @Unsigned long and friends importing as well as an opt-in mode to import unsigned types as Guava's UnsignedInteger and friends which is only available for FFM right now.

@ktoso ktoso force-pushed the wip-unsigned branch 3 times, most recently from 4b92e65 to e998244 Compare July 30, 2025 13:46
@ktoso ktoso changed the title [WIP] Handling unsigned numbers better in jextract Handling unsigned numbers better in jextract Jul 30, 2025
@ktoso ktoso marked this pull request as ready for review July 30, 2025 13:46
/// Specifically negative values of a `@Unchecked long` must be interpreted carefully as
/// a value larger than the Long.MAX_VALUE can represent in Java. You can use `org.swift.swiftkit.core.primitives`
/// utility classes to work with such unsigned values in Java.
case annotate
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's our default mode, it's also similar to what OpenJDK jextract does (we add the annotation, jextract itself does nothing)

@Unsigned
public static int unsignedLong(@Unsigned long first, @Unsigned int second) {
return swiftjava_SwiftModule_unsignedLong_first_second.call(first, second);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Showcase of the default extract mode -- we don't do any conversions, but we annotate the types for easier discovery in IDEs

Image

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the primitives types are vendored Guava types.

TBD if we'd like to may be just roll our own entirely or just make jextract emit code which assumes you'll bring your own Guava perhaps...

@ktoso
Copy link
Collaborator Author

ktoso commented Jul 30, 2025

I'm still on the fence about the Unsigned... wrapper types... This was originally the direction I pursued, but I think the annotate mode ended up more interesting.
In the end, we could also offer kotlin.UShort and unsigned types, which would be a different way to "wrap" that would be welcome on Android perhaps.

I'm gonna sleep over this change and decide that to do about the guava types -- perhaps remove them for now, until we truly want them after all.

@ktoso ktoso merged commit ac30ee4 into swiftlang:main Jul 31, 2025
29 checks passed
@ktoso ktoso deleted the wip-unsigned branch July 31, 2025 08:25
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] Unable to map UInt8 to Java
1 participant