Regenerate anonymous object if call site of non-inlineable
functional argument is suspend Split LambdaInfo into inlineable and non-inlineable #KT-26925
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// COMMON_COROUTINES_TEST
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// CHECK_STATE_MACHINE
|
||||
|
||||
// FILE: inline.kt
|
||||
|
||||
class MyDeferred<T>(val t: suspend () -> T) {
|
||||
suspend fun await() = t()
|
||||
}
|
||||
|
||||
fun <T> async(block: suspend () -> T) = MyDeferred(block)
|
||||
|
||||
inline fun <T, R> map(source: MyDeferred<T>, crossinline mapper: (T) -> R) =
|
||||
async {
|
||||
mapper(source.await())
|
||||
}
|
||||
|
||||
inline fun <T, R1, R2> map2(source: MyDeferred<T>, crossinline mapper1: (T) -> R1, crossinline mapper2: (R1) -> R2) =
|
||||
async {
|
||||
val c = suspend {
|
||||
mapper1(source.await())
|
||||
}
|
||||
mapper2(c())
|
||||
}
|
||||
|
||||
inline fun <T, R1, R2, R3> map3(source: MyDeferred<T>, crossinline mapper1: (T) -> R1, crossinline mapper2: (R1) -> R2, crossinline mapper3: (R2) -> R3) =
|
||||
async {
|
||||
val c = suspend {
|
||||
val c = suspend {
|
||||
mapper1(source.await())
|
||||
}
|
||||
mapper2(c())
|
||||
}
|
||||
mapper3(c())
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val source = MyDeferred { 1 }
|
||||
var result = -1
|
||||
builder {
|
||||
result = map(source) { it + 2 }.await()
|
||||
}
|
||||
if (result != 3) return "FAIL 1 $result"
|
||||
builder {
|
||||
result = map2(source, { it + 2 }, { it + 3 }).await()
|
||||
}
|
||||
if (result != 6) return "FAIL 2 $result"
|
||||
builder {
|
||||
result = map3(source, { it + 2 }, { it + 3 }, { it + 4 }).await()
|
||||
}
|
||||
if (result != 10) return "FAIL 3 $result"
|
||||
return "OK"
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// COMMON_COROUTINES_TEST
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// CHECK_STATE_MACHINE
|
||||
|
||||
// FILE: inline.kt
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
interface SuspendRunnable {
|
||||
suspend fun run()
|
||||
}
|
||||
|
||||
fun runSuspend(c: suspend () -> Unit) {
|
||||
c.startCoroutine(CheckStateMachineContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inlineMe(crossinline c1: suspend () -> Unit) {
|
||||
object : SuspendRunnable {
|
||||
override suspend fun run() {
|
||||
c1()
|
||||
}
|
||||
}.run()
|
||||
|
||||
StateMachineChecker.check(2)
|
||||
StateMachineChecker.reset()
|
||||
|
||||
runSuspend {
|
||||
object : SuspendRunnable {
|
||||
override suspend fun run() {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
}.run()
|
||||
|
||||
StateMachineChecker.check(2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FILE: box.kt
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(CheckStateMachineContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
inlineMe {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// COMMON_COROUTINES_TEST
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// CHECK_STATE_MACHINE
|
||||
|
||||
// FILE: inline.kt
|
||||
|
||||
import helpers.*
|
||||
|
||||
interface SuspendRunnable {
|
||||
suspend fun run()
|
||||
suspend fun ownIndependentInline()
|
||||
}
|
||||
|
||||
inline fun inlineMe(crossinline c1: suspend () -> Unit) =
|
||||
object : SuspendRunnable {
|
||||
override suspend fun run() {
|
||||
c1()
|
||||
c1()
|
||||
}
|
||||
|
||||
override suspend fun ownIndependentInline() {
|
||||
inlineMe2 {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}.ownIndependentInline()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline fun inlineMe2(crossinline c2: suspend () -> Unit): SuspendRunnable =
|
||||
object : SuspendRunnable {
|
||||
override suspend fun run() {
|
||||
}
|
||||
|
||||
override suspend fun ownIndependentInline() {
|
||||
c2()
|
||||
c2()
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(CheckStateMachineContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r = inlineMe {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
|
||||
builder {
|
||||
r.run()
|
||||
}
|
||||
StateMachineChecker.check(numberOfSuspensions = 4)
|
||||
StateMachineChecker.reset()
|
||||
builder {
|
||||
r.ownIndependentInline()
|
||||
}
|
||||
StateMachineChecker.check(numberOfSuspensions = 4)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// COMMON_COROUTINES_TEST
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// CHECK_STATE_MACHINE
|
||||
|
||||
// FILE: inline.kt
|
||||
|
||||
import helpers.*
|
||||
|
||||
interface SuspendRunnable {
|
||||
suspend fun run()
|
||||
suspend fun run2()
|
||||
}
|
||||
|
||||
inline fun inlineMe(crossinline c1: suspend () -> Unit, crossinline c2: suspend () -> Unit) =
|
||||
object : SuspendRunnable {
|
||||
override suspend fun run() {
|
||||
c1() // TODO: Double this call, when suspend markers are generated for inline and crossinline lambdas
|
||||
}
|
||||
|
||||
override suspend fun run2() {
|
||||
c2()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline fun inlineMe2(crossinline c1: suspend () -> Unit) =
|
||||
inlineMe(c1) {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(CheckStateMachineContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r = inlineMe2 {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
|
||||
builder {
|
||||
r.run()
|
||||
}
|
||||
StateMachineChecker.check(numberOfSuspensions = 2)
|
||||
StateMachineChecker.reset()
|
||||
builder {
|
||||
r.run2()
|
||||
}
|
||||
StateMachineChecker.check(numberOfSuspensions = 2)
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// COMMON_COROUTINES_TEST
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// CHECK_STATE_MACHINE
|
||||
|
||||
// FILE: inline.kt
|
||||
|
||||
import helpers.*
|
||||
|
||||
inline fun inlineMe(crossinline c: suspend () -> Unit) = suspend { c(); c() }
|
||||
|
||||
inline fun inlineMe2(crossinline c: suspend () -> Unit) = inlineMe { c(); c() }
|
||||
|
||||
// FILE: box.kt
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(CheckStateMachineContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r = inlineMe2 {
|
||||
StateMachineChecker.suspendHere()
|
||||
StateMachineChecker.suspendHere()
|
||||
}
|
||||
|
||||
builder {
|
||||
r()
|
||||
}
|
||||
StateMachineChecker.check(numberOfSuspensions = 8)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user