Repository navigation
JNI: arrays of optionals, dictionaries and sets - #16
Open
piercifani wants to merge 2 commits into
Open
piercifani wants to merge 2 commits into
piercifani wants to merge 2 commits into
Conversation
Arrays were only converted for primitive, String, jextracted-class and nested-array elements; `[Tag?]` and `[[String: Int64]]` were skipped. Such arrays now use the existing `ArrayBridge`, which converts element by element with the bridges dictionaries already use. The public Java method is typed (`Optional<Tag>[]`, `SwiftDictionaryMap<String, Long>[]`); the native method passes `Object[]` and the wrapper casts with a new `.cast` conversion step. Optional primitive elements are `Optional<Long>`, the class `OptionalBridge` creates. The skipped-declarations test used these two shapes as its unsupported examples; it now uses arrays of tuples and of closures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
piercifani
force-pushed
the
jni/12-optional-nested-arrays
branch
from
November 3, 2026 16:46
7f5131a to
b96b02a
Compare
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 12/21 · base:
jni/11-async-throwing-stream· previous: #15 · next: #17 (jni/13-java-enums)Problem
JNI arrays are converted eagerly, and only primitive,
String, jextracted-class and nested-array elements were handled. Any other element type made jextract skip the declaration, including:[Tag?], an array of optionals, which failed withunsupportedSwiftType(Tag?);[[String: Int64]], an array of dictionaries, which failed withunsupportedSwiftType([String: Int64]).Dictionaries and sets didn't have this problem, because they convert their keys and values through bridges.
[String: [Tag]]and[Tag]?already worked.Changes
Arrays whose elements are optionals, dictionaries or sets now go through the existing
ArrayBridge, which converts element by element with the same bridges dictionaries use.ArrayBridge<…>.toJavaObject(result, in: environment)for results andArrayBridge<…>.fromJavaObject(array, in: environment)for parameters.Optional<Tag>[],SwiftDictionaryMap<String, Long>[],SwiftSet<String>[]. The native method takes and returnsObject[], the array's static type on the Swift side. The wrapper casts the result with a new.castconversion step, which renders(T[]) $f().OptionalBridgealways creates ajava.util.Optional, so an optional primitive element isOptional<Long>, notOptionalLong.bridgedArrayElementJavaTypecomputes that type.Kotlin in this PR
CollectionsTest.ktwithCollections.swift:Why Skip needs it
A production Skip Fuse app (16 Skip modules) bridges 2 signatures with
[T?]and 19 with nested collections. This PR fixes those whose outer collection is an array; dictionaries and sets of collections, and[T]?(85 signatures), already work on this branch. With strict skipped-declaration checks, each unsupported one fails the build. Without the checks, Kotlin silently loses those members.Testing
./gradlew :Samples:SwiftJavaExtractJNIKotlinSampleApp:testpasses (33 tests).JNIBridgedArrayElementsTests(4 tests): the Java signature, cast and nativeObject[]signature; the SwiftArrayBridgecalls for results and parameters; dictionary elements; jextracted optional elements.ArraysTest:[Int64?]and[MySwiftClass?]round trips,[[String: Int64]]and[Set<String>]results.swift test --disable-experimental-prebuilts --disable-sandbox(658 tests) and./gradlew :Samples:SwiftJavaExtractJNISampleApp:test(292 tests) pass.JNISkippedDeclarationsTests(from JExtract: report every skipped declaration; add failOnSkippedDeclarations #3) used[Tag?]and[[String: Int64]]as its unsupported examples; it now uses arrays of tuples and of closures.swift format lint --stricton changed files;git diff --check.Not in this PR
Date,UUID).Item?instead ofOptional<Item>) is a separate gap.🤖 Generated with Claude Code