[FIR2IR] Cache generated IR functions for data/value classes in declarations storage

Previously, DataClassMembersGenerator saved generated functions only in
  symbol table, which led to the situation when there is a FIR function
  in scopes, IR function in symbol table but no record about their relation
  in Fir2IrDeclarationStorage

^KT-61637
This commit is contained in:
Dmitriy Novozhilov
2023-08-31 11:28:55 +03:00
committed by Space Team
parent 58e8dfc23b
commit a3498bdd91
2 changed files with 8 additions and 1 deletions
@@ -352,6 +352,10 @@ class Fir2IrDeclarationStorage(
delegatedReverseCache[irFunction] = function
}
internal fun cacheGeneratedFunction(firFunction: FirSimpleFunction, irFunction: IrSimpleFunction) {
functionCache[firFunction] = irFunction
}
// ------------------------------------ constructors ------------------------------------
@OptIn(IrSymbolInternals::class)
@@ -198,6 +198,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
components.irBuiltIns.stringType,
)
irClass.declarations.add(toStringFunction)
declarationStorage.cacheGeneratedFunction(toStringContributedFunction, toStringFunction)
}
val hashcodeNameContributedFunction = contributedSyntheticFunctions[HASHCODE_NAME]
@@ -209,6 +210,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
components.irBuiltIns.intType,
)
irClass.declarations.add(hashCodeFunction)
declarationStorage.cacheGeneratedFunction(hashcodeNameContributedFunction, hashCodeFunction)
}
val equalsContributedFunction = contributedSyntheticFunctions[EQUALS]
@@ -222,6 +224,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
isOperator = true
)
irClass.declarations.add(equalsFunction)
declarationStorage.cacheGeneratedFunction(equalsContributedFunction, equalsFunction)
}
return result
@@ -291,7 +294,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
returnType: IrType,
otherParameterNeeded: Boolean = false,
isOperator: Boolean = false,
): IrFunction {
): IrSimpleFunction {
val signature = if (klass.symbol.classId.isLocal) null else components.signatureComposer.composeSignature(syntheticCounterpart)
return components.callablesGenerator.declareIrSimpleFunction(signature) { symbol ->
components.irFactory.createSimpleFunction(