Skip to content

Commit cc42e8d

Browse files
authored
Merge pull request #4 from kdroidFilter/feat/suspend-dataclass-collection-returns
feat: Add suspend DataClass and Collection return type support
2 parents b798ca6 + 2f91b3d commit cc42e8d

6 files changed

Lines changed: 1357 additions & 15 deletions

File tree

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ No JNI. No annotations. No boilerplate. Just write Kotlin/Native and use it from
121121

122122
## What's supported
123123

124-
### Types — test coverage (780+ end-to-end FFM tests)
124+
### Types — test coverage (830+ end-to-end FFM tests)
125125

126-
Every test compiles Kotlin/Native → `libcalculator.so` (200+ exported symbols) → loads via FFM `MethodHandle` → verifies on JVM. Zero mocks — all 780+ tests cross the real native boundary. Includes 25 load tests (500K+ FFM calls), concurrent stress tests (10 threads), 60 suspend function tests with cancellation (incl. ByteArray), and 50+ Flow tests (including `Flow<DataClass>`).
126+
Every test compiles Kotlin/Native → `libcalculator.so` (200+ exported symbols) → loads via FFM `MethodHandle` → verifies on JVM. Zero mocks — all 830+ tests cross the real native boundary. Includes 25 load tests (500K+ FFM calls), concurrent stress tests (10 threads), 110+ suspend function tests with cancellation (incl. ByteArray, DataClass, List, Set, Map), and 50+ Flow tests (including `Flow<DataClass>`).
127127

128128
| Feature | As param | As return | As property | CB param | CB return | Notes |
129129
|---------|----------|-----------|-------------|----------|-----------|-------|
@@ -167,7 +167,7 @@ Every test compiles Kotlin/Native → `libcalculator.so` (200+ exported symbols)
167167
| Enum classes || auto-generated JVM enum with ordinal mapping |
168168
| Data classes (nativeMain) || auto-generates JVM data class + field marshalling |
169169
| Data classes (commonMain) || reuses existing JVM type, no proxy generated |
170-
| Suspend functions || `suspendCancellableCoroutine` + bidirectional cancellation (60 tests, incl. ByteArray) |
170+
| Suspend functions || `suspendCancellableCoroutine` + bidirectional cancellation (110+ tests, incl. ByteArray, DataClass, List, Set, Map) |
171171
| Flow&lt;T&gt; return || `channelFlow` + onNext/onError/onComplete callbacks (50+ tests, incl. DataClass) |
172172
| Exception propagation || `try/catch` wrapping, `KotlinNativeException` on JVM |
173173
| Object lifecycle || `Cleaner` for GC + `close()` for explicit release |
@@ -191,7 +191,7 @@ val result = calc.fetchData("test") // suspends the coroutine
191191

192192
**Cancellation**: JVM coroutine cancel → `Job.cancel()` on native side. Native `CancellationException` → JVM `CancellationException`. Bidirectional, automatic.
193193

194-
**Supported return types**: `Int`, `Long`, `Double`, `Float`, `Boolean`, `Byte`, `Short`, `String`, `ByteArray`, `Unit`, `enum class`, `Object`, nullable variants.
194+
**Supported return types**: `Int`, `Long`, `Double`, `Float`, `Boolean`, `Byte`, `Short`, `String`, `ByteArray`, `Unit`, `enum class`, `Object`, `data class`, `List<T>`, `Set<T>`, `Map<K,V>`, nullable variants.
195195

196196
### Flow&lt;T&gt;
197197

@@ -396,13 +396,6 @@ Measured on Intel Core i5-14600 (20 cores), 45 GB RAM, Ubuntu 25.10, JDK 25 (Gra
396396
| Private/internal members | By design | Only public API is exported |
397397
| Expect/actual declarations | KMP's responsibility | Use platform-specific source sets |
398398

399-
### Suspend function limitations
400-
401-
| Unsupported | Reason | Alternative |
402-
|-------------|--------|-------------|
403-
| `suspend fun(): DataClass` | DC field extraction from StableRef not yet implemented | Return individual fields or use non-suspend |
404-
| `suspend fun(): List<T>` / `Set<T>` / `Map<K,V>` | Collection serialization via continuation callback | Return collections from non-suspend functions |
405-
406399
### Flow element limitations
407400

408401
| Unsupported | Reason | Alternative |
@@ -601,7 +594,7 @@ The repository includes two complete examples in [`examples/`](examples/):
601594

602595
| Example | Description |
603596
|---------|-------------|
604-
| [`calculator/`](examples/calculator/) | Stateful Calculator class with 780+ end-to-end tests: all types, callbacks, collections, suspend, Flow (incl. DataClass), nested classes, concurrency |
597+
| [`calculator/`](examples/calculator/) | Stateful Calculator class with 830+ end-to-end tests: all types, callbacks, collections, suspend (incl. DataClass, List, Set, Map), Flow (incl. DataClass), nested classes, concurrency |
605598
| [`systeminfo/`](examples/systeminfo/) | Linux system info (`/proc`, POSIX, `gethostname`) + native notifications via `libnotify` cinterop, with Compose Desktop UI |
606599
| [`benchmark/`](examples/benchmark/) | Performance benchmarks: native vs JVM (fibonacci, pi, sort, string, allocation, concurrent) |
607600

@@ -610,7 +603,7 @@ Run them:
610603
```bash
611604
./gradlew :examples:calculator:run
612605
./gradlew :examples:systeminfo:run
613-
./gradlew :examples:calculator:jvmTest # 780+ end-to-end FFM tests
606+
./gradlew :examples:calculator:jvmTest # 830+ end-to-end FFM tests
614607
./gradlew :examples:benchmark:jvmTest # Performance benchmarks (native vs JVM)
615608
```
616609

0 commit comments

Comments
 (0)