JVM IR: optimize type equality check on IR types

`AbstractTypeChecker.isCommonDenotableType` calls a few functions which
check if the type is flexible, which is not cheap in case of JVM IR, see
`asFlexibleType`.

 #KT-66281
This commit is contained in:
Alexander Udalov
2024-03-04 23:28:21 +01:00
committed by Space Team
parent 45b74d0313
commit d430673320
3 changed files with 12 additions and 2 deletions
@@ -513,7 +513,7 @@ object AbstractTypeChecker {
private fun TypeSystemContext.isCommonDenotableType(type: KotlinTypeMarker): Boolean =
type.typeConstructor().isDenotable() &&
!type.isDynamic() && !type.isDefinitelyNotNullType() && !type.isNotNullTypeParameter() &&
type.lowerBoundIfFlexible().typeConstructor() == type.upperBoundIfFlexible().typeConstructor()
!type.isFlexibleWithDifferentTypeConstructors()
fun effectiveVariance(declared: TypeVariance, useSite: TypeVariance): TypeVariance? {
if (declared == TypeVariance.INV) return useSite
@@ -448,6 +448,9 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun KotlinTypeMarker.lowerBoundIfFlexible(): SimpleTypeMarker = this.asFlexibleType()?.lowerBound() ?: this.asSimpleType()!!
fun KotlinTypeMarker.upperBoundIfFlexible(): SimpleTypeMarker = this.asFlexibleType()?.upperBound() ?: this.asSimpleType()!!
fun KotlinTypeMarker.isFlexibleWithDifferentTypeConstructors(): Boolean =
lowerBoundIfFlexible().typeConstructor() != upperBoundIfFlexible().typeConstructor()
fun TypeConstructorMarker.isDefinitelyClassTypeConstructor(): Boolean = isClassTypeConstructor() && !isInterface()
fun KotlinTypeMarker.isFlexible(): Boolean = asFlexibleType() != null