[FIR2IR] Manage typealias symbols in declaration storage instead of declaration generator
This is needed to be able to implement creation of unbound symbols for references of corresponding declarations (KT-62856)
This commit is contained in:
committed by
Space Team
parent
d4b0627640
commit
10ad526936
+12
-5
@@ -21,12 +21,10 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
@@ -365,11 +363,20 @@ class Fir2IrClassifierStorage(
|
|||||||
typeAlias: FirTypeAlias,
|
typeAlias: FirTypeAlias,
|
||||||
parent: IrDeclarationParent
|
parent: IrDeclarationParent
|
||||||
): IrTypeAlias {
|
): IrTypeAlias {
|
||||||
return classifiersGenerator.createIrTypeAlias(typeAlias, parent).also {
|
val symbol = createTypeAliasSymbol(typeAlias)
|
||||||
|
return classifiersGenerator.createIrTypeAlias(typeAlias, parent, symbol).also {
|
||||||
typeAliasCache[typeAlias] = it
|
typeAliasCache[typeAlias] = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createTypeAliasSymbol(typeAlias: FirTypeAlias): IrTypeAliasSymbol {
|
||||||
|
val signature = signatureComposer.composeSignature(typeAlias)
|
||||||
|
return when {
|
||||||
|
signature != null -> symbolTable.referenceTypeAlias(signature)
|
||||||
|
else -> IrTypeAliasSymbolImpl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
||||||
|
|
||||||
// ------------------------------------ code fragments ------------------------------------
|
// ------------------------------------ code fragments ------------------------------------
|
||||||
|
|||||||
+17
-27
@@ -279,36 +279,26 @@ class Fir2IrClassifiersGenerator(val components: Fir2IrComponents) : Fir2IrCompo
|
|||||||
|
|
||||||
// ------------------------------------ typealiases ------------------------------------
|
// ------------------------------------ typealiases ------------------------------------
|
||||||
|
|
||||||
private fun declareIrTypeAlias(signature: IdSignature?, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias {
|
|
||||||
return if (signature == null)
|
|
||||||
factory(IrTypeAliasSymbolImpl())
|
|
||||||
else
|
|
||||||
symbolTable.declareTypeAlias(signature, { IrTypeAliasPublicSymbolImpl(signature) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createIrTypeAlias(
|
fun createIrTypeAlias(
|
||||||
typeAlias: FirTypeAlias,
|
typeAlias: FirTypeAlias,
|
||||||
parent: IrDeclarationParent
|
parent: IrDeclarationParent,
|
||||||
|
symbol: IrTypeAliasSymbol,
|
||||||
): IrTypeAlias = typeAlias.convertWithOffsets { startOffset, endOffset ->
|
): IrTypeAlias = typeAlias.convertWithOffsets { startOffset, endOffset ->
|
||||||
val signature = signatureComposer.composeSignature(typeAlias)
|
classifierStorage.preCacheTypeParameters(typeAlias, symbol)
|
||||||
declareIrTypeAlias(signature) { symbol ->
|
irFactory.createTypeAlias(
|
||||||
classifierStorage.preCacheTypeParameters(typeAlias, symbol)
|
startOffset = startOffset,
|
||||||
val irTypeAlias = irFactory.createTypeAlias(
|
endOffset = endOffset,
|
||||||
startOffset = startOffset,
|
origin = IrDeclarationOrigin.DEFINED,
|
||||||
endOffset = endOffset,
|
name = typeAlias.name,
|
||||||
origin = IrDeclarationOrigin.DEFINED,
|
visibility = components.visibilityConverter.convertToDescriptorVisibility(typeAlias.visibility),
|
||||||
name = typeAlias.name,
|
symbol = symbol,
|
||||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(typeAlias.visibility),
|
isActual = typeAlias.isActual,
|
||||||
symbol = symbol,
|
expandedType = typeAlias.expandedTypeRef.toIrType(),
|
||||||
isActual = typeAlias.isActual,
|
).apply {
|
||||||
expandedType = typeAlias.expandedTypeRef.toIrType(),
|
this.parent = parent
|
||||||
).apply {
|
setTypeParameters(this, typeAlias)
|
||||||
this.parent = parent
|
setParent(parent)
|
||||||
setTypeParameters(this, typeAlias)
|
addDeclarationToParent(this, parent)
|
||||||
setParent(parent)
|
|
||||||
addDeclarationToParent(this, parent)
|
|
||||||
}
|
|
||||||
irTypeAlias
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user