JVM_IR: Support suspend lambdas with receivers and multiple parameters
In old BE we generate `create` for this kind of suspend lambdas, which, like in simple suspend lambdas is responsible for putting arguments (including extension receiver) to fields. But, if number of parameters of suspend lambda (including receiver) >= 1, there is no need to generate `create`, since `create` is called only by `createCoroutine` and friends from stdlib, and there is no version of `createCoroutine` for lambdas with multiple parameters. Thus, in old BE we generate a redundant method, which affects method count. In JVM_BE we decided to 'inline' create into `invoke` for suspend lambdas with multiple parameters.
This commit is contained in:
-1
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// COMMON_COROUTINES_TEST
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
import COROUTINES_PACKAGE.intrinsics.*
|
||||
|
||||
suspend fun suspendHere(v: String): String = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(v)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
class Controller {
|
||||
var result = ""
|
||||
|
||||
override fun toString() = "Controller"
|
||||
}
|
||||
|
||||
val controller = Controller()
|
||||
|
||||
suspend fun foo(c: suspend Controller.(Long, Int, String) -> String) = controller.c(56L, 55, "abc")
|
||||
|
||||
fun box(): String {
|
||||
var final = ""
|
||||
|
||||
builder {
|
||||
final = foo { l, i, s ->
|
||||
result = suspendHere("$this#$l#$i#$s")
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
|
||||
if (controller.result != "Controller#56#55#abc") return "fail: ${controller.result}"
|
||||
|
||||
return final
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user