Infer coroutine effects automatically

This commit is contained in:
pavel 2026-08-27 21:53:34 +02:00
commit 5b30e49486
15 changed files with 339 additions and 103 deletions

View file

@ -33,7 +33,7 @@ the semantic Type-to-Go mapping turns a class such as `User` into `*User`.
- Gotlin classes are reference types by default; `*` is only needed for external Go pointer types
- named external Go struct construction, for example `http.Client(timeout = 3 * time.second)`
- top-level embedded resources such as `@embed("assets/*") val assets: embed.FS`
- structured coroutines with `suspend fun`, `runBlocking`, `coroutineScope`, `launch`, `async`, `await`, `delay`, `withTimeout`, and `isActive`
- inferred structured coroutine effects with `runBlocking`, `coroutineScope`, `launch`, `async`, `await`, `delay`, `withTimeout`, `isActive`, and `coroutineContext`
## Example
@ -282,8 +282,18 @@ sibling coroutine contexts. The removed `worker`, bare `go`, and channel
`select` forms are not valid Gotlin syntax; use coroutine scopes, `delay`, and
explicit channel `read()`/`send()` operations.
Coroutine effects are inferred through the call graph. Functions that directly
or transitively use coroutine operations receive a hidden scope parameter and
can only be called from an ambient coroutine scope. `runBlocking` establishes a
scope boundary, so neither a `suspend` modifier nor manually threaded context is
needed.
Use `coroutineContext()` only at Go interop boundaries that require a
`context.Context`; it returns the ambient scope context without exposing it in
the Gotlin function signature.
```kotlin
suspend fun load(): Int {
fun load(): Int {
delay(10)
return 42
}