JVM_IR: do not optimize suspend$$forInline functions

`$$forInline` functions do not pass through the state machine generator,
and optimizing `Ref`s before that changes how assignments inside lambdas
passed to `suspendCoroutine`, etc. behave: without a `Ref`, the
assignment is not reflected in the continuation object, so the variable
has old value on resumption.

These functions will be optimized later, after they are inlined
somewhere and the state machine is generated.

^KT-52198 Fixed
This commit is contained in:
pyos
2022-04-29 13:29:42 +02:00
committed by Ilmir Usmanov
parent 153f878df4
commit effd21d074
14 changed files with 109 additions and 7 deletions
+40
View File
@@ -0,0 +1,40 @@
// WITH_COROUTINES
// WITH_STDLIB
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD
// FILE: lib.kt
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
suspend fun foo(value: String): String {
var x = "fail"
suspendCoroutineUninterceptedOrReturn<Unit> {
x = value
it.resume(Unit)
COROUTINE_SUSPENDED
}
return x
}
suspend inline fun fooInline(value: String): String {
var x = "fail"
suspendCoroutineUninterceptedOrReturn<Unit> {
x = value
it.resume(Unit)
COROUTINE_SUSPENDED
}
return x
}
// FILE: main.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun box(): String {
var result = ""
suspend {
result = foo("O") + fooInline("K")
}.startCoroutine(EmptyContinuation)
return result
}