From cf6f823d29812e45a97a610ac9ffb108ec4e5e3b Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 25 Nov 2019 08:38:38 +0100 Subject: [PATCH] Use descriptor from resolved call to inline accessors In case of inline it should be same descriptor (except of fake override), In general case getter could be synthetic accessor and in such case it's not inline --- .../jetbrains/kotlin/codegen/StackValue.java | 4 +-- compiler/testData/codegen/box/jvm8/kt33054.kt | 1 - .../codegen/boxInline/property/fromObject.kt | 27 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 ++++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 ++++ .../LightAnalysisModeTestGenerated.java | 20 +++++++------- .../IrBlackBoxInlineCodegenTestGenerated.java | 5 ++++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 ++++ ...PropertyAccessorsInlineTestsGenerated.java | 5 ++++ ...PropertyAccessorsInlineTestsGenerated.java | 5 ++++ 10 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/property/fromObject.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index 650d71f8c50..c3f46b0a4eb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -1683,7 +1683,7 @@ public abstract class StackValue { PropertyGetterDescriptor getterDescriptor = descriptor.getGetter(); assert getterDescriptor != null : "Getter descriptor should be not null for " + descriptor; if (resolvedCall != null && getterDescriptor.isInline()) { - CallGenerator callGenerator = codegen.getOrCreateCallGenerator(resolvedCall, getterDescriptor); + CallGenerator callGenerator = codegen.getOrCreateCallGenerator(resolvedCall, ((PropertyDescriptor)resolvedCall.getResultingDescriptor()).getGetter()); callGenerator.processAndPutHiddenParameters(false); callGenerator.genCall(getter, resolvedCall, false, codegen); } @@ -1764,7 +1764,7 @@ public abstract class StackValue { PropertySetterDescriptor setterDescriptor = descriptor.getSetter(); if (resolvedCall != null && setterDescriptor != null && setterDescriptor.isInline()) { assert setter != null : "Setter should be not null for " + descriptor; - CallGenerator callGenerator = codegen.getOrCreateCallGenerator(resolvedCall, setterDescriptor); + CallGenerator callGenerator = codegen.getOrCreateCallGenerator(resolvedCall, ((PropertyDescriptor)resolvedCall.getResultingDescriptor()).getSetter()); if (!skipReceiver) { putReceiver(v, false); } diff --git a/compiler/testData/codegen/box/jvm8/kt33054.kt b/compiler/testData/codegen/box/jvm8/kt33054.kt index b42c15ca051..a4a2f810756 100644 --- a/compiler/testData/codegen/box/jvm8/kt33054.kt +++ b/compiler/testData/codegen/box/jvm8/kt33054.kt @@ -1,6 +1,5 @@ // IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM -// IGNORE_BACKEND: JVM // JVM_TARGET: 1.8 open class A(val x: String) { diff --git a/compiler/testData/codegen/boxInline/property/fromObject.kt b/compiler/testData/codegen/boxInline/property/fromObject.kt new file mode 100644 index 00000000000..833e8b9bc57 --- /dev/null +++ b/compiler/testData/codegen/boxInline/property/fromObject.kt @@ -0,0 +1,27 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// FILE: 1.kt +// WITH_RUNTIME +package test + +open class A(var result: String) { + + var y + inline get() = if (this is C) this else A(result) + inline set(a: A) { + if (this is C) this else A(a.result.also { this.result = it }) + } +} + +object C : A("failA") + +object B : A("failB") + +// FILE: 2.kt +import test.A +import test.B.y + +fun box(): String { + y = A("OK") + + return y.result +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 084e6ef77b7..8ddcb26d2f2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2684,6 +2684,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 113e6d4a875..69f971becaf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2684,6 +2684,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4f49727e1ef..bfdd62c684a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14546,16 +14546,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Jvm8 extends AbstractLightAnalysisModeTest { - @TestMetadata("kt29242.kt") - public void ignoreKt29242() throws Exception { - runTest("compiler/testData/codegen/box/jvm8/kt29242.kt"); - } - - @TestMetadata("kt33054.kt") - public void ignoreKt33054() throws Exception { - runTest("compiler/testData/codegen/box/jvm8/kt33054.kt"); - } - private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -14629,6 +14619,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/kt16588.kt"); } + @TestMetadata("kt29242.kt") + public void testKt29242() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/kt29242.kt"); + } + + @TestMetadata("kt33054.kt") + public void testKt33054() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/kt33054.kt"); + } + @TestMetadata("kt6301.kt") public void testKt6301() throws Exception { runTest("compiler/testData/codegen/box/jvm8/kt6301.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index bdcbb42235b..53bbbe3ab11 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -2684,6 +2684,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index 00f4a70ab3c..0ed8dafa77c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2684,6 +2684,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrPropertyAccessorsInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrPropertyAccessorsInlineTestsGenerated.java index 13f74d21db1..596dae8d9ee 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrPropertyAccessorsInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrPropertyAccessorsInlineTestsGenerated.java @@ -59,6 +59,11 @@ public class IrPropertyAccessorsInlineTestsGenerated extends AbstractIrPropertyA runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java index cb80af3522e..c500b4ab9c7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java @@ -59,6 +59,11 @@ public class PropertyAccessorsInlineTestsGenerated extends AbstractPropertyAcces runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("fromObject.kt") + public void testFromObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/fromObject.kt"); + } + @TestMetadata("kt22649.kt") public void testKt22649() throws Exception { runTest("compiler/testData/codegen/boxInline/property/kt22649.kt");