IR: remove IrSimpleTypeBuilder.variance
IrCapturedType (which is a IrSimpleType) does not have variance, so it is confusing to have it in IrSimpleTypeBuilder, and it's clearer to construct type projection separately anyway.
This commit is contained in:
committed by
Space Team
parent
898d3aeea9
commit
8379e48e33
+5
-2
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.SimpleTypeNullability
|
||||
import org.jetbrains.kotlin.ir.types.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -516,7 +519,7 @@ class IrDescriptorBasedFunctionFactory(
|
||||
arguments = listOf(
|
||||
with(IrSimpleTypeBuilder()) {
|
||||
classifier = r.symbol
|
||||
buildTypeProjection()
|
||||
buildSimpleType()
|
||||
},
|
||||
)
|
||||
buildSimpleType()
|
||||
|
||||
@@ -89,7 +89,6 @@ class IrSimpleTypeBuilder {
|
||||
var arguments: List<IrTypeArgument> = emptyList()
|
||||
var annotations: List<IrConstructorCall> = emptyList()
|
||||
var abbreviation: IrTypeAbbreviation? = null
|
||||
var variance = Variance.INVARIANT
|
||||
}
|
||||
|
||||
fun IrSimpleType.toBuilder() =
|
||||
@@ -112,7 +111,7 @@ fun IrSimpleTypeBuilder.buildSimpleType() =
|
||||
abbreviation
|
||||
)
|
||||
|
||||
fun IrSimpleTypeBuilder.buildTypeProjection() =
|
||||
fun IrSimpleTypeBuilder.buildTypeProjection(variance: Variance): IrTypeProjection =
|
||||
if (variance == Variance.INVARIANT)
|
||||
buildSimpleType()
|
||||
else
|
||||
@@ -136,13 +135,12 @@ fun makeTypeProjection(type: IrType, variance: Variance): IrTypeProjection =
|
||||
when {
|
||||
type is IrCapturedType -> IrTypeProjectionImpl(type, variance)
|
||||
type is IrTypeProjection && type.variance == variance -> type
|
||||
type is IrSimpleType -> type.toBuilder().apply { this.variance = variance }.buildTypeProjection()
|
||||
type is IrSimpleType -> type.toBuilder().buildTypeProjection(variance)
|
||||
type is IrDynamicType -> IrDynamicTypeImpl(null, type.annotations, variance)
|
||||
type is IrErrorType -> IrErrorTypeImpl(null, type.annotations, variance)
|
||||
else -> IrTypeProjectionImpl(type, variance)
|
||||
}
|
||||
|
||||
|
||||
fun makeTypeIntersection(types: List<IrType>): IrType =
|
||||
with(types.map { makeTypeProjection(it, Variance.INVARIANT).type }.distinct()) {
|
||||
if (size == 1) return single()
|
||||
|
||||
@@ -126,7 +126,6 @@ abstract class TypeTranslator(
|
||||
return IrSimpleTypeBuilder().apply {
|
||||
this.kotlinType = approximatedType
|
||||
this.nullability = SimpleTypeNullability.fromHasQuestionMark(upperType.isMarkedNullable)
|
||||
this.variance = variance
|
||||
this.abbreviation = upperType.getAbbreviation()?.toIrTypeAbbreviation()
|
||||
|
||||
when (upperTypeDescriptor) {
|
||||
@@ -169,7 +168,7 @@ abstract class TypeTranslator(
|
||||
else ->
|
||||
throw AssertionError("Unexpected type descriptor $upperTypeDescriptor :: ${upperTypeDescriptor::class}")
|
||||
}
|
||||
}.buildTypeProjection()
|
||||
}.buildTypeProjection(variance)
|
||||
}
|
||||
|
||||
private fun approximateUpperBounds(upperBounds: Collection<KotlinType>, variance: Variance): IrTypeProjection {
|
||||
|
||||
+1
-1
@@ -212,7 +212,7 @@ class IrBodyDeserializer(
|
||||
val rawType = with(IrSimpleTypeBuilder()) {
|
||||
arguments = typeParameters.memoryOptimizedMap {
|
||||
classifier = it.symbol
|
||||
buildTypeProjection()
|
||||
buildSimpleType()
|
||||
}
|
||||
classifier = klass.symbol
|
||||
buildSimpleType()
|
||||
|
||||
Reference in New Issue
Block a user