From a7efa5c98bbe162d45cd8c671bb0d7215573425f Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Mon, 30 Nov 2020 13:16:23 +0100 Subject: [PATCH] [IR] Fix remapping of arguments in LocalDeclarationsLowering. It only remapped arguments for IrGetValue and not for IrSetValue. This is hitting Compose which has non-standard default argument handling. --- .../common/lower/LocalDeclarationsLowering.kt | 17 +++++++ .../backend/jvm/codegen/ExpressionCodegen.kt | 4 -- .../composeLikeBytecodeText/default.kt | 4 ++ .../composeLikeBytecodeText/defaultInline.kt | 3 ++ .../composeLikeBytecodeText/defaultLocal.kt | 4 ++ .../AbstractComposeLikeIrBytecodeTextTest.kt | 13 ++++++ .../ir/ComposeLikeGenerationExtension.kt | 7 +++ ...omposeLikeIrBytecodeTextTestGenerated.java | 46 +++++++++++++++++++ 8 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/composeLikeBytecodeText/default.kt create mode 100644 compiler/testData/codegen/composeLikeBytecodeText/defaultInline.kt create mode 100644 compiler/testData/codegen/composeLikeBytecodeText/defaultLocal.kt create mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/AbstractComposeLikeIrBytecodeTextTest.kt create mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt create mode 100644 compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/ComposeLikeIrBytecodeTextTestGenerated.java diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt index 5ec8868dc3c..aa4ad74b6a0 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt @@ -305,6 +305,23 @@ class LocalDeclarationsLowering( return expression } + override fun visitSetValue(expression: IrSetValue): IrExpression { + expression.transformChildrenVoid(this) + + val declaration = expression.symbol.owner + oldParameterToNew[declaration]?.let { + return IrSetValueImpl( + expression.startOffset, + expression.endOffset, + it.type, + it.symbol, + expression.value, + expression.origin + ) + } + return expression + } + override fun visitCall(expression: IrCall): IrExpression { expression.transformChildrenVoid(this) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 2953928ced8..fdb016e48b8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -346,10 +346,6 @@ class ExpressionCodegen( } private fun writeValueParameterInLocalVariableTable(param: IrValueParameter, startLabel: Label, endLabel: Label, isReceiver: Boolean) { - // TODO: old code has a special treatment for destructuring lambda parameters. - // There is no (easy) way to reproduce it with IR structures. - // Does not show up in tests, but might come to bite us at some point. - // If the parameter is an extension receiver parameter or a captured extension receiver from enclosing, // then generate name accordingly. val name = if (param.origin == BOUND_RECEIVER_PARAMETER || isReceiver) { diff --git a/compiler/testData/codegen/composeLikeBytecodeText/default.kt b/compiler/testData/codegen/composeLikeBytecodeText/default.kt new file mode 100644 index 00000000000..6f2dbd0bdea --- /dev/null +++ b/compiler/testData/codegen/composeLikeBytecodeText/default.kt @@ -0,0 +1,4 @@ +fun foo(s: String = "O") = s + +fun box() = foo() + foo("K") + diff --git a/compiler/testData/codegen/composeLikeBytecodeText/defaultInline.kt b/compiler/testData/codegen/composeLikeBytecodeText/defaultInline.kt new file mode 100644 index 00000000000..48384ba3361 --- /dev/null +++ b/compiler/testData/codegen/composeLikeBytecodeText/defaultInline.kt @@ -0,0 +1,3 @@ +inline fun foo(s: String = "O") = s + +fun box() = foo() + foo("K") diff --git a/compiler/testData/codegen/composeLikeBytecodeText/defaultLocal.kt b/compiler/testData/codegen/composeLikeBytecodeText/defaultLocal.kt new file mode 100644 index 00000000000..d3b1c75bc67 --- /dev/null +++ b/compiler/testData/codegen/composeLikeBytecodeText/defaultLocal.kt @@ -0,0 +1,4 @@ +fun box(): String { + fun foo(s: String = "O") = s + return foo() + foo("K") +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/AbstractComposeLikeIrBytecodeTextTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/AbstractComposeLikeIrBytecodeTextTest.kt new file mode 100644 index 00000000000..aa38c234f63 --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/AbstractComposeLikeIrBytecodeTextTest.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.ir + +import org.jetbrains.kotlin.codegen.AbstractBytecodeTextTest +import org.jetbrains.kotlin.test.TargetBackend + +abstract class AbstractComposeLikeIrBytecodeTextTest : AbstractBytecodeTextTest() { + override val backend = TargetBackend.JVM_IR +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt new file mode 100644 index 00000000000..52329090f27 --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.ir + diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/ComposeLikeIrBytecodeTextTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/ComposeLikeIrBytecodeTextTestGenerated.java new file mode 100644 index 00000000000..0f8c46e3c77 --- /dev/null +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/ComposeLikeIrBytecodeTextTestGenerated.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.ir; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/codegen/composeLike") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class ComposeLikeIrBytecodeTextTestGenerated extends AbstractComposeLikeIrBytecodeTextTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInComposeLike() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/composeLike"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/codegen/composeLike/default.kt"); + } + + @TestMetadata("defaultInline.kt") + public void testDefaultInline() throws Exception { + runTest("compiler/testData/codegen/composeLike/defaultInline.kt"); + } + + @TestMetadata("defaultLocal.kt") + public void testDefaultLocal() throws Exception { + runTest("compiler/testData/codegen/composeLike/defaultLocal.kt"); + } +}