Optimize ConstraintInjector::isMyTypeVariable
Do not look into the map for constructors that are not type variables
This commit is contained in:
+7
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstituto
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
@@ -32,6 +33,11 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
|
||||
return this.freshTypeConstructor
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.mayBeTypeVariable(): Boolean {
|
||||
require(this is KotlinType, this::errorMessage)
|
||||
return this.constructor is TypeVariableTypeConstructor
|
||||
}
|
||||
|
||||
override fun createCapturedType(
|
||||
constructorProjection: TypeArgumentMarker,
|
||||
constructorSupertypes: List<KotlinTypeMarker>,
|
||||
@@ -84,4 +90,4 @@ fun NewConstraintSystemImpl(
|
||||
builtIns: KotlinBuiltIns
|
||||
): NewConstraintSystemImpl {
|
||||
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -143,7 +143,8 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
||||
}
|
||||
|
||||
// from AbstractTypeCheckerContextForConstraintSystem
|
||||
override fun isMyTypeVariable(type: SimpleTypeMarker): Boolean = c.allTypeVariables.containsKey(type.typeConstructor())
|
||||
override fun isMyTypeVariable(type: SimpleTypeMarker): Boolean =
|
||||
type.mayBeTypeVariable() && c.allTypeVariables.containsKey(type.typeConstructor())
|
||||
|
||||
override fun addUpperConstraint(typeVariable: TypeConstructorMarker, superType: KotlinTypeMarker) =
|
||||
addConstraint(typeVariable, superType, UPPER)
|
||||
@@ -244,4 +245,4 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
||||
}
|
||||
}
|
||||
|
||||
data class ConstraintContext(val kind: ConstraintKind, val derivedFrom: Set<TypeVariableMarker>)
|
||||
data class ConstraintContext(val kind: ConstraintKind, val derivedFrom: Set<TypeVariableMarker>)
|
||||
|
||||
Reference in New Issue
Block a user