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