JVM_IR: make continuation detection more consistent

* unify various checks for whether a suspend function needs a
    continuation;

  * mark the continuation parameter with an origin (this also allows
    correctly computing the offset of the local in codegen -- see the
    new test);

  * when wrapping `suspend fun main`, use a suspend reference instead of
    a synthetic non-suspend lambda (required to correctly implement the
    previous point, as previously the continuation parameter was passed
    to main() itself correctly only because of very lenient checks in
    AddContinuationLowering).
This commit is contained in:
pyos
2020-02-26 10:37:46 +01:00
committed by Ilmir Usmanov
parent c57f466494
commit 159d292ea7
13 changed files with 138 additions and 215 deletions
@@ -0,0 +1,22 @@
// WITH_RUNTIME
// WITH_COROUTINES
// TARGET_BACKEND: JVM
// FILE: a.kt
inline suspend fun f(crossinline lambda: suspend (Double) -> Double): Double {
val obj = object {
suspend fun g(x: Double): Double = lambda(x)
}
return obj.g(1.0)
}
// FILE: b.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun box(): String {
var result: Double = 0.0
suspend { result = f { it } }.startCoroutine(EmptyContinuation)
return if (result == 1.0) "OK" else "fail: $result"
}