[FIR2IR] Part 3. Don't create type parameter symbols with signature
^KT-64990
This commit is contained in:
committed by
Space Team
parent
d0c9353d41
commit
e340286606
+6
-15
@@ -78,15 +78,15 @@ class Fir2IrClassifierStorage(
|
|||||||
// ------------------------------------ type parameters ------------------------------------
|
// ------------------------------------ type parameters ------------------------------------
|
||||||
|
|
||||||
// Note: declareTypeParameters should be called before!
|
// Note: declareTypeParameters should be called before!
|
||||||
internal fun preCacheTypeParameters(owner: FirTypeParameterRefsOwner, irOwnerSymbol: IrSymbol) {
|
internal fun preCacheTypeParameters(owner: FirTypeParameterRefsOwner) {
|
||||||
for ((index, typeParameter) in owner.typeParameters.withIndex()) {
|
for ((index, typeParameter) in owner.typeParameters.withIndex()) {
|
||||||
val original = typeParameter.symbol.fir
|
val original = typeParameter.symbol.fir
|
||||||
getCachedIrTypeParameter(original)
|
getCachedIrTypeParameter(original)
|
||||||
?: createAndCacheIrTypeParameter(original, index, irOwnerSymbol)
|
?: createAndCacheIrTypeParameter(original, index)
|
||||||
if (owner is FirProperty && owner.isVar) {
|
if (owner is FirProperty && owner.isVar) {
|
||||||
val context = ConversionTypeOrigin.SETTER
|
val context = ConversionTypeOrigin.SETTER
|
||||||
getCachedIrTypeParameter(original, context)
|
getCachedIrTypeParameter(original, context)
|
||||||
?: createAndCacheIrTypeParameter(original, index, irOwnerSymbol, context)
|
?: createAndCacheIrTypeParameter(original, index, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,11 +94,10 @@ class Fir2IrClassifierStorage(
|
|||||||
internal fun getIrTypeParameter(
|
internal fun getIrTypeParameter(
|
||||||
typeParameter: FirTypeParameter,
|
typeParameter: FirTypeParameter,
|
||||||
index: Int,
|
index: Int,
|
||||||
ownerSymbol: IrSymbol,
|
|
||||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
getCachedIrTypeParameter(typeParameter, typeOrigin)?.let { return it }
|
getCachedIrTypeParameter(typeParameter, typeOrigin)?.let { return it }
|
||||||
val irTypeParameter = createAndCacheIrTypeParameter(typeParameter, index, ownerSymbol, typeOrigin)
|
val irTypeParameter = createAndCacheIrTypeParameter(typeParameter, index, typeOrigin)
|
||||||
classifiersGenerator.initializeTypeParameterBounds(typeParameter, irTypeParameter)
|
classifiersGenerator.initializeTypeParameterBounds(typeParameter, irTypeParameter)
|
||||||
return irTypeParameter
|
return irTypeParameter
|
||||||
}
|
}
|
||||||
@@ -106,10 +105,9 @@ class Fir2IrClassifierStorage(
|
|||||||
private fun createAndCacheIrTypeParameter(
|
private fun createAndCacheIrTypeParameter(
|
||||||
typeParameter: FirTypeParameter,
|
typeParameter: FirTypeParameter,
|
||||||
index: Int,
|
index: Int,
|
||||||
ownerSymbol: IrSymbol,
|
|
||||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
val symbol = createTypeParameterSymbol(ownerSymbol, index)
|
val symbol = IrTypeParameterSymbolImpl()
|
||||||
val irTypeParameter = classifiersGenerator.createIrTypeParameterWithoutBounds(typeParameter, index, symbol)
|
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) {
|
||||||
@@ -120,13 +118,6 @@ 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
|
||||||
@@ -165,7 +156,7 @@ class Fir2IrClassifierStorage(
|
|||||||
val isSetter = firTypeParameterOwner is FirPropertyAccessor && firTypeParameterOwner.isSetter
|
val isSetter = firTypeParameterOwner is FirPropertyAccessor && firTypeParameterOwner.isSetter
|
||||||
val conversionTypeOrigin = if (isSetter) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
val conversionTypeOrigin = if (isSetter) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
||||||
|
|
||||||
return createAndCacheIrTypeParameter(firTypeParameter, index, IrTypeParameterSymbolImpl(), conversionTypeOrigin).also {
|
return createAndCacheIrTypeParameter(firTypeParameter, index, conversionTypeOrigin).also {
|
||||||
classifiersGenerator.initializeTypeParameterBounds(firTypeParameter, it)
|
classifiersGenerator.initializeTypeParameterBounds(firTypeParameter, it)
|
||||||
}.symbol
|
}.symbol
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -111,7 +111,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendOrKSuspendFunctionType(session) == true
|
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendOrKSuspendFunctionType(session) == true
|
||||||
else function.isSuspend
|
else function.isSuspend
|
||||||
val created = function.convertWithOffsets { startOffset, endOffset ->
|
val created = function.convertWithOffsets { startOffset, endOffset ->
|
||||||
classifierStorage.preCacheTypeParameters(function, symbol)
|
classifierStorage.preCacheTypeParameters(function)
|
||||||
irFactory.createSimpleFunction(
|
irFactory.createSimpleFunction(
|
||||||
startOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else startOffset,
|
startOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else startOffset,
|
||||||
endOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else endOffset,
|
endOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else endOffset,
|
||||||
@@ -186,7 +186,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
}
|
}
|
||||||
val visibility = if (irParent.isAnonymousObject) Visibilities.Public else constructor.visibility
|
val visibility = if (irParent.isAnonymousObject) Visibilities.Public else constructor.visibility
|
||||||
return constructor.convertWithOffsets { startOffset, endOffset ->
|
return constructor.convertWithOffsets { startOffset, endOffset ->
|
||||||
classifierStorage.preCacheTypeParameters(constructor, symbol)
|
classifierStorage.preCacheTypeParameters(constructor)
|
||||||
irFactory.createConstructor(
|
irFactory.createConstructor(
|
||||||
startOffset = startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = endOffset,
|
endOffset = endOffset,
|
||||||
@@ -245,7 +245,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
return lazyDeclarationsGenerator.createIrLazyProperty(property, irParent!!, symbols, origin)
|
return lazyDeclarationsGenerator.createIrLazyProperty(property, irParent!!, symbols, origin)
|
||||||
}
|
}
|
||||||
return property.convertWithOffsets { startOffset, endOffset ->
|
return property.convertWithOffsets { startOffset, endOffset ->
|
||||||
classifierStorage.preCacheTypeParameters(property, symbols.propertySymbol)
|
classifierStorage.preCacheTypeParameters(property)
|
||||||
irFactory.createProperty(
|
irFactory.createProperty(
|
||||||
startOffset = startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = endOffset,
|
endOffset = endOffset,
|
||||||
@@ -275,7 +275,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
|||||||
if (delegate != null || property.hasBackingField) {
|
if (delegate != null || property.hasBackingField) {
|
||||||
val backingField = if (delegate != null) {
|
val backingField = if (delegate != null) {
|
||||||
((delegate as? FirQualifiedAccessExpression)?.calleeReference?.toResolvedBaseSymbol()?.fir as? FirTypeParameterRefsOwner)?.let {
|
((delegate as? FirQualifiedAccessExpression)?.calleeReference?.toResolvedBaseSymbol()?.fir as? FirTypeParameterRefsOwner)?.let {
|
||||||
classifierStorage.preCacheTypeParameters(it, symbol)
|
classifierStorage.preCacheTypeParameters(it)
|
||||||
}
|
}
|
||||||
createBackingField(
|
createBackingField(
|
||||||
this,
|
this,
|
||||||
|
|||||||
+3
-3
@@ -121,7 +121,7 @@ class Fir2IrClassifiersGenerator(val components: Fir2IrComponents) : Fir2IrCompo
|
|||||||
// `irClass` is a source class and definitely is not a lazy class
|
// `irClass` is a source class and definitely is not a lazy class
|
||||||
@OptIn(UnsafeDuringIrConstructionAPI::class)
|
@OptIn(UnsafeDuringIrConstructionAPI::class)
|
||||||
private fun IrClass.declareTypeParameters(klass: FirClass) {
|
private fun IrClass.declareTypeParameters(klass: FirClass) {
|
||||||
classifierStorage.preCacheTypeParameters(klass, symbol)
|
classifierStorage.preCacheTypeParameters(klass)
|
||||||
setTypeParameters(this, klass)
|
setTypeParameters(this, klass)
|
||||||
if (klass is FirRegularClass) {
|
if (klass is FirRegularClass) {
|
||||||
val fieldsForContextReceiversOfCurrentClass = classifierStorage.getFieldsWithContextReceiversForClass(this, klass)
|
val fieldsForContextReceiversOfCurrentClass = classifierStorage.getFieldsWithContextReceiversForClass(this, klass)
|
||||||
@@ -285,7 +285,7 @@ class Fir2IrClassifiersGenerator(val components: Fir2IrComponents) : Fir2IrCompo
|
|||||||
parent: IrDeclarationParent,
|
parent: IrDeclarationParent,
|
||||||
symbol: IrTypeAliasSymbol,
|
symbol: IrTypeAliasSymbol,
|
||||||
): IrTypeAlias = typeAlias.convertWithOffsets { startOffset, endOffset ->
|
): IrTypeAlias = typeAlias.convertWithOffsets { startOffset, endOffset ->
|
||||||
classifierStorage.preCacheTypeParameters(typeAlias, symbol)
|
classifierStorage.preCacheTypeParameters(typeAlias)
|
||||||
irFactory.createTypeAlias(
|
irFactory.createTypeAlias(
|
||||||
startOffset = startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = endOffset,
|
endOffset = endOffset,
|
||||||
@@ -389,7 +389,7 @@ class Fir2IrClassifiersGenerator(val components: Fir2IrComponents) : Fir2IrCompo
|
|||||||
) {
|
) {
|
||||||
irOwner.typeParameters = owner.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
irOwner.typeParameters = owner.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||||
classifierStorage.getIrTypeParameter(typeParameter, index, irOwner.symbol, typeOrigin).apply {
|
classifierStorage.getIrTypeParameter(typeParameter, index, typeOrigin).apply {
|
||||||
parent = irOwner
|
parent = irOwner
|
||||||
if (superTypes.isEmpty()) {
|
if (superTypes.isEmpty()) {
|
||||||
superTypes = typeParameter.bounds.map { it.toIrType(typeOrigin) }
|
superTypes = typeParameter.bounds.map { it.toIrType(typeOrigin) }
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class Fir2IrLazyClass(
|
|||||||
IrMaybeDeserializedClass, DeserializableClass, Fir2IrComponents by components {
|
IrMaybeDeserializedClass, DeserializableClass, Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir, symbol)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Fir2IrLazyConstructor(
|
|||||||
Fir2IrComponents by components {
|
Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir, symbol)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Fir2IrLazyProperty(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir, symbol)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class Fir2IrLazySimpleFunction(
|
|||||||
) : AbstractFir2IrLazyFunction<FirSimpleFunction>(components, startOffset, endOffset, origin, symbol, parent, isFakeOverride) {
|
) : AbstractFir2IrLazyFunction<FirSimpleFunction>(components, startOffset, endOffset, origin, symbol, parent, isFakeOverride) {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir, symbol)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Fir2IrLazyTypeAlias(
|
|||||||
) : IrTypeAlias(), AbstractFir2IrLazyDeclaration<FirTypeAlias>, Fir2IrTypeParametersContainer, Fir2IrComponents by components {
|
) : IrTypeAlias(), AbstractFir2IrLazyDeclaration<FirTypeAlias>, Fir2IrTypeParametersContainer, Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir, symbol)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ interface Fir2IrTypeParametersContainer : IrTypeParametersContainer, Fir2IrCompo
|
|||||||
fun prepareTypeParameters() {
|
fun prepareTypeParameters() {
|
||||||
typeParameters = fir.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
typeParameters = fir.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||||
classifierStorage.getIrTypeParameter(typeParameter, index, symbol).apply {
|
classifierStorage.getIrTypeParameter(typeParameter, index).apply {
|
||||||
parent = this@Fir2IrTypeParametersContainer
|
parent = this@Fir2IrTypeParametersContainer
|
||||||
if (superTypes.isEmpty()) {
|
if (superTypes.isEmpty()) {
|
||||||
superTypes = typeParameter.bounds.map { it.toIrType(typeConverter) }
|
superTypes = typeParameter.bounds.map { it.toIrType(typeConverter) }
|
||||||
|
|||||||
Reference in New Issue
Block a user