IR: make IrTypeParameter.superTypes persistent mutable field
This commit is contained in:
@@ -111,7 +111,7 @@ class Fir2IrClassifierStorage(
|
||||
getIrTypeParameter(typeParameter, index, typeContext).apply {
|
||||
parent = this@setTypeParameters
|
||||
if (superTypes.isEmpty()) {
|
||||
typeParameter.bounds.mapTo(superTypes) { it.toIrType() }
|
||||
superTypes = typeParameter.bounds.map { it.toIrType() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,7 +369,7 @@ class Fir2IrClassifierStorage(
|
||||
getCachedIrTypeParameter(typeParameter, index, typeContext)?.let { return it }
|
||||
return typeParameter.run {
|
||||
val irTypeParameter = createIrTypeParameterWithoutBounds(typeParameter, index, typeContext)
|
||||
bounds.mapTo(irTypeParameter.superTypes) { it.toIrType() }
|
||||
irTypeParameter.superTypes = bounds.map { it.toIrType() }
|
||||
irTypeParameter
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ interface AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSymbolOw
|
||||
classifierStorage.getIrTypeParameter(typeParameter, index).apply {
|
||||
parent = this@AbstractFir2IrLazyDeclaration
|
||||
if (superTypes.isEmpty()) {
|
||||
typeParameter.bounds.mapTo(superTypes) { it.toIrType(typeConverter) }
|
||||
superTypes = typeParameter.bounds.map { it.toIrType(typeConverter) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,8 +224,8 @@ private fun IrTypeParameter.copySuperTypesFrom(source: IrTypeParameter, srcToDst
|
||||
val target = this
|
||||
val sourceParent = source.parent as IrTypeParametersContainer
|
||||
val targetParent = target.parent as IrTypeParametersContainer
|
||||
source.superTypes.forEach {
|
||||
target.superTypes.add(it.remapTypeParameters(sourceParent, targetParent, srcToDstParameterMap))
|
||||
target.superTypes += source.superTypes.map {
|
||||
it.remapTypeParameters(sourceParent, targetParent, srcToDstParameterMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ fun IrFactory.createStaticFunctionWithReceivers(
|
||||
fun remap(type: IrType): IrType =
|
||||
type.remapTypeParameters(oldFunction, this, typeParameterMap)
|
||||
|
||||
typeParameters.forEach { it.superTypes.replaceAll { remap(it) } }
|
||||
typeParameters.forEach { it.superTypes = it.superTypes.map(::remap) }
|
||||
|
||||
annotations = oldFunction.annotations
|
||||
|
||||
|
||||
+1
-1
@@ -610,7 +610,7 @@ class LocalDeclarationsLowering(
|
||||
newDeclaration.copyTypeParametersFrom(oldDeclaration, parameterMap = localFunctionContext.capturedTypeParameterToTypeParameter)
|
||||
// Type parameters of oldDeclaration may depend on captured type parameters, so deal with that after copying.
|
||||
newDeclaration.typeParameters.drop(newTypeParameters.size).forEach { tp ->
|
||||
tp.superTypes.replaceAll { localFunctionContext.remapType(it) }
|
||||
tp.superTypes = tp.superTypes.map { localFunctionContext.remapType(it) }
|
||||
}
|
||||
|
||||
newDeclaration.parent = memberOwner
|
||||
|
||||
+1
-1
@@ -291,7 +291,7 @@ internal fun IrFactory.buildTypeParameter(builder: IrTypeParameterBuilder, paren
|
||||
name, index, isReified, variance
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
it.superTypes.addAll(superTypes)
|
||||
it.superTypes = superTypes
|
||||
it.parent = parent
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
}
|
||||
|
||||
for (irTypeParameter in irTypeParametersOwner.typeParameters) {
|
||||
irTypeParameter.descriptor.upperBounds.mapTo(irTypeParameter.superTypes) {
|
||||
irTypeParameter.superTypes = irTypeParameter.descriptor.upperBounds.map {
|
||||
it.toIrType()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
|
||||
}
|
||||
|
||||
for (irTypeParameter in irTypeParametersOwner.typeParameters) {
|
||||
irTypeParameter.descriptor.upperBounds.mapTo(irTypeParameter.superTypes) {
|
||||
irTypeParameter.superTypes = irTypeParameter.descriptor.upperBounds.map {
|
||||
it.toIrType()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -53,5 +53,5 @@ class IrTypeParameterImpl(
|
||||
override val descriptor: TypeParameterDescriptor
|
||||
get() = symbol.descriptor
|
||||
|
||||
override val superTypes: MutableList<IrType> = SmartList()
|
||||
override var superTypes: List<IrType> = emptyList()
|
||||
}
|
||||
|
||||
+9
-1
@@ -62,5 +62,13 @@ internal class PersistentIrTypeParameter(
|
||||
override val descriptor: TypeParameterDescriptor
|
||||
get() = symbol.descriptor
|
||||
|
||||
override val superTypes: MutableList<IrType> = SmartList()
|
||||
override var superTypesField: List<IrType> = emptyList()
|
||||
|
||||
override var superTypes: List<IrType>
|
||||
get() = getCarrier().superTypesField
|
||||
set(v) {
|
||||
if (superTypes !== v) {
|
||||
setCarrier().superTypesField = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -8,10 +8,13 @@ package org.jetbrains.kotlin.ir.declarations.persistent.carriers
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
|
||||
internal interface TypeParameterCarrier : DeclarationCarrier {
|
||||
var superTypesField: List<IrType>
|
||||
|
||||
override fun clone(): TypeParameterCarrier {
|
||||
return TypeParameterCarrierImpl(lastModified, parentField, originField, annotationsField)
|
||||
return TypeParameterCarrierImpl(lastModified, parentField, originField, annotationsField, superTypesField)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,5 +22,6 @@ internal class TypeParameterCarrierImpl(
|
||||
override val lastModified: Int,
|
||||
override var parentField: IrDeclarationParent?,
|
||||
override var originField: IrDeclarationOrigin,
|
||||
override var annotationsField: List<IrConstructorCall>
|
||||
override var annotationsField: List<IrConstructorCall>,
|
||||
override var superTypesField: List<IrType>,
|
||||
) : TypeParameterCarrier
|
||||
|
||||
@@ -31,7 +31,7 @@ abstract class IrTypeParameter : IrDeclarationBase(), IrSymbolDeclaration<IrType
|
||||
abstract val variance: Variance
|
||||
abstract val index: Int
|
||||
abstract val isReified: Boolean
|
||||
abstract val superTypes: MutableList<IrType>
|
||||
abstract var superTypes: List<IrType>
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeParameter(this, data)
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class IrLazyTypeParameter(
|
||||
|
||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||
|
||||
override val superTypes: MutableList<IrType> by lazy {
|
||||
override var superTypes: List<IrType> by lazyVar {
|
||||
withInitialIr {
|
||||
typeTranslator.buildWithScope(this.parent as IrTypeParametersContainer) {
|
||||
val descriptor = symbol.descriptor
|
||||
|
||||
@@ -308,7 +308,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
override fun visitTypeParameter(declaration: IrTypeParameter): IrTypeParameter =
|
||||
copyTypeParameter(declaration).apply {
|
||||
// TODO type parameter scopes?
|
||||
declaration.superTypes.mapTo(superTypes) { it.remapType() }
|
||||
superTypes = declaration.superTypes.map { it.remapType() }
|
||||
}
|
||||
|
||||
private fun copyTypeParameter(declaration: IrTypeParameter): IrTypeParameter =
|
||||
@@ -331,7 +331,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
|
||||
typeRemapper.withinScope(this) {
|
||||
for ((thisTypeParameter, otherTypeParameter) in this.typeParameters.zip(other.typeParameters)) {
|
||||
otherTypeParameter.superTypes.mapTo(thisTypeParameter.superTypes) {
|
||||
thisTypeParameter.superTypes = otherTypeParameter.superTypes.map {
|
||||
typeRemapper.remapType(it)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1090,7 +1090,7 @@ abstract class IrFileDeserializer(
|
||||
}
|
||||
|
||||
for (i in protos.indices) {
|
||||
protos[i].superTypeList.mapTo(result[i].superTypes) { deserializeIrType(it) }
|
||||
result[i].superTypes = protos[i].superTypeList.map { deserializeIrType(it) }
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
+1
-1
@@ -416,7 +416,7 @@ interface IrBuilderExtension {
|
||||
}
|
||||
|
||||
newTypeParameters.forEach { typeParameter ->
|
||||
typeParameter.superTypes.addAll(typeParameter.descriptor.upperBounds.map { it.toIrType() })
|
||||
typeParameter.superTypes = typeParameter.descriptor.upperBounds.map { it.toIrType() }
|
||||
}
|
||||
|
||||
typeParameters = newTypeParameters
|
||||
|
||||
Reference in New Issue
Block a user