Simplify implementation of TypeSystemCommonSuperTypesContext.typeDepth
This commit is contained in:
+2
-16
@@ -91,7 +91,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
|
|||||||
|| this is ConeTypeParameterType
|
|| this is ConeTypeParameterType
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ConeKotlinType.typeDepthSimple(): Int {
|
override fun SimpleTypeMarker.typeDepth(): Int {
|
||||||
|
require(this is ConeKotlinType)
|
||||||
// if (this is TypeUtils.SpecialType) return 0 // TODO: WTF?
|
// if (this is TypeUtils.SpecialType) return 0 // TODO: WTF?
|
||||||
|
|
||||||
val maxInArguments = this.typeArguments.asSequence().map {
|
val maxInArguments = this.typeArguments.asSequence().map {
|
||||||
@@ -101,21 +102,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
|
|||||||
return maxInArguments + 1
|
return maxInArguments + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun SimpleTypeMarker.typeDepth(): Int {
|
|
||||||
require(this is ConeKotlinType)
|
|
||||||
return this.typeDepthSimple()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun KotlinTypeMarker.typeDepth(): Int {
|
|
||||||
require(this is ConeKotlinType) {
|
|
||||||
"Incorrect type of class ${this::class.java}: $this"
|
|
||||||
}
|
|
||||||
return when (this) {
|
|
||||||
is ConeFlexibleType -> Math.max(lowerBound.typeDepthSimple(), upperBound.typeDepthSimple())
|
|
||||||
else -> typeDepthSimple()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean {
|
override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean {
|
||||||
return this.containsInternal(predicate)
|
return this.containsInternal(predicate)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,8 +217,6 @@ interface IrTypeSystemContext : TypeSystemInferenceExtensionContext {
|
|||||||
|
|
||||||
override fun SimpleTypeMarker.typeDepth() = 2
|
override fun SimpleTypeMarker.typeDepth() = 2
|
||||||
|
|
||||||
override fun KotlinTypeMarker.typeDepth() = if (this is IrStarProjection) 1 else 0
|
|
||||||
|
|
||||||
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
||||||
irBuiltIns.intType as IrSimpleType
|
irBuiltIns.intType as IrSimpleType
|
||||||
|
|
||||||
|
|||||||
+6
-23
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||||
import kotlin.contracts.ExperimentalContracts
|
import kotlin.contracts.ExperimentalContracts
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
|
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
|
||||||
override fun TypeConstructorMarker.isDenotable(): Boolean {
|
override fun TypeConstructorMarker.isDenotable(): Boolean {
|
||||||
@@ -268,12 +267,13 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
|
|||||||
|
|
||||||
override fun SimpleTypeMarker.typeDepth(): Int {
|
override fun SimpleTypeMarker.typeDepth(): Int {
|
||||||
require(this is SimpleType, this::errorMessage)
|
require(this is SimpleType, this::errorMessage)
|
||||||
return this.typeDepthInternal()
|
if (this is TypeUtils.SpecialType) return 0
|
||||||
}
|
|
||||||
|
|
||||||
override fun KotlinTypeMarker.typeDepth(): Int {
|
val maxInArguments = arguments.asSequence().map {
|
||||||
require(this is UnwrappedType, this::errorMessage)
|
if (it.isStarProjection) 1 else it.type.unwrap().typeDepth()
|
||||||
return this.typeDepthInternal()
|
}.max() ?: 0
|
||||||
|
|
||||||
|
return maxInArguments + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
override fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
||||||
@@ -514,23 +514,6 @@ private fun containsInternal(type: KotlinType, predicate: (KotlinTypeMarker) ->
|
|||||||
|
|
||||||
private fun singleBestRepresentative(collection: Collection<KotlinType>) = collection.singleBestRepresentative()
|
private fun singleBestRepresentative(collection: Collection<KotlinType>) = collection.singleBestRepresentative()
|
||||||
|
|
||||||
internal fun UnwrappedType.typeDepthInternal() =
|
|
||||||
when (this) {
|
|
||||||
is SimpleType -> typeDepthInternal()
|
|
||||||
is FlexibleType -> max(lowerBound.typeDepthInternal(), upperBound.typeDepthInternal())
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun SimpleType.typeDepthInternal(): Int {
|
|
||||||
if (this is TypeUtils.SpecialType) return 0
|
|
||||||
|
|
||||||
val maxInArguments = arguments.asSequence().map {
|
|
||||||
if (it.isStarProjection) 1 else it.type.unwrap().typeDepthInternal()
|
|
||||||
}.max() ?: 0
|
|
||||||
|
|
||||||
return maxInArguments + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
private inline fun Any.errorMessage(): String {
|
private inline fun Any.errorMessage(): String {
|
||||||
return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}"
|
return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}"
|
||||||
|
|||||||
@@ -76,7 +76,12 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
|
|||||||
fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean
|
fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean
|
||||||
|
|
||||||
fun SimpleTypeMarker.typeDepth(): Int
|
fun SimpleTypeMarker.typeDepth(): Int
|
||||||
fun KotlinTypeMarker.typeDepth(): Int
|
|
||||||
|
fun KotlinTypeMarker.typeDepth(): Int = when (this) {
|
||||||
|
is SimpleTypeMarker -> typeDepth()
|
||||||
|
is FlexibleTypeMarker -> maxOf(lowerBound().typeDepth(), upperBound().typeDepth())
|
||||||
|
else -> error("Type should be simple or flexible: $this")
|
||||||
|
}
|
||||||
|
|
||||||
fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker?
|
fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker?
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user