JS: replace suspend inline metadata after inlining
This fixes some issues on coroutine inlining, see tests
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import helpers.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
var stopped = false
|
||||
var log = ""
|
||||
var postponed: () -> Unit = { }
|
||||
|
||||
suspend fun delay(): Unit = suspendCoroutine { c ->
|
||||
log += "1"
|
||||
postponed = {
|
||||
log += "3"
|
||||
c.resume(Unit)
|
||||
}
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend inline fun foo(x: String): String {
|
||||
delay()
|
||||
return x
|
||||
}
|
||||
|
||||
suspend inline fun bar(x: String) = foo(x)
|
||||
|
||||
suspend fun baz(x: String) = bar(x)
|
||||
|
||||
fun act(c: suspend () -> Unit) {
|
||||
stopped = false
|
||||
|
||||
c.startCoroutine(handleResultContinuation {
|
||||
stopped = true
|
||||
})
|
||||
|
||||
while (!stopped) {
|
||||
log += "2"
|
||||
postponed()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
act {
|
||||
result = baz("OK")
|
||||
}
|
||||
|
||||
if (log != "123") return "fail: $log"
|
||||
return result
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_COROUTINES
|
||||
// WITH_RUNTIME
|
||||
|
||||
// MODULE: lib(support)
|
||||
// FILE: lib.kt
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
var continuation: () -> Unit = { }
|
||||
var log = ""
|
||||
var finished = false
|
||||
|
||||
suspend fun <T> foo(v: T): T = suspendCoroutineOrReturn { x ->
|
||||
continuation = {
|
||||
x.resume(v)
|
||||
}
|
||||
log += "foo($v);"
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
inline suspend fun boo(v: String): String {
|
||||
foo("!$v")
|
||||
log += "boo($v);"
|
||||
return foo(v)
|
||||
}
|
||||
|
||||
inline suspend fun bar(v: String): String {
|
||||
val x = boo(v)
|
||||
log += "bar($x);"
|
||||
return x
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(handleResultContinuation {
|
||||
continuation = { }
|
||||
finished = true
|
||||
})
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
suspend fun baz() {
|
||||
val a = bar("A")
|
||||
log += "$a;"
|
||||
log += "between bar;"
|
||||
val b = bar("B")
|
||||
log += "$b;"
|
||||
}
|
||||
|
||||
val expectedString =
|
||||
"foo(!A);@;boo(A);foo(A);@;bar(A);A;" +
|
||||
"between bar;" +
|
||||
"foo(!B);@;boo(B);foo(B);@;bar(B);B;"
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
baz()
|
||||
}
|
||||
|
||||
while (!finished) {
|
||||
log += "@;"
|
||||
continuation()
|
||||
}
|
||||
|
||||
if (log != expectedString) return "fail: $log"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
suspend inline fun foo(v: String): String = v
|
||||
|
||||
suspend inline fun bar(): String = foo("O")
|
||||
|
||||
// MODULE: main(lib, support)
|
||||
// FILE: main.kt
|
||||
import helpers.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
builder {
|
||||
result = bar()
|
||||
result += foo("K")
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user