From b6fa28ea81d046df2d6ccb2de83ddba4b33df4fd Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Thu, 6 May 2021 14:08:49 +0200 Subject: [PATCH] [JVM_IR] Deal with inline-class arguments in large arity lambdas. FunctionNVarargBridgeLowering checked the name of the method instead of whether the method overrides an invoke method. That doesn't work when the name of the function gets mangled because of inline class arguments. Fixed KT-45084. --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../lower/FunctionNVarargBridgeLowering.kt | 7 +++++-- .../codegen/box/inlineClasses/kt45084.kt | 20 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../LightAnalysisModeTestGenerated.java | 5 +++++ .../IrJsCodegenBoxES6TestGenerated.java | 5 +++++ .../IrJsCodegenBoxTestGenerated.java | 5 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++++ .../IrCodegenBoxWasmTestGenerated.java | 5 +++++ 10 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/box/inlineClasses/kt45084.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 b5df1c9061e..5adce461a90 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 @@ -18272,6 +18272,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @Test + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @Test @TestMetadata("kt45991.kt") public void testKt45991() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt index 9c578f8d80b..af309bc09a3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt @@ -91,8 +91,11 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) : ) // Add vararg invoke bridge - val invokeFunction = declaration.functions.single { - it.name.asString() == "invoke" && it.valueParameters.size == superType.arguments.size - if (it.isSuspend) 0 else 1 + val invokeFunction = declaration.functions.single { function -> + val overridesInvoke = function.overriddenSymbols.any { symbol -> + symbol.owner.name.asString() == "invoke" + } + overridesInvoke && function.valueParameters.size == superType.arguments.size - if (function.isSuspend) 0 else 1 } invokeFunction.overriddenSymbols = emptyList() declaration.addBridge(invokeFunction, functionNInvokeFun.owner) diff --git a/compiler/testData/codegen/box/inlineClasses/kt45084.kt b/compiler/testData/codegen/box/inlineClasses/kt45084.kt new file mode 100644 index 00000000000..58e99923f2a --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/kt45084.kt @@ -0,0 +1,20 @@ +// IGNORE_BACKEND: WASM + +inline class Z(val value: Long) + +fun f(g: ( + z: Z, + p01: Long, p02: Long, p03: Long, p04: Long, p05: Long, p06: Long, p07: Long, p08: Long, p09: Long, p10: Long, + p11: Long, p12: Long, p13: Long, p14: Long, p15: Long, p16: Long, p17: Long, p18: Long, p19: Long, p20: Long, + p21: Long, p22: Long +) -> Unit) { + g(Z(42L), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) +} + +fun box(): String { + var result = "" + f { z, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ -> + result = if (z.value == 42L) "OK" else "FAIL" + } + return result +} 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 097b4e85757..2c2d356e71b 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 @@ -18248,6 +18248,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @Test + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @Test @TestMetadata("kt45991.kt") public void testKt45991() 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 e9aaadd31ea..47613ad3a32 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 @@ -18272,6 +18272,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @Test + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @Test @TestMetadata("kt45991.kt") public void testKt45991() 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 7bc3ee5e9e9..85575d4b057 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15142,6 +15142,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/kt44141.kt"); } + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @TestMetadata("mangledDefaultParameterFunction.kt") public void testMangledDefaultParameterFunction() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 5f551d50e78..75cafc2bca3 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -13276,6 +13276,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @TestMetadata("kt45991.kt") public void testKt45991() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt45991.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index a1b34209e59..50c0b8d57a9 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -12687,6 +12687,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @TestMetadata("kt45991.kt") public void testKt45991() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt45991.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index ae445efa494..84c89001a76 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -12752,6 +12752,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @TestMetadata("kt45991.kt") public void testKt45991() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt45991.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 8e54f3f33d9..39aa1d9e85a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -6902,6 +6902,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/inlineClasses/kt44978.kt"); } + @TestMetadata("kt45084.kt") + public void testKt45084() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt45084.kt"); + } + @TestMetadata("kt45991.kt") public void testKt45991() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt45991.kt");