Skip to content

jextract/jni: SwiftDictionaryMap - a native backed Map implementation#614

Open
ktoso wants to merge 1 commit intoswiftlang:mainfrom
ktoso:wip-dictionary-experiment
Open

jextract/jni: SwiftDictionaryMap - a native backed Map implementation#614
ktoso wants to merge 1 commit intoswiftlang:mainfrom
ktoso:wip-dictionary-experiment

Conversation

@ktoso
Copy link
Collaborator

@ktoso ktoso commented Mar 12, 2026

This allows us to return and accept Swift dictionaries / Java Maps in jextracted functions in JNI mode.

We implement this by a wrapper type in Java that implements Map and delegates implementation of methods via downcalls to the underlying Swift dictionary. Actual dictionary remains in Swift native memory, though toJavaMap allows copying it onto the java heap.

We also needed to adjust how we get JNI values since we need to environment.interface.NewLocalRef in order to keep it alive when returning a java object from the native funcs. Maybe there's a better way to think about it -- open to exploring this further.

Next up we can do Set<T> as well

resolves #609

@ktoso ktoso changed the title SwiftDictionaryMap - a native backed Map implementation jextract/jni: SwiftDictionaryMap - a native backed Map implementation Mar 12, 2026
@ktoso ktoso force-pushed the wip-dictionary-experiment branch 2 times, most recently from 4472b35 to 95e0f8b Compare March 14, 2026 01:58
@ktoso ktoso force-pushed the wip-dictionary-experiment branch from 95e0f8b to e7b4cde Compare March 14, 2026 02:24
@ktoso ktoso marked this pull request as ready for review March 14, 2026 02: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: Support native Swift Dictionary use from Java

1 participant