Repository navigation
JNI: Foundation values as standard Java types - #27
Open
piercifani wants to merge 2 commits into
Open
piercifani wants to merge 2 commits into
piercifani wants to merge 2 commits into
Conversation
Ports swiftlang#952: with `"foundationTypesAsJavaTypes": true`, `URL`, `Date`, `Data`, `Locale` and `TimeZone` cross as `java.net.URI`, `java.util.Date`, `byte[]`, `java.util.Locale` and `java.util.TimeZone` instead of wrapper classes generated into every module, through `JavaValue` conformances in SwiftJavaRuntimeSupport. `CGFloat` is a Java `double`. On top of swiftlang#952, for this stack: - Escaping closures pass these values to Java as they are, since their `@JavaInterface` is printed by jextract and the values are `JavaValue`s, and closures returned to Java box them with a new `JavaObjectValueBridge`. Protocols implemented in Java still skip them: wrap-java maps the Java types on its own terms. - With `optionalsAsNullable`, an optional parameter whose Java type has a package, such as `Optional<java.net.URI>`, now becomes nullable too: its dots made the one-name spelling parse as a package and a class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Stack 23/23 · base:
jni/22-export-control· previous: #26Problem
Data,DateandURLreach Java as Swift-backed wrapper classes generated into every module's Java package. In a multi-module app, aURLreturned by one module's API is a different Java type from theURLanother module's API accepts, so the value can't be passed along. OptionalURL?parameters weren't supported either. Skip bridges these asjava.net.URI,java.util.DateandByteArray.Changes
This ports upstream swiftlang#952. With
"foundationTypesAsJavaTypes": true:URLjava.net.URIDatejava.util.DateDatabyte[]/ByteArrayLocalejava.util.LocaleTimeZonejava.util.TimeZoneCGFloatis adoubleeither way. The values conform toJavaValueinSwiftJavaRuntimeSupport, and no wrapper classes are generated.On top of swiftlang#952, for features that only exist in this stack:
@JavaInterfaceitself, and the values areJavaValues.JavaObjectValueBridge.java.net.URIand the other types on its own terms.optionalsAsNullable(JNI: optionalsAsNullable passes optionals as nullable Java types #19) now also applies to an optional parameter whose Java type has a package, such asOptional<java.net.URI>. Before, the dots made that one-name spelling parse as a package plus a class namedURI>, so the parameter stayed anOptional, and Kotlin saw a read-only property for aURL?var.Kotlin in this PR
FoundationValuesTest.ktwithBookmarks.swift:Why Skip needs it
Skip bridges these types by value, to the same Java types. On a production Skip Fuse app (9 Skip modules) run through this stack in annotated mode, with the app's bridging annotations as
@JavaExportmarkers:URLparameter;@JavaExport(false)and exportMode #26 for members that use unexported types.Testing
./gradlew :Samples:SwiftJavaExtractJNIKotlinSampleApp:testpasses (54 tests, including 3 inFoundationValuesTest).JNIFoundationJavaTypesTests(3 tests) andFoundationJavaValueTests(5 tests on a real JVM).swift testpasses.🤖 Generated with Claude Code