jextract/jni: Overhaul enum associated value retrieval#727
Draft
sidepelican wants to merge 17 commits intoswiftlang:mainfrom
Draft
jextract/jni: Overhaul enum associated value retrieval#727sidepelican wants to merge 17 commits intoswiftlang:mainfrom
sidepelican wants to merge 17 commits intoswiftlang:mainfrom
Conversation
# Conflicts: # Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift
This reverts commit 7102952. # Conflicts: # Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift # Sources/JExtractSwiftLib/JavaTypes/JavaAccessModifier.swift
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.
This PR overhauls the implementation of enum associated value retrieval.
By leveraging the recent improvements in tuple handling, I can now support complex patterns (such as arrays and generic types).
The Problem
The current
getAsCaseimplementation relies on specialized, hard-coded logic.swift-java/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift
Lines 161 to 221 in 6e97fc0
It only works for very simple patterns.
Adding support for complex types (tuples, arrays, etc.) within the current structure is not sustainable and would lead to code duplication.
The Solution
Instead of a specialized path, I have unified the logic with our existing tuple infrastructure.
In Swift, associated values are extracted as an optional tuple (e.g.,
(Foo, String)?).In Java, the glue code wraps it into the appropriate
Caseclass.Example
Original:
Generated:
Benchmarks
I have tested via
./gradlew jmh -PjmhIncludes='.EnumBenchmark*'inSamples/SwiftJavaExtractJNISampleApp/.The performance improvement is likely a direct result of reducing the number of JNI calls.
Note
This PR is currently a draft as it depends on #725. I will mark it as ready for review once the dependency is merged.