From fda47c45ecd59dc9ba25c6c4d87730070b3c93a1 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 13 Sep 2023 14:32:43 +0200 Subject: [PATCH] IR: do not change overrides for lazy IR in FakeOverrideRebuilder `FakeOverrideBuilder.provideFakeOverrides` recursively changes overrides for all superclasses in the hierarchy, including lazy IR, which is a lot of extra work. Also it leads to some tests failing in the IR fake override builder mode because it changes correct fake overrides of Java classes to incorrect ones. Those tests are unmuted but it doesn't mean they are fixed -- most likely we'll generate fake overrides via IR for lazy IR too, at which point they'll start to fail again. --- .../common/actualizer/FakeOverrideRebuilder.kt | 2 +- .../backend/common/overrides/FakeOverrides.kt | 16 ++++++++-------- .../collections/irrelevantImplCharSequence.kt | 2 -- .../differentDependencyVersion/kt51194_java.kt | 1 - .../box/fir/syntheticPropertyThroughJava.kt | 1 - .../syntheticPropertyThroughJavaMultiModule.kt | 2 -- .../syntheticPropertyThroughJavaWithSetter.kt | 1 - compiler/testData/codegen/box/ir/kt41765.kt | 1 - ...conflictingOverloadsForThrowableInheritors.kt | 1 - ...onflictingOverloadsForThrowableInheritors2.kt | 1 - .../testData/codegen/box/jvm8/treeMapBridge.kt | 1 - 11 files changed, 9 insertions(+), 20 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/FakeOverrideRebuilder.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/FakeOverrideRebuilder.kt index 651ec02c117..512b133c696 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/FakeOverrideRebuilder.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/FakeOverrideRebuilder.kt @@ -134,7 +134,7 @@ class FakeOverrideRebuilder( for (c in irClass.superTypes) { c.getClass()?.let { rebuildClassFakeOverrides(it) } } - fakeOverrideBuilder.provideFakeOverrides(irClass, CompatibilityMode.CURRENT) + fakeOverrideBuilder.buildFakeOverridesForSingleClass(irClass, CompatibilityMode.CURRENT) val overriddenMap = mutableMapOf() diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/overrides/FakeOverrides.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/overrides/FakeOverrides.kt index 851327f44d9..685d21c7925 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/overrides/FakeOverrides.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/overrides/FakeOverrides.kt @@ -108,13 +108,8 @@ class FakeOverrideBuilder( private fun buildFakeOverrideChainsForClass(clazz: IrClass, compatibilityMode: CompatibilityMode): Boolean { if (haveFakeOverrides.contains(clazz)) return true - val superTypes = clazz.superTypes - - val superClasses = superTypes.map { - it.getClass() ?: error("Unexpected super type: $it") - } - - superClasses.forEach { superClass -> + for (supertype in clazz.superTypes) { + val superClass = supertype.getClass() ?: error("Unexpected super type: ${supertype.render()}") val mode = fakeOverrideCandidates[superClass] ?: compatibilityMode if (buildFakeOverrideChainsForClass(superClass, mode)) haveFakeOverrides.add(superClass) @@ -122,12 +117,17 @@ class FakeOverrideBuilder( if (!platformSpecificClassFilter.needToConstructFakeOverrides(clazz)) return false + buildFakeOverridesForSingleClass(clazz, compatibilityMode) + + return true + } + + fun buildFakeOverridesForSingleClass(clazz: IrClass, compatibilityMode: CompatibilityMode) { fakeOverrideDeclarationTable.run { inFile(clazz.fileOrNull) { irOverridingUtil.buildFakeOverridesForClass(clazz, compatibilityMode.oldSignatures) } } - return true } override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) { diff --git a/compiler/testData/codegen/box/collections/irrelevantImplCharSequence.kt b/compiler/testData/codegen/box/collections/irrelevantImplCharSequence.kt index 8308f11d30a..6b6a5045817 100644 --- a/compiler/testData/codegen/box/collections/irrelevantImplCharSequence.kt +++ b/compiler/testData/codegen/box/collections/irrelevantImplCharSequence.kt @@ -1,6 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61370 - // FILE: J.java public class J { diff --git a/compiler/testData/codegen/box/differentDependencyVersion/kt51194_java.kt b/compiler/testData/codegen/box/differentDependencyVersion/kt51194_java.kt index 961000b82d7..97354630450 100644 --- a/compiler/testData/codegen/box/differentDependencyVersion/kt51194_java.kt +++ b/compiler/testData/codegen/box/differentDependencyVersion/kt51194_java.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61804 // ISSUE: KT-51194 // MODULE: coreLib_1 diff --git a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJava.kt b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJava.kt index 90180eaee83..17b129ceb85 100644 --- a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJava.kt +++ b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJava.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM_IR -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61805 // ISSUE: KT-59550 // FILE: Intermediate.java diff --git a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt index aba3e0da66b..a12dd4bc013 100644 --- a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt +++ b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaMultiModule.kt @@ -1,7 +1,5 @@ // TARGET_BACKEND: JVM_IR // ISSUE: KT-59550 (related) -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61805 - // MODULE: m1 // FILE: Base.kt abstract class Base(internal val foo: String) { diff --git a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt index b077c647610..4e6e0b0bc0d 100644 --- a/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt +++ b/compiler/testData/codegen/box/fir/syntheticPropertyThroughJavaWithSetter.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM_IR -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61805 // ISSUE: KT-59550 // FILE: Intermediate.java diff --git a/compiler/testData/codegen/box/ir/kt41765.kt b/compiler/testData/codegen/box/ir/kt41765.kt index ea2d12eba3d..7ea4e75c1ce 100644 --- a/compiler/testData/codegen/box/ir/kt41765.kt +++ b/compiler/testData/codegen/box/ir/kt41765.kt @@ -1,5 +1,4 @@ // MODULE: lib -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61543 // FILE: lib.kt // KT-41765 diff --git a/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors.kt b/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors.kt index 0cede6a58de..3263d2d1eb8 100644 --- a/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors.kt +++ b/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61805 // FULL_JDK // ISSUE: KT-45584 diff --git a/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt b/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt index 6c3970c4cc7..3263d2d1eb8 100644 --- a/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt +++ b/compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt @@ -1,6 +1,5 @@ // TARGET_BACKEND: JVM // FULL_JDK -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61805 // ISSUE: KT-45584 // FILE: PlaceholderExceptionSupport.java diff --git a/compiler/testData/codegen/box/jvm8/treeMapBridge.kt b/compiler/testData/codegen/box/jvm8/treeMapBridge.kt index 6d22950ea40..852cfb7774c 100644 --- a/compiler/testData/codegen/box/jvm8/treeMapBridge.kt +++ b/compiler/testData/codegen/box/jvm8/treeMapBridge.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: KT-61370 // java.lang.NoSuchMethodError: java.util.TreeMap.remove // IGNORE_BACKEND: ANDROID