From 8666b95dd2e94db7c1ff7d2357eb1c1f486b0375 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 3 Jul 2017 15:52:59 +0200 Subject: [PATCH] Delete local variables on default mask expantion #KT-18792 Fixed --- .../codegen/inline/defaultMethodUtil.kt | 6 ++-- .../defaultValues/maskElimination/kt18792.kt | 28 +++++++++++++++++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 6 ++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 ++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 ++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 ++++ .../InlineDefaultValuesTestsGenerated.java | 6 ++++ 7 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/defaultMethodUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/defaultMethodUtil.kt index 0a1dd8fb2e2..2b407d521b5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/defaultMethodUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/defaultMethodUtil.kt @@ -105,7 +105,7 @@ fun expandMaskConditionsAndUpdateVariableNodes( else null }.toList() - val toDelete = arrayListOf() + val toDelete = linkedSetOf() val toInsert = arrayListOf>() val defaultLambdasInfo = extractDefaultLambdasInfo(conditions, defaultLambdas, toDelete, toInsert) @@ -127,6 +127,8 @@ fun expandMaskConditionsAndUpdateVariableNodes( node.instructions.insert(position, newInsn) } + node.localVariables.removeIf { it.start in toDelete && it.end in toDelete } + node.remove(toDelete) return defaultLambdasInfo @@ -136,7 +138,7 @@ fun expandMaskConditionsAndUpdateVariableNodes( private fun extractDefaultLambdasInfo( conditions: List, defaultLambdas: Map, - toDelete: MutableList, + toDelete: MutableCollection, toInsert: MutableList> ): List { val defaultLambdaConditions = conditions.filter { it.expandNotDelete && defaultLambdas.contains(it.varIndex) } diff --git a/compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt b/compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt new file mode 100644 index 00000000000..6003e8bdccd --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt @@ -0,0 +1,28 @@ +// FILE: 1.kt +//WITH_RUNTIME + +package test + +class SceneContainer2() { + inline fun pushTo(vararg injects: Any, time: A = 0.seconds, transition: B = b) = pushTo(T::class.java, *injects, time = time, transition = transition) + + fun pushTo(clazz: Class, vararg injects: Any, time: A = 0.seconds, transition: B = b): T { + return "OK" as T + } +} + +class B + +val b = B() + +data class A(val x: Int) + +inline val Number.seconds: A get() = A(toInt()) + +// FILE: 2.kt + +import test.* + +fun box(): String { + return SceneContainer2().pushTo(time = 0.2.seconds) +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index efff0edd70a..101211d16c8 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -1321,6 +1321,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/maskElimination"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt18792.kt") + public void testKt18792() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/simple.kt"); diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index 7fee8a33f97..aa4afd387b6 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1321,6 +1321,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/maskElimination"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt18792.kt") + public void testKt18792() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 95868a8afe6..c2a55987be4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1321,6 +1321,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/maskElimination"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt18792.kt") + public void testKt18792() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 4bebf16b5ae..b9af20d66f6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1321,6 +1321,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/maskElimination"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt18792.kt") + public void testKt18792() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/simple.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java index fa492454ea1..a5e02ce8264 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java @@ -410,6 +410,12 @@ public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValu KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues/maskElimination"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("kt18792.kt") + public void testKt18792() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/kt18792.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/maskElimination/simple.kt");