From 5e25707648b48ef4926d388dbf7095f3c14ceae1 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Mon, 22 Jan 2024 18:55:34 +0100 Subject: [PATCH] [Fir2IR] Don't compute overriddenSymbols if ir builder is enabled Ir builder would recompute them anyway, while computation can lead to triggering computations in lazy classes too early, which is incorrect. ^KT-65116 --- ...LFirBlackBoxCodegenBasedTestGenerated.java | 6 +++++ ...rsedBlackBoxCodegenBasedTestGenerated.java | 6 +++++ .../generators/ClassMemberGenerator.kt | 16 +++++++++++-- ...LightTreeBlackBoxCodegenTestGenerated.java | 6 +++++ ...hIrFakeOverrideGeneratorTestGenerated.java | 6 +++++ .../FirPsiBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/box/fakeOverride/kt65116.kt | 24 +++++++++++++++++++ .../JvmAbiConsistencyTestBoxGenerated.java | 6 +++++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++++ ...kBoxCodegenWithIrInlinerTestGenerated.java | 6 +++++ .../LightAnalysisModeTestGenerated.java | 5 ++++ 11 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/box/fakeOverride/kt65116.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java index c7e7597d849..0f14a8d7f22 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java @@ -19280,6 +19280,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java index 2300af71102..059653c48b7 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java @@ -19280,6 +19280,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index 561294bc291..c258cf88183 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -211,7 +211,13 @@ internal class ClassMemberGenerator( declarationStorage.leaveScope(irFunction.symbol) } if (irFunction is IrSimpleFunction && firFunction is FirSimpleFunction && containingClass != null) { - irFunction.overriddenSymbols = firFunction.generateOverriddenFunctionSymbols(containingClass) + /** + * In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass] + * recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway. + */ + if (!configuration.useIrFakeOverrideBuilder) { + irFunction.overriddenSymbols = firFunction.generateOverriddenFunctionSymbols(containingClass) + } } } return irFunction @@ -223,7 +229,13 @@ internal class ClassMemberGenerator( val propertyType = property.returnTypeRef.toIrType() irProperty.initializeBackingField(property, initializerExpression = initializer ?: delegate) if (containingClass != null) { - irProperty.overriddenSymbols = property.generateOverriddenPropertySymbols(containingClass) + /** + * In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass] + * recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway. + */ + if (!configuration.useIrFakeOverrideBuilder) { + irProperty.overriddenSymbols = property.generateOverriddenPropertySymbols(containingClass) + } } val needGenerateDefaultGetter = property.getter is FirDefaultPropertyGetter || diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 3985279bac8..1f57835dc47 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -19269,6 +19269,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index 8275a312286..9f63d791a0d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -19269,6 +19269,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index c0472d17ba9..166b9145afd 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -19269,6 +19269,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/compiler/testData/codegen/box/fakeOverride/kt65116.kt b/compiler/testData/codegen/box/fakeOverride/kt65116.kt new file mode 100644 index 00000000000..d0447ea3f2d --- /dev/null +++ b/compiler/testData/codegen/box/fakeOverride/kt65116.kt @@ -0,0 +1,24 @@ +// TARGET_BACKEND: JVM_IR + +// FILE: Java1.java +public interface Java1 extends KotlinInterface { } + +//FILE: Java2.java +public interface Java2 { + public void bar(int o); +} + +//FILE: 1.kt +class A: Java1 { + override fun bar(o: Int) { } +} + +abstract class B : Java1 + +interface KotlinInterface : Java2 + +fun test(b: B) { + val k = b.bar(1) +} + +fun box() = "OK" \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java index 65cf80fff79..4f2e2e4d7c7 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java @@ -19269,6 +19269,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() 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 1547a485a24..6c0bc526f59 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 @@ -19269,6 +19269,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 5301fb1d663..db3e0e66dff 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -19269,6 +19269,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @Test + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @Test @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() 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 323b02f7118..1d63249f8bf 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16054,6 +16054,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt"); } + @TestMetadata("kt65116.kt") + public void testKt65116() throws Exception { + runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt"); + } + @TestMetadata("methodOfAnyFromInterface.kt") public void testMethodOfAnyFromInterface() throws Exception { runTest("compiler/testData/codegen/box/fakeOverride/methodOfAnyFromInterface.kt");