[FIR2IR] Part 5. Cleanup Fir2IrClassifierStorage API (type aliases)
This commit is contained in:
committed by
Space Team
parent
fb4b14e250
commit
aba1e587c4
+12
-8
@@ -35,7 +35,7 @@ class Fir2IrClassifierStorage(
|
|||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
private val classCache: MutableMap<FirRegularClass, IrClassSymbol> = commonMemberStorage.classCache
|
private val classCache: MutableMap<FirRegularClass, IrClassSymbol> = commonMemberStorage.classCache
|
||||||
|
|
||||||
private val typeAliasCache: MutableMap<FirTypeAlias, IrTypeAlias> = mutableMapOf()
|
private val typeAliasCache: MutableMap<FirTypeAlias, IrTypeAliasSymbol> = mutableMapOf()
|
||||||
|
|
||||||
private val typeParameterCache: MutableMap<FirTypeParameter, IrTypeParameter> = commonMemberStorage.typeParameterCache
|
private val typeParameterCache: MutableMap<FirTypeParameter, IrTypeParameter> = commonMemberStorage.typeParameterCache
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ class Fir2IrClassifierStorage(
|
|||||||
@DelicateDeclarationStorageApi
|
@DelicateDeclarationStorageApi
|
||||||
fun forEachCachedDeclarationSymbol(block: (IrSymbol) -> Unit) {
|
fun forEachCachedDeclarationSymbol(block: (IrSymbol) -> Unit) {
|
||||||
classCache.values.forEach { block(it) }
|
classCache.values.forEach { block(it) }
|
||||||
typeAliasCache.values.forEach { block(it.symbol) }
|
typeAliasCache.values.forEach { block(it) }
|
||||||
enumEntryCache.values.forEach { block(it) }
|
enumEntryCache.values.forEach { block(it) }
|
||||||
fieldsForContextReceivers.values.forEach { fields ->
|
fieldsForContextReceivers.values.forEach { fields ->
|
||||||
fields.forEach { block(it.symbol) }
|
fields.forEach { block(it.symbol) }
|
||||||
@@ -381,15 +381,19 @@ class Fir2IrClassifierStorage(
|
|||||||
): IrTypeAlias {
|
): IrTypeAlias {
|
||||||
val symbol = IrTypeAliasSymbolImpl()
|
val symbol = IrTypeAliasSymbolImpl()
|
||||||
return classifiersGenerator.createIrTypeAlias(typeAlias, parent, symbol).also {
|
return classifiersGenerator.createIrTypeAlias(typeAlias, parent, symbol).also {
|
||||||
typeAliasCache[typeAlias] = it
|
typeAliasCache[typeAlias] = symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? {
|
||||||
|
// Type alias should be created at this point
|
||||||
|
@OptIn(UnsafeDuringIrConstructionAPI::class)
|
||||||
|
return typeAliasCache[firTypeAlias]?.owner
|
||||||
|
}
|
||||||
|
|
||||||
fun referenceTypeAlias(firTypeAliasSymbol: FirTypeAliasSymbol): IrTypeAlias {
|
fun getIrTypeAliasSymbol(firTypeAliasSymbol: FirTypeAliasSymbol): IrTypeAliasSymbol {
|
||||||
val firTypeAlias = firTypeAliasSymbol.fir
|
val firTypeAlias = firTypeAliasSymbol.fir
|
||||||
classifierStorage.getCachedTypeAlias(firTypeAlias)?.let { return it }
|
getCachedTypeAlias(firTypeAlias)?.let { return it.symbol }
|
||||||
|
|
||||||
val typeAliasId = firTypeAliasSymbol.classId
|
val typeAliasId = firTypeAliasSymbol.classId
|
||||||
val parentId = typeAliasId.outerClassId
|
val parentId = typeAliasId.outerClassId
|
||||||
@@ -403,10 +407,10 @@ class Fir2IrClassifierStorage(
|
|||||||
|
|
||||||
val symbol = IrTypeAliasSymbolImpl()
|
val symbol = IrTypeAliasSymbolImpl()
|
||||||
val irTypeAlias = lazyDeclarationsGenerator.createIrLazyTypeAlias(firTypeAlias, irParent, symbol)
|
val irTypeAlias = lazyDeclarationsGenerator.createIrLazyTypeAlias(firTypeAlias, irParent, symbol)
|
||||||
typeAliasCache[firTypeAlias] = irTypeAlias
|
typeAliasCache[firTypeAlias] = symbol
|
||||||
irTypeAlias.prepareTypeParameters()
|
irTypeAlias.prepareTypeParameters()
|
||||||
|
|
||||||
return irTypeAlias
|
return symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------ code fragments ------------------------------------
|
// ------------------------------------ code fragments ------------------------------------
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Fir2IrPluginContext(
|
|||||||
|
|
||||||
override fun referenceTypeAlias(classId: ClassId): IrTypeAliasSymbol? {
|
override fun referenceTypeAlias(classId: ClassId): IrTypeAliasSymbol? {
|
||||||
val firSymbol = symbolProvider.getClassLikeSymbolByClassId(classId) as? FirTypeAliasSymbol ?: return null
|
val firSymbol = symbolProvider.getClassLikeSymbolByClassId(classId) as? FirTypeAliasSymbol ?: return null
|
||||||
return components.classifierStorage.referenceTypeAlias(firSymbol).symbol
|
return components.classifierStorage.getIrTypeAliasSymbol(firSymbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun referenceConstructors(classId: ClassId): Collection<IrConstructorSymbol> {
|
override fun referenceConstructors(classId: ClassId): Collection<IrConstructorSymbol> {
|
||||||
|
|||||||
Reference in New Issue
Block a user