[FIR2IR] Extract logic of IR declarations generation into separate component. Part 6
Move caching of created IrProperty back to Fir2IrDeclarationStorage
This commit is contained in:
committed by
Space Team
parent
e83dc35ba5
commit
b3efad5428
+38
-6
@@ -517,10 +517,12 @@ class Fir2IrDeclarationStorage(
|
||||
fun getOrCreateIrProperty(
|
||||
property: FirProperty,
|
||||
irParent: IrDeclarationParent?,
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
isLocal: Boolean = false,
|
||||
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null
|
||||
): IrProperty {
|
||||
getCachedIrProperty(property)?.let { return it }
|
||||
return callablesGenerator.createIrProperty(property, irParent, isLocal = isLocal)
|
||||
return createAndCacheIrProperty(property, irParent, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag)
|
||||
}
|
||||
|
||||
fun getOrCreateIrPropertyByPureField(
|
||||
@@ -529,7 +531,7 @@ class Fir2IrDeclarationStorage(
|
||||
): IrProperty {
|
||||
return fieldToPropertyCache.getOrPut(field to irParent) {
|
||||
val containingClassId = (irParent as? IrClass)?.classId
|
||||
callablesGenerator.createIrProperty(
|
||||
createAndCacheIrProperty(
|
||||
field.toStubProperty(),
|
||||
irParent,
|
||||
fakeOverrideOwnerLookupTag = containingClassId?.toLookupTag()
|
||||
@@ -537,6 +539,38 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAndCacheIrProperty(
|
||||
property: FirProperty,
|
||||
irParent: IrDeclarationParent?,
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
isLocal: Boolean = false,
|
||||
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null
|
||||
): IrProperty {
|
||||
val irProperty = callablesGenerator.createIrProperty(property, irParent, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag)
|
||||
val irPropertySymbol = irProperty.symbol
|
||||
irProperty.backingField?.symbol?.let {
|
||||
backingFieldForPropertyCache[irPropertySymbol] = it
|
||||
propertyForBackingFieldCache[it] = irPropertySymbol
|
||||
}
|
||||
irProperty.getter?.let {
|
||||
getterForPropertyCache[irPropertySymbol] = it.symbol
|
||||
}
|
||||
irProperty.setter?.let {
|
||||
setterForPropertyCache[irPropertySymbol] = it.symbol
|
||||
}
|
||||
if (property.isFakeOverride(fakeOverrideOwnerLookupTag)) {
|
||||
val originalProperty = property.unwrapFakeOverrides()
|
||||
val key = FakeOverrideIdentifier(
|
||||
originalProperty.symbol,
|
||||
fakeOverrideOwnerLookupTag ?: property.containingClassLookupTag()!!
|
||||
)
|
||||
irFakeOverridesForFirFakeOverrideMap[key] = irProperty
|
||||
} else {
|
||||
propertyCache[property] = irProperty
|
||||
}
|
||||
return irProperty
|
||||
}
|
||||
|
||||
private fun FirField.toStubProperty(): FirProperty {
|
||||
val field = this
|
||||
return buildProperty {
|
||||
@@ -817,7 +851,7 @@ class Fir2IrDeclarationStorage(
|
||||
fakeOverrideOwnerLookupTag = this,
|
||||
getCachedIrDeclaration = ::getCachedIrProperty,
|
||||
createIrDeclaration = { parent, origin ->
|
||||
callablesGenerator.createIrProperty(
|
||||
createAndCacheIrProperty(
|
||||
fir, parent, predefinedOrigin = origin, fakeOverrideOwnerLookupTag = fakeOverrideOwnerLookupTag,
|
||||
)
|
||||
},
|
||||
@@ -1006,9 +1040,7 @@ class Fir2IrDeclarationStorage(
|
||||
propertyCache[fir]?.let { return it.backingField!!.symbol }
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
callablesGenerator.createIrProperty(fir, irParent, predefinedOrigin = parentOrigin).also {
|
||||
callablesGenerator.setAndModifyParent(it, irParent)
|
||||
}.backingField!!.symbol
|
||||
createAndCacheIrProperty(fir, irParent, predefinedOrigin = parentOrigin).backingField!!.symbol
|
||||
}
|
||||
else -> {
|
||||
getIrVariableSymbol(fir)
|
||||
|
||||
+4
-5
@@ -295,11 +295,10 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
||||
firSubClass: FirClass,
|
||||
firDelegateProperty: FirProperty
|
||||
): IrProperty {
|
||||
val delegateProperty =
|
||||
callablesGenerator.createIrProperty(
|
||||
firDelegateProperty, subClass, predefinedOrigin = IrDeclarationOrigin.DELEGATED_MEMBER,
|
||||
fakeOverrideOwnerLookupTag = firSubClass.symbol.toLookupTag()
|
||||
)
|
||||
val delegateProperty = declarationStorage.getOrCreateIrProperty(
|
||||
firDelegateProperty, subClass, predefinedOrigin = IrDeclarationOrigin.DELEGATED_MEMBER,
|
||||
fakeOverrideOwnerLookupTag = firSubClass.symbol.toLookupTag()
|
||||
)
|
||||
// the overridden symbols should be collected only after all fake overrides for all superclases are created and bound to their
|
||||
// overridden symbols, otherwise in some cases they will be left in inconsistent state leading to the errors in IR
|
||||
val baseSymbols = mutableListOf<FirPropertySymbol>()
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ class FakeOverrideGenerator(
|
||||
createFakeOverriddenIfNeeded(
|
||||
firClass, irClass, isLocal, propertyOrFieldSymbol,
|
||||
declarationStorage::getCachedIrProperty,
|
||||
callablesGenerator::createIrProperty,
|
||||
declarationStorage::getOrCreateIrProperty,
|
||||
createFakeOverrideSymbol = { firProperty, callableSymbol ->
|
||||
val symbolForOverride =
|
||||
FirFakeOverrideGenerator.createSymbolForSubstitutionOverride(callableSymbol, firClass.symbol.classId)
|
||||
|
||||
+2
-20
@@ -661,10 +661,6 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
}
|
||||
}
|
||||
}
|
||||
backingField.symbol.let {
|
||||
backingFieldForPropertyCache[symbol] = it
|
||||
propertyForBackingFieldCache[it] = symbol
|
||||
}
|
||||
this.backingField = backingField
|
||||
}
|
||||
if (irParent != null) {
|
||||
@@ -684,9 +680,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
startOffset, endOffset,
|
||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||
property.unwrapFakeOverrides().getter,
|
||||
).also {
|
||||
getterForPropertyCache[symbol] = it.symbol
|
||||
}
|
||||
)
|
||||
if (property.isVar) {
|
||||
this.setter = createIrPropertyAccessor(
|
||||
setter, property, this, type, irParent, true,
|
||||
@@ -700,23 +694,11 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
startOffset, endOffset,
|
||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||
property.unwrapFakeOverrides().setter,
|
||||
).also {
|
||||
setterForPropertyCache[symbol] = it.symbol
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (property.isFakeOverride(fakeOverrideOwnerLookupTag)) {
|
||||
val originalProperty = property.unwrapFakeOverrides()
|
||||
val key = Fir2IrDeclarationStorage.FakeOverrideIdentifier(
|
||||
originalProperty.symbol,
|
||||
fakeOverrideOwnerLookupTag ?: property.containingClassLookupTag()!!
|
||||
)
|
||||
irFakeOverridesForFirFakeOverrideMap[key] = result
|
||||
} else {
|
||||
propertyCache[property] = result
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user