[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(
|
fun getOrCreateIrProperty(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
irParent: IrDeclarationParent?,
|
irParent: IrDeclarationParent?,
|
||||||
|
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||||
isLocal: Boolean = false,
|
isLocal: Boolean = false,
|
||||||
|
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null
|
||||||
): IrProperty {
|
): IrProperty {
|
||||||
getCachedIrProperty(property)?.let { return it }
|
getCachedIrProperty(property)?.let { return it }
|
||||||
return callablesGenerator.createIrProperty(property, irParent, isLocal = isLocal)
|
return createAndCacheIrProperty(property, irParent, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getOrCreateIrPropertyByPureField(
|
fun getOrCreateIrPropertyByPureField(
|
||||||
@@ -529,7 +531,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
): IrProperty {
|
): IrProperty {
|
||||||
return fieldToPropertyCache.getOrPut(field to irParent) {
|
return fieldToPropertyCache.getOrPut(field to irParent) {
|
||||||
val containingClassId = (irParent as? IrClass)?.classId
|
val containingClassId = (irParent as? IrClass)?.classId
|
||||||
callablesGenerator.createIrProperty(
|
createAndCacheIrProperty(
|
||||||
field.toStubProperty(),
|
field.toStubProperty(),
|
||||||
irParent,
|
irParent,
|
||||||
fakeOverrideOwnerLookupTag = containingClassId?.toLookupTag()
|
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 {
|
private fun FirField.toStubProperty(): FirProperty {
|
||||||
val field = this
|
val field = this
|
||||||
return buildProperty {
|
return buildProperty {
|
||||||
@@ -817,7 +851,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
fakeOverrideOwnerLookupTag = this,
|
fakeOverrideOwnerLookupTag = this,
|
||||||
getCachedIrDeclaration = ::getCachedIrProperty,
|
getCachedIrDeclaration = ::getCachedIrProperty,
|
||||||
createIrDeclaration = { parent, origin ->
|
createIrDeclaration = { parent, origin ->
|
||||||
callablesGenerator.createIrProperty(
|
createAndCacheIrProperty(
|
||||||
fir, parent, predefinedOrigin = origin, fakeOverrideOwnerLookupTag = fakeOverrideOwnerLookupTag,
|
fir, parent, predefinedOrigin = origin, fakeOverrideOwnerLookupTag = fakeOverrideOwnerLookupTag,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -1006,9 +1040,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
propertyCache[fir]?.let { return it.backingField!!.symbol }
|
propertyCache[fir]?.let { return it.backingField!!.symbol }
|
||||||
val irParent = findIrParent(fir)
|
val irParent = findIrParent(fir)
|
||||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||||
callablesGenerator.createIrProperty(fir, irParent, predefinedOrigin = parentOrigin).also {
|
createAndCacheIrProperty(fir, irParent, predefinedOrigin = parentOrigin).backingField!!.symbol
|
||||||
callablesGenerator.setAndModifyParent(it, irParent)
|
|
||||||
}.backingField!!.symbol
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
getIrVariableSymbol(fir)
|
getIrVariableSymbol(fir)
|
||||||
|
|||||||
+4
-5
@@ -295,11 +295,10 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
|||||||
firSubClass: FirClass,
|
firSubClass: FirClass,
|
||||||
firDelegateProperty: FirProperty
|
firDelegateProperty: FirProperty
|
||||||
): IrProperty {
|
): IrProperty {
|
||||||
val delegateProperty =
|
val delegateProperty = declarationStorage.getOrCreateIrProperty(
|
||||||
callablesGenerator.createIrProperty(
|
firDelegateProperty, subClass, predefinedOrigin = IrDeclarationOrigin.DELEGATED_MEMBER,
|
||||||
firDelegateProperty, subClass, predefinedOrigin = IrDeclarationOrigin.DELEGATED_MEMBER,
|
fakeOverrideOwnerLookupTag = firSubClass.symbol.toLookupTag()
|
||||||
fakeOverrideOwnerLookupTag = firSubClass.symbol.toLookupTag()
|
)
|
||||||
)
|
|
||||||
// the overridden symbols should be collected only after all fake overrides for all superclases are created and bound to their
|
// 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
|
// overridden symbols, otherwise in some cases they will be left in inconsistent state leading to the errors in IR
|
||||||
val baseSymbols = mutableListOf<FirPropertySymbol>()
|
val baseSymbols = mutableListOf<FirPropertySymbol>()
|
||||||
|
|||||||
+1
-1
@@ -150,7 +150,7 @@ class FakeOverrideGenerator(
|
|||||||
createFakeOverriddenIfNeeded(
|
createFakeOverriddenIfNeeded(
|
||||||
firClass, irClass, isLocal, propertyOrFieldSymbol,
|
firClass, irClass, isLocal, propertyOrFieldSymbol,
|
||||||
declarationStorage::getCachedIrProperty,
|
declarationStorage::getCachedIrProperty,
|
||||||
callablesGenerator::createIrProperty,
|
declarationStorage::getOrCreateIrProperty,
|
||||||
createFakeOverrideSymbol = { firProperty, callableSymbol ->
|
createFakeOverrideSymbol = { firProperty, callableSymbol ->
|
||||||
val symbolForOverride =
|
val symbolForOverride =
|
||||||
FirFakeOverrideGenerator.createSymbolForSubstitutionOverride(callableSymbol, firClass.symbol.classId)
|
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
|
this.backingField = backingField
|
||||||
}
|
}
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
@@ -684,9 +680,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||||
property.unwrapFakeOverrides().getter,
|
property.unwrapFakeOverrides().getter,
|
||||||
).also {
|
)
|
||||||
getterForPropertyCache[symbol] = it.symbol
|
|
||||||
}
|
|
||||||
if (property.isVar) {
|
if (property.isVar) {
|
||||||
this.setter = createIrPropertyAccessor(
|
this.setter = createIrPropertyAccessor(
|
||||||
setter, property, this, type, irParent, true,
|
setter, property, this, type, irParent, true,
|
||||||
@@ -700,23 +694,11 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||||
property.unwrapFakeOverrides().setter,
|
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
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user