[FIR2IR] Extract logic of IR declarations generation into separate component. Part 7
Move caching of created IrField back to Fir2IrDeclarationStorage
This commit is contained in:
committed by
Space Team
parent
b3efad5428
commit
8d9fa0fdde
+36
-5
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerAbiStability
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.getOrPut
|
||||
import org.jetbrains.kotlin.utils.threadLocal
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@@ -737,14 +736,29 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
}
|
||||
return callablesGenerator.createIrField(
|
||||
return createAndCacheIrField(
|
||||
field,
|
||||
irParent = irClass,
|
||||
type = initializer?.resolvedType ?: field.returnTypeRef.coneType,
|
||||
origin = IrDeclarationOrigin.DELEGATE
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Field(field)
|
||||
)
|
||||
}
|
||||
|
||||
private fun createAndCacheIrField(
|
||||
field: FirField,
|
||||
irParent: IrDeclarationParent?,
|
||||
type: ConeKotlinType = field.returnTypeRef.coneType,
|
||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
): IrField {
|
||||
val irField = callablesGenerator.createIrField(field, irParent, type, origin)
|
||||
val containingClassLookupTag = (irParent as IrClass?)?.classId?.toLookupTag()
|
||||
val staticFakeOverrideKey = getFieldStaticFakeOverrideKey(field, containingClassLookupTag)
|
||||
if (staticFakeOverrideKey == null) {
|
||||
fieldCache[field] = irField
|
||||
} else {
|
||||
fieldStaticOverrideCache[staticFakeOverrideKey] = irField
|
||||
}
|
||||
return irField
|
||||
}
|
||||
|
||||
// This function returns null if this field/ownerClassId combination does not describe static fake override
|
||||
@@ -1002,7 +1016,24 @@ class Fir2IrDeclarationStorage(
|
||||
if (unwrapped !== fir) {
|
||||
return getIrFieldSymbol(unwrapped.symbol)
|
||||
}
|
||||
return callablesGenerator.createIrField(fir, irParent).symbol
|
||||
return createAndCacheIrField(fir, irParent).symbol
|
||||
}
|
||||
|
||||
// TODO: there is a mess with methods for fields
|
||||
// we have three (!) different functions to getOrCreate field in different circumstances
|
||||
fun getOrCreateIrField(field: FirField, irParent: IrDeclarationParent?): IrField {
|
||||
getCachedIrField(field, irParent)?.let { return it }
|
||||
return createAndCacheIrField(field, irParent)
|
||||
}
|
||||
|
||||
private fun getCachedIrField(field: FirField, irParent: IrDeclarationParent?): IrField? {
|
||||
val containingClassLookupTag = (irParent as IrClass?)?.classId?.toLookupTag()
|
||||
val staticFakeOverrideKey = getFieldStaticFakeOverrideKey(field, containingClassLookupTag)
|
||||
return if (staticFakeOverrideKey == null) {
|
||||
fieldCache[field]
|
||||
} else {
|
||||
fieldStaticOverrideCache[staticFakeOverrideKey]
|
||||
}
|
||||
}
|
||||
|
||||
fun getIrBackingFieldSymbol(firBackingFieldSymbol: FirBackingFieldSymbol): IrSymbol {
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ class FakeOverrideGenerator(
|
||||
firClass, irClass, isLocal, propertyOrFieldSymbol,
|
||||
{ field, _, _ -> declarationStorage.getCachedIrFieldStaticFakeOverrideByDeclaration(field) },
|
||||
{ field, irParent, _, _ ->
|
||||
callablesGenerator.createIrField(field, irParent)
|
||||
declarationStorage.getOrCreateIrField(field, irParent)
|
||||
},
|
||||
createFakeOverrideSymbol = { firField, _ ->
|
||||
FirFakeOverrideGenerator.createSubstitutionOverrideField(
|
||||
|
||||
-6
@@ -774,12 +774,6 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
)
|
||||
}.apply {
|
||||
metadata = FirMetadataSource.Field(field)
|
||||
val staticFakeOverrideKey = getFieldStaticFakeOverrideKey(field, containingClassLookupTag)
|
||||
if (staticFakeOverrideKey == null) {
|
||||
fieldCache[field] = this
|
||||
} else {
|
||||
fieldStaticOverrideCache[staticFakeOverrideKey] = this
|
||||
}
|
||||
val initializer = field.unwrapFakeOverrides().initializer
|
||||
if (initializer is FirConstExpression<*>) {
|
||||
this.initializer = factory.createExpressionBody(initializer.toIrConst(irType))
|
||||
|
||||
Reference in New Issue
Block a user