Make CHECKCAST Object not break tail-call optimization

Since CHECKCAST Object does nothing for return value of suspend
function - the function returns references only, this is safe.
 #KT-49157 Fixed
This commit is contained in:
Ilmir Usmanov
2021-10-08 17:20:27 +02:00
committed by Space
parent 4a99f04b41
commit f760cd6736
6 changed files with 65 additions and 5 deletions
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
// WITH_COROUTINES
// CHECK_TAIL_CALL_OPTIMIZATION
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
suspend fun awaitInternal(): Any? = TailCallOptimizationChecker.saveStackTrace()
interface Deferred<out T> {
suspend fun await(): T
}
open class DeferredCoroutine<T> : Deferred<T> {
override suspend fun await(): T = awaitInternal() as T
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
builder {
DeferredCoroutine<String>().await()
}
TailCallOptimizationChecker.checkNoStateMachineIn("await\$suspendImpl")
return "OK"
}