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.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.SimpleTypeNullability
|
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.ir.util.*
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -516,7 +519,7 @@ class IrDescriptorBasedFunctionFactory(
|
|||||||
arguments = listOf(
|
arguments = listOf(
|
||||||
with(IrSimpleTypeBuilder()) {
|
with(IrSimpleTypeBuilder()) {
|
||||||
classifier = r.symbol
|
classifier = r.symbol
|
||||||
buildTypeProjection()
|
buildSimpleType()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
buildSimpleType()
|
buildSimpleType()
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ class IrSimpleTypeBuilder {
|
|||||||
var arguments: List<IrTypeArgument> = emptyList()
|
var arguments: List<IrTypeArgument> = emptyList()
|
||||||
var annotations: List<IrConstructorCall> = emptyList()
|
var annotations: List<IrConstructorCall> = emptyList()
|
||||||
var abbreviation: IrTypeAbbreviation? = null
|
var abbreviation: IrTypeAbbreviation? = null
|
||||||
var variance = Variance.INVARIANT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrSimpleType.toBuilder() =
|
fun IrSimpleType.toBuilder() =
|
||||||
@@ -112,7 +111,7 @@ fun IrSimpleTypeBuilder.buildSimpleType() =
|
|||||||
abbreviation
|
abbreviation
|
||||||
)
|
)
|
||||||
|
|
||||||
fun IrSimpleTypeBuilder.buildTypeProjection() =
|
fun IrSimpleTypeBuilder.buildTypeProjection(variance: Variance): IrTypeProjection =
|
||||||
if (variance == Variance.INVARIANT)
|
if (variance == Variance.INVARIANT)
|
||||||
buildSimpleType()
|
buildSimpleType()
|
||||||
else
|
else
|
||||||
@@ -136,13 +135,12 @@ fun makeTypeProjection(type: IrType, variance: Variance): IrTypeProjection =
|
|||||||
when {
|
when {
|
||||||
type is IrCapturedType -> IrTypeProjectionImpl(type, variance)
|
type is IrCapturedType -> IrTypeProjectionImpl(type, variance)
|
||||||
type is IrTypeProjection && type.variance == variance -> type
|
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 IrDynamicType -> IrDynamicTypeImpl(null, type.annotations, variance)
|
||||||
type is IrErrorType -> IrErrorTypeImpl(null, type.annotations, variance)
|
type is IrErrorType -> IrErrorTypeImpl(null, type.annotations, variance)
|
||||||
else -> IrTypeProjectionImpl(type, variance)
|
else -> IrTypeProjectionImpl(type, variance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun makeTypeIntersection(types: List<IrType>): IrType =
|
fun makeTypeIntersection(types: List<IrType>): IrType =
|
||||||
with(types.map { makeTypeProjection(it, Variance.INVARIANT).type }.distinct()) {
|
with(types.map { makeTypeProjection(it, Variance.INVARIANT).type }.distinct()) {
|
||||||
if (size == 1) return single()
|
if (size == 1) return single()
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ abstract class TypeTranslator(
|
|||||||
return IrSimpleTypeBuilder().apply {
|
return IrSimpleTypeBuilder().apply {
|
||||||
this.kotlinType = approximatedType
|
this.kotlinType = approximatedType
|
||||||
this.nullability = SimpleTypeNullability.fromHasQuestionMark(upperType.isMarkedNullable)
|
this.nullability = SimpleTypeNullability.fromHasQuestionMark(upperType.isMarkedNullable)
|
||||||
this.variance = variance
|
|
||||||
this.abbreviation = upperType.getAbbreviation()?.toIrTypeAbbreviation()
|
this.abbreviation = upperType.getAbbreviation()?.toIrTypeAbbreviation()
|
||||||
|
|
||||||
when (upperTypeDescriptor) {
|
when (upperTypeDescriptor) {
|
||||||
@@ -169,7 +168,7 @@ abstract class TypeTranslator(
|
|||||||
else ->
|
else ->
|
||||||
throw AssertionError("Unexpected type descriptor $upperTypeDescriptor :: ${upperTypeDescriptor::class}")
|
throw AssertionError("Unexpected type descriptor $upperTypeDescriptor :: ${upperTypeDescriptor::class}")
|
||||||
}
|
}
|
||||||
}.buildTypeProjection()
|
}.buildTypeProjection(variance)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun approximateUpperBounds(upperBounds: Collection<KotlinType>, variance: Variance): IrTypeProjection {
|
private fun approximateUpperBounds(upperBounds: Collection<KotlinType>, variance: Variance): IrTypeProjection {
|
||||||
|
|||||||
+1
-1
@@ -212,7 +212,7 @@ class IrBodyDeserializer(
|
|||||||
val rawType = with(IrSimpleTypeBuilder()) {
|
val rawType = with(IrSimpleTypeBuilder()) {
|
||||||
arguments = typeParameters.memoryOptimizedMap {
|
arguments = typeParameters.memoryOptimizedMap {
|
||||||
classifier = it.symbol
|
classifier = it.symbol
|
||||||
buildTypeProjection()
|
buildSimpleType()
|
||||||
}
|
}
|
||||||
classifier = klass.symbol
|
classifier = klass.symbol
|
||||||
buildSimpleType()
|
buildSimpleType()
|
||||||
|
|||||||
Reference in New Issue
Block a user