[FIR2IR] Manage type parameter 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
36c0ed3c9e
commit
78259e3ee0
+10
-1
@@ -21,6 +21,7 @@ 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.IrClassifierSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
@@ -93,7 +94,8 @@ class Fir2IrClassifierStorage(
|
|||||||
ownerSymbol: IrSymbol,
|
ownerSymbol: IrSymbol,
|
||||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
val irTypeParameter = classifiersGenerator.createIrTypeParameterWithoutBounds(typeParameter, index, ownerSymbol)
|
val symbol = createTypeParameterSymbol(ownerSymbol, index)
|
||||||
|
val irTypeParameter = classifiersGenerator.createIrTypeParameterWithoutBounds(typeParameter, index, symbol)
|
||||||
// Cache the type parameter BEFORE processing its bounds/supertypes, to properly handle recursive type bounds.
|
// Cache the type parameter BEFORE processing its bounds/supertypes, to properly handle recursive type bounds.
|
||||||
if (typeOrigin.forSetter) {
|
if (typeOrigin.forSetter) {
|
||||||
typeParameterCacheForSetter[typeParameter] = irTypeParameter
|
typeParameterCacheForSetter[typeParameter] = irTypeParameter
|
||||||
@@ -103,6 +105,13 @@ class Fir2IrClassifierStorage(
|
|||||||
return irTypeParameter
|
return irTypeParameter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createTypeParameterSymbol(ownerSymbol: IrSymbol, index: Int): IrTypeParameterSymbol {
|
||||||
|
if (ownerSymbol !is IrClassifierSymbol) return IrTypeParameterSymbolImpl()
|
||||||
|
val signature = signatureComposer.composeTypeParameterSignature(index, ownerSymbol.signature)
|
||||||
|
?: return IrTypeParameterSymbolImpl()
|
||||||
|
return symbolTable.referenceTypeParameter(signature)
|
||||||
|
}
|
||||||
|
|
||||||
internal fun getCachedIrTypeParameter(
|
internal fun getCachedIrTypeParameter(
|
||||||
typeParameter: FirTypeParameter,
|
typeParameter: FirTypeParameter,
|
||||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||||
|
|||||||
+12
-51
@@ -36,60 +36,21 @@ class Fir2IrClassifiersGenerator(val components: Fir2IrComponents) : Fir2IrCompo
|
|||||||
fun createIrTypeParameterWithoutBounds(
|
fun createIrTypeParameterWithoutBounds(
|
||||||
typeParameter: FirTypeParameter,
|
typeParameter: FirTypeParameter,
|
||||||
index: Int,
|
index: Int,
|
||||||
ownerSymbol: IrSymbol,
|
symbol: IrTypeParameterSymbol
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
require(index >= 0)
|
require(index >= 0)
|
||||||
val origin = typeParameter.computeIrOrigin()
|
val origin = typeParameter.computeIrOrigin()
|
||||||
val irTypeParameter = with(typeParameter) {
|
val irTypeParameter = typeParameter.convertWithOffsets { startOffset, endOffset ->
|
||||||
convertWithOffsets { startOffset, endOffset ->
|
irFactory.createTypeParameter(
|
||||||
signatureComposer.composeTypeParameterSignature(
|
startOffset = startOffset,
|
||||||
index, ownerSymbol.signature
|
endOffset = endOffset,
|
||||||
)?.let { signature ->
|
origin = origin,
|
||||||
if (ownerSymbol is IrClassifierSymbol) {
|
name = typeParameter.name,
|
||||||
symbolTable.declareGlobalTypeParameter(
|
symbol = symbol,
|
||||||
signature,
|
variance = typeParameter.variance,
|
||||||
symbolFactory = { IrTypeParameterPublicSymbolImpl(signature) }
|
index = index,
|
||||||
) { symbol ->
|
isReified = typeParameter.isReified,
|
||||||
irFactory.createTypeParameter(
|
)
|
||||||
startOffset = startOffset,
|
|
||||||
endOffset = endOffset,
|
|
||||||
origin = origin,
|
|
||||||
name = name,
|
|
||||||
symbol = symbol,
|
|
||||||
variance = variance,
|
|
||||||
index = index,
|
|
||||||
isReified = isReified,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
symbolTable.declareScopedTypeParameter(
|
|
||||||
signature,
|
|
||||||
symbolFactory = { IrTypeParameterPublicSymbolImpl(signature) }
|
|
||||||
) { symbol ->
|
|
||||||
irFactory.createTypeParameter(
|
|
||||||
startOffset = startOffset,
|
|
||||||
endOffset = endOffset,
|
|
||||||
origin = origin,
|
|
||||||
name = name,
|
|
||||||
symbol = symbol,
|
|
||||||
variance = variance,
|
|
||||||
index = index,
|
|
||||||
isReified = isReified,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} ?: irFactory.createTypeParameter(
|
|
||||||
startOffset = startOffset,
|
|
||||||
endOffset = endOffset,
|
|
||||||
origin = origin,
|
|
||||||
name = name,
|
|
||||||
symbol = IrTypeParameterSymbolImpl(),
|
|
||||||
variance = variance,
|
|
||||||
index = index,
|
|
||||||
isReified = isReified,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
annotationGenerator.generate(irTypeParameter, typeParameter)
|
annotationGenerator.generate(irTypeParameter, typeParameter)
|
||||||
return irTypeParameter
|
return irTypeParameter
|
||||||
|
|||||||
Reference in New Issue
Block a user