Kotlin/Native: class/struct bridging and global variables#4
Open
RandVid wants to merge 10 commits into
Open
Conversation
added 6 commits
June 18, 2026 13:36
…d type safety and clarity - Replace `String`-based type mapping with `KotlinType` enum for consistency across primitive and reference types. - Update `swiftTypeToKotlin` function to return `KotlinType?` and adjust type mapping logic accordingly. - Introduce `KotlinType.swift` to define the `KotlinType` enum, associated cases, and descriptions. - Refactor call argument handling to leverage `KotlinType` cases (e.g., `.string`, `.unit`). - Update code to switch on `KotlinType` enum instead of raw strings for type checks. - Ensure proper handling of `String` and other specific types with the new enum.
- Extend `swiftTypeToKotlin` and `KotlinType` to map `[UInt8]` to `UByteArray`. - Add struct `Pinning` to encapsulate pinning information for parameters requiring `usePinned`.
- Extend `swiftTypeToKotlin` and `KotlinType` to handle primitive and `String?` optional types.
…ion of primitives, UByteArrays and optionals
Owner
Author
|
😪 |
3e6dda4 to
6ab0866
Compare
added 3 commits
July 2, 2026 17:37
…well as global variables - Extend `KotlinNativeSwift2KotlinGenerator` to generate Kotlin/Native wrapper classes for Swift nominal types. - Ensure proper memory management via `SwiftHandle` with cleanup using GC `createCleaner` or explicit `close()`. - Add global variable export with getter and setter wrappers
…d structs in Kotlin/Native
- Remove support for structs in Kotlin/Native wrapper generation. - Migrate memory management from `SwiftHandle` to `NSObject` for improved interoperability. - Update `Counter` test cases - Modify `nativeThunkName` logic to sanitize Cinterop symbols for Kotlin/Native compatibility. - Adjust Gradle build output structure to resolve IntelliJ indexing issues.
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.
What was done
Custom class & struct support — each imported Swift nominal type becomes a
Kotlin/Native wrapper class holding an
COpaquePointerto a Swift-allocatedbox. Supported member surfaces:
constructors, instance methods, static methods, and stored-property get/set.
Custom types work as parameters and return values on both top-level functions
and members.
SwiftKitKN — new Kotlin/Native library (
org.swift.swiftkit.kn)that exports
SwiftHandle: the opaque-pointer box that backs every wrapperinstance, guards the destroy thunk with a CAS
AtomicInt, and fires exactly oncevia deterministic
close()or GCcreateCleaner.Type support — constructors, instance/static
methods, and property accessors now handle all primitives,
String,[UInt8](params viausePinned, returns viamemScoped+out-count), optionals and custom imported class/struct types (passed as opaque box
pointers)
Top-level global variables — Swift
public vardeclarations at module scopeare emitted as Kotlin
val(getter-only) orvar(getter+setter) top-levelproperties.
Lifetime test suite — covers exact-once destroy on
close(), CASidempotency on double-close, no-leak across 100 cycles, shared-identity and
multi-owner lifetime, struct releasing a reference member, GC cleaner path, and
a Swift weak-reference probe that observes ARC deallocation independently of the
deinit counter.