Support inline suspend functions
A lot of additional work was required to support them: - Suspension points are being identified by two markers instead of one pointing to suspend function call - Approach with replacing return type of suspend function does not work anymore. So we decode suspension return type as an argument for begin marker - It became necessary to perform variables liveness analysis (see comment in org.jetbrains.kotlin.codegen.coroutines.CoroutineTransformerMethodVisitor.spillVariables)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// WITH_RUNTIME
|
||||
class Controller {
|
||||
fun withValue(v: String, x: Continuation<String>) {
|
||||
x.resume(v)
|
||||
}
|
||||
|
||||
suspend inline fun suspendInline(v: String, x: Continuation<String>) {
|
||||
withValue(v, x)
|
||||
}
|
||||
|
||||
suspend inline fun suspendInline(crossinline b: () -> String, x: Continuation<String>) {
|
||||
suspendInline(b(), x)
|
||||
}
|
||||
|
||||
suspend inline fun <reified T : Any> suspendInline(x: Continuation<String>) {
|
||||
suspendInline({ T::class.java.simpleName }, x)
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
c(Controller()).resume(Unit)
|
||||
}
|
||||
|
||||
class OK
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
builder {
|
||||
result = suspendInline("56")
|
||||
if (result != "56") throw RuntimeException("fail 1")
|
||||
|
||||
result = suspendInline { "57" }
|
||||
if (result != "57") throw RuntimeException("fail 2")
|
||||
|
||||
result = suspendInline<OK>()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user