diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index d40edd2b67a..3d45fe1a2b0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -439,10 +439,13 @@ inline fun FrameMap.evaluateOnce( fun MethodNode.textifyMethodNode(): String { val text = Textifier() val tmv = TraceMethodVisitor(text) - this.instructions.asSequence().forEach { it.accept(tmv) } - localVariables.forEach { text.visitLocalVariable(it.name, it.desc, it.signature, it.start.label, it.end.label, it.index) } + accept(tmv) val sw = StringWriter() - text.print(PrintWriter(sw)) + val pw = PrintWriter(sw) + pw.print(name) + pw.print(desc) + pw.print("\n") + text.print(pw) return "$sw" } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt index 531f92e7857..0d3058fe87d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.codegen.inline.* import org.jetbrains.kotlin.codegen.optimization.common.asSequence import org.jetbrains.kotlin.codegen.optimization.common.findPreviousOrNull import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer +import org.jetbrains.kotlin.codegen.optimization.fixStack.FixStackMethodTransformer import org.jetbrains.kotlin.config.isReleaseCoroutines import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -251,6 +252,7 @@ class SurroundSuspendLambdaCallsWithSuspendMarkersMethodVisitor( override fun performTransformations(methodNode: MethodNode) { fun AbstractInsnNode.index() = methodNode.instructions.indexOf(this) + FixStackMethodTransformer().transform(thisName, methodNode) val sourceFrames = MethodTransformer.analyze(thisName, methodNode, SourceInterpreter()) val noinlineInvokes = arrayListOf>() diff --git a/compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt b/compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt new file mode 100644 index 00000000000..72f4110e2c1 --- /dev/null +++ b/compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt @@ -0,0 +1,67 @@ +// FILE: inlined.kt +// COMMON_COROUTINES_TEST +// WITH_RUNTIME +// WITH_COROUTINES +// NO_CHECK_LAMBDA_INLINING + +interface Flow { + suspend fun collect(collector: FlowCollector) +} + +interface FlowCollector { + suspend fun emit(value: T) +} + +inline suspend fun Flow.collect(crossinline action: suspend (value: T) -> Unit): Unit = + collect(object : FlowCollector { + override suspend fun emit(value: T) = action(value) + }) + +inline fun Flow.transform( + crossinline transform: suspend FlowCollector.(value: T) -> Unit +): Flow = flow { + collect { value -> + return@collect transform(value) + } +} + +inline fun Flow.map(crossinline transform: suspend (value: T) -> R): Flow = transform { value -> + return@transform emit(transform(value)) +} + +public fun flow(block: suspend FlowCollector.() -> Unit): Flow = SafeFlow(block) + +private class SafeFlow(private val block: suspend FlowCollector.() -> Unit) : Flow { + override suspend fun collect(collector: FlowCollector) { + collector.block() + } +} + +// FILE: inlineSite.kt +// COMMON_COROUTINES_TEST +import COROUTINES_PACKAGE.* +import helpers.* + +fun Flow.abc() = map { line -> + try { + line + } catch (e: Exception) { + e.message!! + } +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var res = "FAIL" + builder { + flow { + emit("OK") + }.abc().collect { + res = it + } + } + return res +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 2ef2ef83475..4e29a4bb0a2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3813,6 +3813,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 06e2c787810..212a30a2b4d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3813,6 +3813,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 612e582bab8..d1d9cb3eb66 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3728,6 +3728,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index fbced8d3687..32502ed6f2f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3728,6 +3728,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java index d3f20a2c5da..e897b1da130 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineSuspendTestsGenerated.java @@ -113,6 +113,11 @@ public class IrInlineSuspendTestsGenerated extends AbstractIrInlineSuspendTests runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java index 0c84821acc6..b3f04d30090 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineSuspendTestsGenerated.java @@ -113,6 +113,11 @@ public class InlineSuspendTestsGenerated extends AbstractInlineSuspendTests { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/returnValue.kt", "kotlin.coroutines"); } + @TestMetadata("tryCatchReceiver.kt") + public void testTryCatchReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("tryCatchStackTransform.kt") public void testTryCatchStackTransform_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt", "kotlin.coroutines");