FIR: Add separate type constructor to stub types

This commit is contained in:
Simon Ogorodnik
2021-11-14 15:31:54 +03:00
committed by teamcity
parent 2e01377ce0
commit 196be93d42
9 changed files with 24 additions and 15 deletions
@@ -322,7 +322,11 @@ fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): Con
return ConeIntersectionType(intersectedTypes.map(func), alternativeType?.let(func))
}
sealed class ConeStubType(val variable: ConeTypeVariable, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() {
data class ConeStubTypeConstructor(val variable: ConeTypeVariable, val isTypeVariableInSubtyping: Boolean) : TypeConstructorMarker
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
ConeSimpleKotlinType() {
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
@@ -335,7 +339,7 @@ sealed class ConeStubType(val variable: ConeTypeVariable, override val nullabili
other as ConeStubType
if (variable != other.variable) return false
if (constructor != other.constructor) return false
if (nullability != other.nullability) return false
return true
@@ -343,14 +347,16 @@ sealed class ConeStubType(val variable: ConeTypeVariable, override val nullabili
override fun hashCode(): Int {
var result = 0
result = 31 * result + variable.hashCode()
result = 31 * result + constructor.hashCode()
result = 31 * result + nullability.hashCode()
return result
}
}
class ConeStubTypeForBuilderInference(variable: ConeTypeVariable, nullability: ConeNullability) : ConeStubType(variable, nullability)
class ConeStubTypeForTypeVariableInSubtyping(variable: ConeTypeVariable, nullability: ConeNullability) : ConeStubType(variable, nullability)
open class ConeStubTypeForBuilderInference(variable: ConeTypeVariable, nullability: ConeNullability) :
ConeStubType(ConeStubTypeConstructor(variable, isTypeVariableInSubtyping = false), nullability)
class ConeStubTypeForTypeVariableInSubtyping(variable: ConeTypeVariable, nullability: ConeNullability) :
ConeStubType(ConeStubTypeConstructor(variable, isTypeVariableInSubtyping = true), nullability)
open class ConeTypeVariable(name: String, originalTypeParameter: TypeParameterMarker? = null) : TypeVariableMarker {
val typeConstructor = ConeTypeVariableTypeConstructor(name, originalTypeParameter)
@@ -46,8 +46,8 @@ fun ConeKotlinType.render(): String {
postfix = ")"
)
}
is ConeStubTypeForBuilderInference -> "${renderAttributes()}Stub (builder inference): $variable"
is ConeStubType -> "${renderAttributes()}Stub (subtyping): $variable"
is ConeStubTypeForBuilderInference -> "${renderAttributes()}Stub (builder inference): ${constructor.variable}"
is ConeStubType -> "${renderAttributes()}Stub (subtyping): ${constructor.variable}"
is ConeIntegerLiteralType -> "${renderAttributes()}ILT: $value"
} + nullabilitySuffix
}
@@ -127,7 +127,7 @@ fun ConeKotlinType.findClassRepresentation(
is ConeTypeParameterType -> lookupTag.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session)
is ConeTypeVariableType -> (this.lookupTag.originalTypeParameter as? ConeTypeParameterLookupTag)
?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session)
is ConeStubType -> (this.variable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag)
is ConeStubType -> (this.constructor.variable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag)
?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session)
is ConeLookupTagBasedType -> null
}
@@ -131,7 +131,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
override fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker {
require(this is ConeStubType)
return this.variable.typeConstructor
return this.constructor.variable.typeConstructor
}
override fun KotlinTypeMarker.typeDepth() = when (this) {
@@ -144,7 +144,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
is ConeCapturedType -> constructor
is ConeTypeVariableType -> lookupTag
is ConeIntersectionType -> this
is ConeStubType -> variable.typeConstructor
is ConeStubType -> constructor
is ConeDefinitelyNotNullType -> original.typeConstructor()
is ConeIntegerLiteralType -> this
else -> error("?: $this")
@@ -244,6 +244,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
}
}
is ConeIntegerLiteralType -> 0
is ConeStubTypeConstructor -> 0
else -> unknownConstructorError()
}
}
@@ -271,6 +272,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
override fun TypeConstructorMarker.supertypes(): Collection<ConeKotlinType> {
if (this is ErrorTypeConstructor) return emptyList()
return when (this) {
is ConeStubTypeConstructor -> emptyList()
is ConeTypeVariableTypeConstructor -> emptyList()
is ConeTypeParameterLookupTag -> symbol.fir.bounds.map { it.coneType }
is ConeClassLikeLookupTag -> {
@@ -342,6 +344,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
is ConeClassLikeLookupTag,
is ConeTypeParameterLookupTag -> true
is ConeStubTypeConstructor,
is ConeCapturedTypeConstructor,
is ErrorTypeConstructor,
is ConeTypeVariableTypeConstructor,
@@ -165,8 +165,8 @@ fun <T : ConeKotlinType> T.withNullability(
ConeNullability.UNKNOWN -> this // TODO: is that correct?
ConeNullability.NOT_NULL -> this
}
is ConeStubTypeForBuilderInference -> ConeStubTypeForBuilderInference(variable, nullability)
is ConeStubTypeForTypeVariableInSubtyping -> ConeStubTypeForTypeVariableInSubtyping(variable, nullability)
is ConeStubTypeForBuilderInference -> ConeStubTypeForBuilderInference(constructor.variable, nullability)
is ConeStubTypeForTypeVariableInSubtyping -> ConeStubTypeForTypeVariableInSubtyping(constructor.variable, nullability)
is ConeDefinitelyNotNullType -> when (nullability) {
ConeNullability.NOT_NULL -> this
ConeNullability.NULLABLE -> original.withNullability(nullability, typeContext)
@@ -169,7 +169,7 @@ class FirBuilderInferenceSession(
val bindings = mutableMapOf<TypeConstructorMarker, ConeKotlinType>()
for ((variable, nonFixedType) in stubsForPostponedVariables) {
bindings[nonFixedType.variable.typeConstructor] = variable.defaultType
bindings[nonFixedType.constructor] = variable.defaultType
}
return ctx.typeSubstitutorByTypeConstructor(bindings)
@@ -145,7 +145,7 @@ object ConeKotlinTypeComparator : Comparator<ConeKotlinType> {
require(b is ConeStubType) {
"priority is inconsistent: ${a.render()} v.s. ${b.render()}"
}
val nameDiff = a.variable.typeConstructor.name.compareTo(b.variable.typeConstructor.name)
val nameDiff = a.constructor.variable.typeConstructor.name.compareTo(b.constructor.variable.typeConstructor.name)
if (nameDiff != 0) {
return nameDiff
}
@@ -39,7 +39,7 @@ fun ConeKotlinType.renderForDebugInfo(): String {
separator = " & ",
) { it.renderForDebugInfo() }
}
is ConeStubType -> "Stub: $variable"
is ConeStubType -> "Stub: ${constructor.variable}"
is ConeIntegerLiteralType -> "ILT: $value"
} + nullabilitySuffix
}