diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt index ac4914c7953..6a95f8791ee 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.codegen.coroutines import com.intellij.util.ArrayUtil -import org.jetbrains.kotlin.backend.common.CONTINUATION_RESUME_METHOD_NAME import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.binding.CodegenBinding import org.jetbrains.kotlin.codegen.context.ClosureContext @@ -184,16 +183,8 @@ class CoroutineCodegen( ) checkcast(Type.getObjectType(v.thisName)) - // .resume(Unit) - StackValue.putUnitInstance(this) - invokevirtual( - AsmTypes.COROUTINE_IMPL.internalName, - CONTINUATION_RESUME_METHOD_NAME.identifier, - Type.getMethodDescriptor(Type.VOID_TYPE, AsmTypes.OBJECT_TYPE), - false - ) - - loadSuspendMarker() + // .doResume(Unit) + invokeDoResumeWithUnit(v.thisName) areturn(AsmTypes.OBJECT_TYPE) } diff --git a/compiler/testData/codegen/box/coroutines/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/dispatchResume.kt index 87e851f6e6c..9d9a0ee0c9b 100644 --- a/compiler/testData/codegen/box/coroutines/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/dispatchResume.kt @@ -1,6 +1,5 @@ // WITH_RUNTIME // WITH_COROUTINES -// IGNORE_BACKEND: JS import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* @@ -82,7 +81,7 @@ fun box(): String { val k = suspendWithValue("K") log += "$o$k;" } - if (result != "suspend(O);before 0;suspend(K);before 1;OK;after 1;after 0;") return "fail1: $result" + if (result != "before 0;suspend(O);before 1;suspend(K);before 2;OK;after 2;after 1;after 0;") return "fail1: $result" result = test { try { @@ -93,7 +92,7 @@ fun box(): String { log += "${e.message};" } } - if (result != "error(OK);before 0;OK;after 0;") return "fail2: $result" + if (result != "before 0;error(OK);before 1;OK;after 1;after 0;") return "fail2: $result" return "OK" } diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt index ccfc25a6cad..c0aea34e9e3 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt @@ -100,12 +100,12 @@ fun box(): String { var result = test { test1() } - if (result != "suspend();before 0;suspend(O);before 1;suspend(K);before 2;OK;after 2;after 1;after 0;") return "fail1: $result" + if (result != "before 0;suspend();before 1;suspend(O);before 2;suspend(K);before 3;OK;after 3;after 2;after 1;after 0;") return "fail1: $result" result = test { test2() } - if (result != "suspend();before 0;suspend(O);before 1;error(OK);before 2;OK;after 2;after 1;after 0;") return "fail2: $result" + if (result != "before 0;suspend();before 1;suspend(O);before 2;error(OK);before 3;OK;after 3;after 2;after 1;after 0;") return "fail2: $result" return "OK" } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index b136d03c031..0649fdd9261 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5355,13 +5355,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("dispatchResume.kt") public void testDispatchResume() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/dispatchResume.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("emptyClosure.kt") diff --git a/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt b/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt index ed1f31d1ddc..4c530b47bb0 100644 --- a/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt +++ b/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt @@ -17,7 +17,7 @@ import kotlin.coroutines.intrinsics.* public fun (suspend R.() -> T).createCoroutine( receiver: R, completion: Continuation -): Continuation = (this as kotlin.jvm.internal.CoroutineImpl).create(receiver, completion) +): Continuation = ((this as kotlin.jvm.internal.CoroutineImpl).create(receiver, completion) as kotlin.jvm.internal.CoroutineImpl).facade /** * Starts coroutine with receiver type [R] and result type [T]. @@ -30,7 +30,7 @@ public fun (suspend R.() -> T).startCoroutine( receiver: R, completion: Continuation ) { - (this as Function2, Any?>).invoke(receiver, completion) + createCoroutine(receiver, completion).resume(Unit) } /** @@ -43,7 +43,7 @@ public fun (suspend R.() -> T).startCoroutine( @Suppress("UNCHECKED_CAST") public fun (suspend () -> T).createCoroutine( completion: Continuation -): Continuation = (this as kotlin.jvm.internal.CoroutineImpl).create(completion) +): Continuation = ((this as kotlin.jvm.internal.CoroutineImpl).create(completion) as kotlin.jvm.internal.CoroutineImpl).facade /** * Starts coroutine without receiver and with result type [T]. @@ -55,7 +55,7 @@ public fun (suspend () -> T).createCoroutine( public fun (suspend () -> T).startCoroutine( completion: Continuation ) { - (this as Function1, Any?>).invoke(completion) + createCoroutine(completion).resume(Unit) } /**