From 8487211ae18cb4a2db6cc8f2e9c3a3e1809385ae Mon Sep 17 00:00:00 2001 From: pyos Date: Fri, 6 Mar 2020 10:35:35 +0100 Subject: [PATCH] JVM_IR: refine the condition for mangling names of multifile members Private $$forInline versions of public suspend functions should not be mangled. (Note that there are no $$forInline versions of private suspend functions, as those are effectively inline-only.) --- .../jvm/codegen/MethodSignatureMapper.kt | 4 +-- .../suspend/inlineSuspendInMultifileClass.kt | 34 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 +++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 +++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 +++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 +++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index d25d240af7e..0e5bcdcf276 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -112,8 +112,8 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { val newName = JvmCodegenUtil.sanitizeNameIfNeeded(name, context.state.languageVersionSettings) if (function.isTopLevel) { - if (Visibilities.isPrivate(function.visibility) && newName != "" && - (function.parent as? IrClass)?.attributeOwnerId in context.multifileFacadeForPart + if (Visibilities.isPrivate(if (function.isSuspend) function.suspendFunctionOriginal().visibility else function.visibility) && + newName != "" && (function.parent as? IrClass)?.attributeOwnerId in context.multifileFacadeForPart ) { return "$newName$${function.parentAsClass.name.asString()}" } diff --git a/compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt b/compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt new file mode 100644 index 00000000000..ddf2fbdc3bf --- /dev/null +++ b/compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt @@ -0,0 +1,34 @@ +// FILE: test.kt +// WITH_RUNTIME +// WITH_COROUTINES +// NO_CHECK_LAMBDA_INLINING +// TARGET_BACKEND: JVM +// !INHERIT_MULTIFILE_PARTS + +// The lambda in box() attempts to store the result in a null Ref for some reason. +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_MULTI_MODULE: JVM + +@file:JvmMultifileClass +@file:JvmName("XKt") + +suspend fun suspendHere() {} + +suspend inline fun test(c: suspend () -> String): String { + suspendHere() + val result = c() + suspendHere() + return result +} + +// FILE: box.kt +import kotlin.coroutines.* +import helpers.* + +fun box() : String { + var res = "fail" + suspend { + res = test { "OK" } + }.startCoroutine(EmptyContinuation) + return res +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 9928a668700..d84ffccacb4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -3718,6 +3718,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendContinuation.kt", "kotlin.coroutines"); } + @TestMetadata("inlineSuspendInMultifileClass.kt") + public void testInlineSuspendInMultifileClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt"); + } + @TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt") public void testInlineSuspendOfCrossinlineOrdinary_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.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 eb8a4507258..d600a5cd28e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3718,6 +3718,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendContinuation.kt", "kotlin.coroutines"); } + @TestMetadata("inlineSuspendInMultifileClass.kt") + public void testInlineSuspendInMultifileClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt"); + } + @TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt") public void testInlineSuspendOfCrossinlineOrdinary_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.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 ede7432e6a6..d105f139e4d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -3683,6 +3683,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendContinuation.kt", "kotlin.coroutines"); } + @TestMetadata("inlineSuspendInMultifileClass.kt") + public void testInlineSuspendInMultifileClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt"); + } + @TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt") public void testInlineSuspendOfCrossinlineOrdinary_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.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 3bf2fd54722..9a05bdf064d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -3683,6 +3683,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendContinuation.kt", "kotlin.coroutines"); } + @TestMetadata("inlineSuspendInMultifileClass.kt") + public void testInlineSuspendInMultifileClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendInMultifileClass.kt"); + } + @TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt") public void testInlineSuspendOfCrossinlineOrdinary_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.kt", "kotlin.coroutines");