IC & Coroutines: Unbox inline classes of suspend lambdas

inside 'invoke' if 'create' does not override 'create' from
BaseContinuationImpl. In other words, when suspend lambda accepts more
than one parameter (including receiver).

Do that only if we do not generate bridge 'invoke' method, since
inline classes are unboxed in the bridge.

Use mangled name for 'create' function in this case inside 'invoke'.

 #KT-43249 In progress
 #KT-39847 Fixed
 #KT-38937 Fixed
This commit is contained in:
Ilmir Usmanov
2020-11-25 22:26:51 +01:00
parent 0a0b5b5d2b
commit eba260f681
11 changed files with 202 additions and 5 deletions
@@ -0,0 +1,22 @@
// WITH_RUNTIME
import kotlin.coroutines.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline class IC(val s: String)
fun box(): String {
var res = "FAIL"
val lambda: suspend (IC, IC) -> String = { a, b ->
a.s + b.s
}
builder {
res = lambda(IC("O"), IC("K"))
}
return res
}
@@ -0,0 +1,29 @@
// WITH_RUNTIME
import kotlin.coroutines.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline class IC(val s: String)
var c: Continuation<Any>? = null
var res = "FAIL"
fun box(): String {
val lambda: suspend (IC, IC) -> String = { _, _ ->
suspendCoroutine<String> {
@Suppress("UNCHECKED_CAST")
c = it as Continuation<Any>
}
}
builder {
res = lambda(IC("_"), IC("_"))
}
c?.resume("OK")
return res
}
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.*
import helpers.*
var result = "FAIL"
fun builder(c: suspend () -> Unit) {
c.startCoroutine(handleExceptionContinuation {
result = it.message!!
})
}
inline class IC(val s: String)
var c: Continuation<Any>? = null
fun box(): String {
val lambda: suspend (IC, IC) -> String = { _, _ ->
suspendCoroutine<String> {
@Suppress("UNCHECKED_CAST")
c = it as Continuation<Any>
}
}
builder {
lambda(IC("O"), IC("K"))
}
c?.resumeWithException(IllegalStateException("OK"))
return result
}