Obtain original suspend function view for inline codegen

It's necessary for generic inline suspend as a codegen
for it uses binding slice SUSPEND_FUNCTION_TO_JVM_VIEW
to generate fake continuation parameter, so all the
descriptors that are used for body generation must be
obtained from the SUSPEND_FUNCTION_TO_JVM_VIEW

 #KT-19528 Fixed
This commit is contained in:
Denis Zharkov
2017-08-23 15:30:20 +03:00
parent abb07ced6d
commit aef5911c7e
8 changed files with 129 additions and 1 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
suspend fun suspendThere(v: Any?): String = suspendCoroutineOrReturn { x ->
x.resume(v?.toString() ?: "<empty>")
COROUTINE_SUSPENDED
}
class A<T>(val arg: T) {
var result = ""
inline suspend fun foo() {
result = suspendThere(arg)
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
val a = A<String>("OK")
builder {
a.foo()
}
return a.result
}
@@ -0,0 +1,39 @@
// WITH_RUNTIME
// WITH_COROUTINES
// WITH_REFLECT
import helpers.*
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
suspend fun suspendThere(v: String): String = suspendCoroutineOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
suspend fun foo(x: suspend () -> String): String = x()
abstract class A {
inline suspend fun <reified T : Any> baz(): String {
return foo {
suspendThere(T::class.simpleName!!)
}
}
}
class B : A() {
suspend fun bar(): String {
return baz<OK>()
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
class OK
fun box(): String {
var result = "fail"
builder {
result = B().bar()
}
return result
}