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:
committed by
Space Team
parent
45b74d0313
commit
d430673320
+8
-1
@@ -7,15 +7,16 @@ package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.IrJvmFlexibleType
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.asJvmFlexibleType
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isWithFlexibleMutability
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isWithFlexibleNullability
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.ir.types.isMarkedNullable as irIsMarkedNullable
|
||||
import org.jetbrains.kotlin.types.model.FlexibleTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import org.jetbrains.kotlin.ir.types.isMarkedNullable as irIsMarkedNullable
|
||||
|
||||
class JvmIrTypeSystemContext(override val irBuiltIns: IrBuiltIns) : IrTypeSystemContext {
|
||||
override fun KotlinTypeMarker.asFlexibleType(): FlexibleTypeMarker? =
|
||||
@@ -37,4 +38,10 @@ class JvmIrTypeSystemContext(override val irBuiltIns: IrBuiltIns) : IrTypeSystem
|
||||
|
||||
override fun KotlinTypeMarker.isMarkedNullable(): Boolean =
|
||||
this is IrSimpleType && !isWithFlexibleNullability() && irIsMarkedNullable()
|
||||
|
||||
override fun KotlinTypeMarker.isDynamic(): Boolean =
|
||||
false
|
||||
|
||||
override fun KotlinTypeMarker.isFlexibleWithDifferentTypeConstructors(): Boolean =
|
||||
(this as IrType).isWithFlexibleMutability()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user