From 59398536d7d4a68990ad59ec00617e482dbb68bb Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Wed, 27 Mar 2019 17:30:36 +0300 Subject: [PATCH] Generate inline site's file name in metadata Otherwise, stacktraces will have invalid file name (declaration site). #KT-30508 Fixed --- .../inline/AnonymousObjectTransformer.kt | 1 - .../inline/coroutines/CoroutineTransformer.kt | 5 +- .../boxInline/suspend/fileNameInMetadata.kt | 49 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 ++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 ++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 ++ 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt index b7ff75e8909..9f2e4b353ea 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt @@ -133,7 +133,6 @@ class AnonymousObjectTransformer( val coroutineTransformer = CoroutineTransformer( inliningContext, classBuilder, - sourceInfo, methodsToTransform, superClassName ) 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 90a9777c79a..d57caaf9f72 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 @@ -26,7 +26,6 @@ import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode class CoroutineTransformer( private val inliningContext: InliningContext, private val classBuilder: ClassBuilder, - private val sourceFile: String?, private val methods: List, private val superClassName: String ) { @@ -111,7 +110,7 @@ class CoroutineTransformer( shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization, containingClassInternalName = classBuilder.thisName, isForNamedFunction = false, - sourceFile = sourceFile ?: "", + sourceFile = element.containingKtFile.name, isCrossinlineLambda = inliningContext.isContinuation ) } @@ -140,7 +139,7 @@ class CoroutineTransformer( isForNamedFunction = true, needDispatchReceiver = true, internalNameForDispatchReceiver = classBuilder.thisName, - sourceFile = sourceFile ?: "" + sourceFile = element.containingKtFile.name ) } } diff --git a/compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt b/compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt new file mode 100644 index 00000000000..20b227c8d3b --- /dev/null +++ b/compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt @@ -0,0 +1,49 @@ +// IGNORE_BACKEND: JVM_IR +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// WITH_COROUTINES + +// FILE: flow.kt +package flow + +interface FlowCollector { + suspend fun emit(value: T) +} + +interface Flow { + suspend fun collect(collector: FlowCollector) +} + +public inline fun flow(crossinline block: suspend FlowCollector.() -> Unit): Flow = object : Flow { + override suspend fun collect(collector: FlowCollector) = collector.block() +} + +inline suspend fun Flow.collect(crossinline action: suspend (T) -> Unit): Unit = + collect(object : FlowCollector { + override suspend fun emit(value: T) = action(value) + }) + +// FILE: Test.kt + +import flow.* +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var str = "FAIL" + builder { + flow { + var continuation: Continuation? = null + suspendCoroutineUninterceptedOrReturn { continuation = it; Unit } + str = "$continuation" + }.collect { + } + } + if ("(Test.kt:" !in str) return str + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index bee8770e61f..e19339a5ff0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3425,6 +3425,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/crossinlineSuspendLambdaInsideCrossinlineSuspendLambda.kt", "kotlin.coroutines"); } + @TestMetadata("fileNameInMetadata.kt") + public void testFileNameInMetadata() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt"); + } + @TestMetadata("inlineOrdinaryOfCrossinlineSuspend.kt") public void testInlineOrdinaryOfCrossinlineSuspend_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfCrossinlineSuspend.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 48e25997368..fbce461a698 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3425,6 +3425,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/crossinlineSuspendLambdaInsideCrossinlineSuspendLambda.kt", "kotlin.coroutines"); } + @TestMetadata("fileNameInMetadata.kt") + public void testFileNameInMetadata() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt"); + } + @TestMetadata("inlineOrdinaryOfCrossinlineSuspend.kt") public void testInlineOrdinaryOfCrossinlineSuspend_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfCrossinlineSuspend.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 222b84e87fd..0b23e3f1976 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3425,6 +3425,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/crossinlineSuspendLambdaInsideCrossinlineSuspendLambda.kt", "kotlin.coroutines"); } + @TestMetadata("fileNameInMetadata.kt") + public void testFileNameInMetadata() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/fileNameInMetadata.kt"); + } + @TestMetadata("inlineOrdinaryOfCrossinlineSuspend.kt") public void testInlineOrdinaryOfCrossinlineSuspend_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfCrossinlineSuspend.kt", "kotlin.coroutines.experimental");