From 03aee58585a207e0589f202fa66940b6e13924c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Tue, 2 Aug 2022 12:30:30 +0200 Subject: [PATCH] JVM IR: Avoid IrComposite in ReturnableBlockLowering (KT-53202) --- .../codegen/FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../backend/common/lower/ReturnableBlockLowering.kt | 2 +- .../box/directInvokeOptimization/kt53202_returns.kt | 10 ++++++++++ .../runners/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../kotlin/js/test/JsCodegenBoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java | 6 ++++++ .../wasm/semantics/IrCodegenBoxWasmTestGenerated.java | 5 +++++ .../blackboxtest/NativeCodegenBoxTestGenerated.java | 6 ++++++ 10 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.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 9596572b824..193e0eb7172 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 @@ -16005,6 +16005,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt index c27d15b4e08..740d0568d3a 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt @@ -143,7 +143,7 @@ class ReturnableBlockTransformer(val context: CommonBackendContext, val containe newStatements ) - return builder.irComposite(expression, expression.origin) { + return builder.irBlock(expression, expression.origin) { +variable +loop +irGet(variable) diff --git a/compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt b/compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt new file mode 100644 index 00000000000..d907af636c1 --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt @@ -0,0 +1,10 @@ +fun box(): String { + val a = "" + + val c = fun(): String { + if (a != "") return "Fail" + return "OK" + }.invoke() + + return c +} 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 a6baa73df3c..6b0d7f58831 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 @@ -15819,6 +15819,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() 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 d13cb1aeed4..7c70aeff185 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 @@ -16005,6 +16005,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() 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 8be075934c3..4634aa08c7b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13030,6 +13030,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 431856d7ebf..e5f3bea5a10 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -12209,6 +12209,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index b75ae0eeca1..8042aebef77 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -12251,6 +12251,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index e324a049cbf..c3535990f14 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -10880,6 +10880,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 8ef3c9f34de..1d9388a5cf0 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -13255,6 +13255,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_funLiteral.kt"); } + @Test + @TestMetadata("kt53202_returns.kt") + public void testKt53202_returns() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/kt53202_returns.kt"); + } + @Test @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception {