diff --git a/compiler/testData/codegen/bytecodeListing/coroutineFields.kt b/compiler/testData/codegen/bytecodeListing/coroutineFields.kt index d638c2c0131..92a3d0d5674 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutineFields.kt +++ b/compiler/testData/codegen/bytecodeListing/coroutineFields.kt @@ -1,17 +1,18 @@ +import kotlin.coroutines.* class Controller { suspend fun suspendHere() = suspendWithCurrentContinuation { x -> x.resume("OK") } } -fun builder(coroutine c: Controller.(String, Long) -> Continuation) { - c(Controller(), "", 2L).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + } fun box(): String { var result = "" - builder { x, y -> + builder { -> val z = "" val u = 1L result = suspendHere() diff --git a/compiler/testData/codegen/bytecodeListing/coroutineFields.txt b/compiler/testData/codegen/bytecodeListing/coroutineFields.txt index e2f397fc242..5c74bb06804 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutineFields.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutineFields.txt @@ -10,18 +10,17 @@ final class CoroutineFieldsKt$box$1 { private field J$0: long private field L$0: java.lang.Object private field L$1: java.lang.Object - private field p$0: java.lang.String - private field p$1: long + private field p$: Controller inner class CoroutineFieldsKt$box$1 - method (p0: kotlin.jvm.internal.Ref$ObjectRef): void - protected final method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): void - public final @org.jetbrains.annotations.NotNull method invoke(@org.jetbrains.annotations.NotNull p0: Controller, @org.jetbrains.annotations.NotNull p1: java.lang.String, p2: long): kotlin.coroutines.Continuation - public synthetic method invoke(p0: java.lang.Object, p1: java.lang.Object, p2: java.lang.Object): java.lang.Object + method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.coroutines.Continuation): void + protected final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object + public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.NotNull p0: Controller, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object + public synthetic method invoke(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object } @kotlin.Metadata public final class CoroutineFieldsKt { inner class CoroutineFieldsKt$box$1 public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String - public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function3): void + public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): void } diff --git a/compiler/testData/codegen/bytecodeText/constCoroutine.kt b/compiler/testData/codegen/bytecodeText/constCoroutine.kt index 2e0712f8cac..dc7940f63c6 100644 --- a/compiler/testData/codegen/bytecodeText/constCoroutine.kt +++ b/compiler/testData/codegen/bytecodeText/constCoroutine.kt @@ -1,10 +1,11 @@ -class Controller { - suspend fun suspendHere() = "" -} +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* +suspend fun suspendHere() = "" - -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) } fun box(): String { @@ -19,5 +20,5 @@ fun box(): String { } // 1 GETSTATIC kotlin/Unit.INSTANCE : Lkotlin/Unit; -// 1 GETSTATIC kotlin/coroutines/Suspend.INSTANCE +// 1 GETSTATIC EmptyContinuation.INSTANCE // 2 GETSTATIC diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/complicatedMerge.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/complicatedMerge.kt index 8972b652060..c98d3c6256d 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/complicatedMerge.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/complicatedMerge.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } fun foo() = true diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/i2bResult.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/i2bResult.kt index 4a8fd563eb3..6a20b8468d0 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/i2bResult.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/i2bResult.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var byteResult: Byte = 0 diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromBooleanArray.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromBooleanArray.kt index 9f3aa0d3d41..c5cee8b75ca 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromBooleanArray.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromBooleanArray.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var booleanResult = false diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromByteArray.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromByteArray.kt index e1e22943094..8457a8c201d 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromByteArray.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/loadFromByteArray.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var byteResult: Byte = 0 diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/noVariableInTable.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/noVariableInTable.kt index 4a7cfd6537e..dd7d272e2d7 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/noVariableInTable.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/noVariableInTable.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var booleanResult = false diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/sameIconst1ManyVars.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/sameIconst1ManyVars.kt index 6fa2ff81a9a..bd2441b8535 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/sameIconst1ManyVars.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/sameIconst1ManyVars.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var result: String = "" diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInArrayStore.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInArrayStore.kt index 24045035bbb..c38032aad72 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInArrayStore.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInArrayStore.kt @@ -1,12 +1,18 @@ // WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +// TARGET_BACKEND: JVM +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } @JvmField diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInMethodCall.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInMethodCall.kt index 75423fd16b1..6b59a5a4dff 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInMethodCall.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInMethodCall.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } private var booleanResult = false diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInPutfield.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInPutfield.kt index 628edd90881..e585bb33e1c 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInPutfield.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInPutfield.kt @@ -1,12 +1,18 @@ // WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +// TARGET_BACKEND: JVM +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } @JvmField diff --git a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInVarStore.kt b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInVarStore.kt index e08059f341e..d781767ffb5 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInVarStore.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/intLikeVarSpilling/usedInVarStore.kt @@ -1,11 +1,17 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* + class Controller { suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x -> x.resume(Unit) + SUSPENDED } } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend Controller.() -> Unit) { + c.startCoroutine(Controller(), EmptyContinuation) } fun box(): String { diff --git a/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt b/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt index 8336b1d2334..1bf3a1a1c1f 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt @@ -1,11 +1,13 @@ -class Controller { - suspend fun suspendHere(): String = suspendWithCurrentContinuation { x -> - x.resume("OK") - } +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* +suspend fun suspendHere(): String = suspendWithCurrentContinuation { x -> + x.resume("OK") } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) } fun box(): String { diff --git a/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTableSameSort.kt b/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTableSameSort.kt index d73aa0c6d62..452d4447d42 100644 --- a/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTableSameSort.kt +++ b/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTableSameSort.kt @@ -1,11 +1,13 @@ -class Controller { - suspend fun suspendHere(): String = suspendWithCurrentContinuation { x -> - x.resume("OK") - } +// WITH_RUNTIME +// WITH_COROUTINES +// TREAT_AS_ONE_FILE +import kotlin.coroutines.* +suspend fun suspendHere(): String = suspendWithCurrentContinuation { x -> + x.resume("OK") } -fun builder(coroutine c: Controller.() -> Continuation) { - c(Controller()).resume(Unit) +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) } fun box(): String { diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.kt b/compiler/tests-common/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.kt index db424d19151..a2eed17a080 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.test.ConfigurationKind +import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.utils.rethrow import org.junit.Assert import java.io.File @@ -33,7 +34,7 @@ abstract class AbstractBytecodeTextTest : CodegenTestCase() { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, javaFilesDir) loadMultiFiles(files) - if (isMultiFileTest(files)) { + if (isMultiFileTest(files) && !InTextDirectivesUtils.isDirectiveDefined(wholeFile.readText(), "TREAT_AS_ONE_FILE")) { doTestMultiFile(files) } else {