From 368465e24ba13894db1af3b2b5055b7dc77d8220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Mon, 21 Mar 2022 20:59:30 +0100 Subject: [PATCH] JVM IR: Resolve fake overrides during inline class mangling This is necessary to determine which mangling scheme to use (KT-51672). (cherry picked from commit 1134dc3858a6d330e0a12cf5503bb7b2b8d6fd9d) --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../jvm/MemoizedInlineClassReplacements.kt | 11 +++++----- .../codegen/box/inlineClasses/kt51672.kt | 20 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../LightAnalysisModeTestGenerated.java | 5 +++++ 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/codegen/box/inlineClasses/kt51672.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 89fb05d7465d7..583f7071f9452 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -21189,6 +21189,12 @@ public void testKt51353() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt51353.kt"); } + @Test + @TestMetadata("kt51672.kt") + public void testKt51672() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt51672.kt"); + } + @Test @TestMetadata("mangledDefaultParameterFunction.kt") public void testMangledDefaultParameterFunction() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt index b9d80b77a784d..cc385fc370a21 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt @@ -234,12 +234,11 @@ class MemoizedInlineClassReplacements( val replacement = buildReplacementInner(function, replacementOrigin, noFakeOverride, useOldManglingScheme, body) // When using the new mangling scheme we might run into dependencies using the old scheme // for which we will fall back to the old mangling scheme as well. - if ( - !useOldManglingScheme && - replacement.name.asString().contains("-") && - function.parentClassId?.let { classFileContainsMethod(it, replacement, context) } == false - ) { - return buildReplacementInner(function, replacementOrigin, noFakeOverride, true, body) + if (!useOldManglingScheme && replacement.name.asString().contains('-') && function.parentClassId != null) { + val resolved = (function as? IrSimpleFunction)?.resolveFakeOverride(true) + if (resolved?.parentClassId?.let { classFileContainsMethod(it, replacement, context) } == false) { + return buildReplacementInner(function, replacementOrigin, noFakeOverride, true, body) + } } return replacement } diff --git a/compiler/testData/codegen/box/inlineClasses/kt51672.kt b/compiler/testData/codegen/box/inlineClasses/kt51672.kt new file mode 100644 index 0000000000000..449e71ff5ded6 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/kt51672.kt @@ -0,0 +1,20 @@ +// MODULE: lib +// WITH_STDLIB +// TARGET_BACKEND: JVM +// FILE: lib.kt +@JvmInline +value class S(val value: String) + +interface A { + fun f(s: S): S = s +} + +interface B : A + +// MODULE: main(lib) +// FILE: main.kt +interface C : B + +fun box(): String { + return object : C {}.f(S("OK")).value +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 212217b6906e2..4b7d760c614dc 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -19929,6 +19929,12 @@ public void testKt51353() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt51353.kt"); } + @Test + @TestMetadata("kt51672.kt") + public void testKt51672() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt51672.kt"); + } + @Test @TestMetadata("mangledDefaultParameterFunction.kt") public void testMangledDefaultParameterFunction() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 1d72f94f5b8a0..9d440140acd26 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -21189,6 +21189,12 @@ public void testKt51353() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt51353.kt"); } + @Test + @TestMetadata("kt51672.kt") + public void testKt51672() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt51672.kt"); + } + @Test @TestMetadata("mangledDefaultParameterFunction.kt") public void testMangledDefaultParameterFunction() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index dfa88c05627fa..1f9331dbd96e7 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16592,6 +16592,11 @@ public void testKt51353() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt51353.kt"); } + @TestMetadata("kt51672.kt") + public void testKt51672() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt51672.kt"); + } + @TestMetadata("mangledDefaultParameterFunction.kt") public void testMangledDefaultParameterFunction() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());