From e83dc35ba5b8e3fa38fcf7c4f83d593c0e9bec1b Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 28 Aug 2023 13:10:50 +0300 Subject: [PATCH] [FIR2IR] Extract logic of IR declarations generation into separate component. Part 5 Move caching of created IrConstructor back to Fir2IrDeclarationStorage ^KT-61513 --- .../kotlin/fir/backend/Fir2IrDeclarationStorage.kt | 12 ++++++++++++ .../Fir2IrCallableDeclarationsGenerator.kt | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) 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 61a73f67fdc..b26ac7542a8 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 @@ -509,6 +509,11 @@ class Fir2IrDeclarationStorage( return callablesGenerator.createIrConstructor(constructor, irParent, predefinedOrigin, isLocal) } + @LeakedDeclarationCaches + internal fun cacheIrConstructor(constructor: FirConstructor, irConstructor: IrConstructor) { + constructorCache[constructor] = irConstructor + } + fun getOrCreateIrProperty( property: FirProperty, irParent: IrDeclarationParent?, @@ -1068,3 +1073,10 @@ internal fun FirCallableDeclaration.isFakeOverride(fakeOverrideOwnerLookupTag: C private object IsStubPropertyForPureFieldKey : FirDeclarationDataKey() internal var FirProperty.isStubPropertyForPureField: Boolean? by FirDeclarationDataRegistry.data(IsStubPropertyForPureFieldKey) + +/** + * Opt-in to this annotation indicates that some code uses annotated function but it actually shouldn't + * See KT-61513 + */ +@RequiresOptIn +annotation class LeakedDeclarationCaches diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/Fir2IrCallableDeclarationsGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/Fir2IrCallableDeclarationsGenerator.kt index 4a4b4a6ef82..d4059d0c12f 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/Fir2IrCallableDeclarationsGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/Fir2IrCallableDeclarationsGenerator.kt @@ -410,7 +410,8 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi metadata = FirMetadataSource.Function(constructor) // Add to cache before generating parameters to prevent an infinite loop when an annotation value parameter is annotated // with the annotation itself. - constructorCache[constructor] = this + @OptIn(LeakedDeclarationCaches::class) + declarationStorage.cacheIrConstructor(constructor, this) declarationStorage.withScope(symbol) { setAndModifyParent(this, irParent) declareParameters(constructor, irParent, dispatchReceiverType = null, isStatic = false, forSetter = false)