From 0e92f980314d0e19babaf1bea69b2f1498ec596c Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 12 Sep 2023 14:58:55 +0300 Subject: [PATCH] [FIR2IR] Allow symbolTable cache lookups if IR f/o builder mode is enabled Without this change, the following test is failing: - FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.Collections.testInheritFromHashtable ^KT-58861 --- .../fir/backend/Fir2IrDeclarationStorage.kt | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 79f4ddc89ae..84a1c88db45 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1018,15 +1018,29 @@ class Fir2IrDeclarationStorage( */ signatureCalculator()?.let { signature -> val cachedInSymbolTable = referenceIfAny(signature) ?: return@let - if (isFakeOverride) { - val key = FakeOverrideIdentifier( - declaration.symbol.unwrapFakeOverrides(), - fakeOverrideOwnerLookupTag ?: declaration.containingClassLookupTag()!! - ) - irFakeOverridesForFirFakeOverrideMap[key] = cachedInSymbolTable - return cachedInSymbolTable - } else { - error("IR declaration with signature $signature found in SymbolTable and not found in declaration storage") + when { + isFakeOverride -> { + val key = FakeOverrideIdentifier( + declaration.symbol.unwrapFakeOverrides(), + fakeOverrideOwnerLookupTag ?: declaration.containingClassLookupTag()!! + ) + irFakeOverridesForFirFakeOverrideMap[key] = cachedInSymbolTable + return cachedInSymbolTable + } + configuration.useIrFakeOverrideBuilder -> { + /* + * If IR fake override builder is used for building fake-overrides, they are generated bypassing Fir2IrDeclarationStorage, + * and are written directly to SymbolTable. So in this case it is normal to save the result from symbol table into + * storage + * + * TODO: potentially this situation won't happen after migration from FIR2IR f/o generator to IR f/o generator (see KT-58861) + */ + cache[declaration] = cachedInSymbolTable + return cachedInSymbolTable + } + else -> { + error("IR declaration with signature $signature found in SymbolTable and not found in declaration storage") + } } }