Rename AbstractTypeCheckerContext to TypeCheckerState
This commit is contained in:
+1
-1
@@ -441,7 +441,7 @@ object FirExpectActualResolver {
|
||||
if (expectedType == null) return actualType == null
|
||||
if (actualType == null) return false
|
||||
|
||||
val typeCheckerContext = ConeInferenceContextForExpectActual(expectSession, actualSession).newBaseTypeCheckerContext(
|
||||
val typeCheckerContext = ConeInferenceContextForExpectActual(expectSession, actualSession).newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
)
|
||||
|
||||
+7
-7
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerState
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
@@ -43,7 +43,7 @@ object FirImplementationMismatchChecker : FirClassChecker() {
|
||||
val classKind = declaration.classKind
|
||||
if (classKind == ClassKind.ANNOTATION_CLASS || classKind == ClassKind.ENUM_CLASS) return
|
||||
|
||||
val typeCheckerContext = context.session.typeContext.newBaseTypeCheckerContext(
|
||||
val typeCheckerState = context.session.typeContext.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = false
|
||||
)
|
||||
@@ -52,10 +52,10 @@ object FirImplementationMismatchChecker : FirClassChecker() {
|
||||
|
||||
for (name in classScope.getCallableNames()) {
|
||||
classScope.processFunctionsByName(name) {
|
||||
checkInheritanceClash(declaration, context, dedupReporter, typeCheckerContext, it, classScope)
|
||||
checkInheritanceClash(declaration, context, dedupReporter, typeCheckerState, it, classScope)
|
||||
}
|
||||
classScope.processPropertiesByName(name) {
|
||||
checkInheritanceClash(declaration, context, dedupReporter, typeCheckerContext, it, classScope)
|
||||
checkInheritanceClash(declaration, context, dedupReporter, typeCheckerState, it, classScope)
|
||||
checkValOverridesVar(declaration, context, dedupReporter, it, classScope)
|
||||
}
|
||||
checkConflictingMembers(declaration, context, dedupReporter, classScope, name)
|
||||
@@ -66,7 +66,7 @@ object FirImplementationMismatchChecker : FirClassChecker() {
|
||||
containingClass: FirClass,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter,
|
||||
typeCheckerContext: ConeTypeCheckerContext,
|
||||
typeCheckerState: ConeTypeCheckerState,
|
||||
symbol: FirCallableSymbol<*>,
|
||||
classScope: FirTypeScope
|
||||
) {
|
||||
@@ -96,9 +96,9 @@ object FirImplementationMismatchChecker : FirClassChecker() {
|
||||
): Boolean {
|
||||
val inheritedTypeSubstituted = inheritedType.substituteTypeParameters(inheritedMember, baseMember, context)
|
||||
return if (baseMember is FirPropertySymbol && baseMember.isVar)
|
||||
AbstractTypeChecker.equalTypes(typeCheckerContext, inheritedTypeSubstituted, baseType)
|
||||
AbstractTypeChecker.equalTypes(typeCheckerState, inheritedTypeSubstituted, baseType)
|
||||
else
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerContext, inheritedTypeSubstituted, baseType)
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerState, inheritedTypeSubstituted, baseType)
|
||||
}
|
||||
|
||||
val intersectionSymbols = when {
|
||||
|
||||
+8
-8
@@ -34,11 +34,11 @@ import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.upperBoundIfFlexible
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
|
||||
object FirOverrideChecker : FirClassChecker() {
|
||||
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val typeCheckerContext = context.session.typeContext.newBaseTypeCheckerContext(
|
||||
val typeCheckerState = context.session.typeContext.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = false
|
||||
)
|
||||
@@ -47,7 +47,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
|
||||
for (it in declaration.declarations) {
|
||||
if (it is FirSimpleFunction || it is FirProperty) {
|
||||
checkMember((it as FirCallableDeclaration).symbol, declaration, reporter, typeCheckerContext, firTypeScope, context)
|
||||
checkMember((it as FirCallableDeclaration).symbol, declaration, reporter, typeCheckerState, firTypeScope, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
// See [OverrideResolver#isReturnTypeOkForOverride]
|
||||
private fun FirCallableSymbol<*>.checkReturnType(
|
||||
overriddenSymbols: List<FirCallableSymbol<*>>,
|
||||
typeCheckerContext: AbstractTypeCheckerContext,
|
||||
typeCheckerState: TypeCheckerState,
|
||||
context: CheckerContext,
|
||||
): FirCallableSymbol<*>? {
|
||||
val overridingReturnType = resolvedReturnTypeRef.coneType
|
||||
@@ -191,9 +191,9 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
|
||||
val isReturnTypeOkForOverride =
|
||||
if (overriddenDeclaration is FirPropertySymbol && overriddenDeclaration.isVar)
|
||||
AbstractTypeChecker.equalTypes(typeCheckerContext, overridingReturnType, overriddenReturnType)
|
||||
AbstractTypeChecker.equalTypes(typeCheckerState, overridingReturnType, overriddenReturnType)
|
||||
else
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerContext, overridingReturnType, overriddenReturnType)
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerState, overridingReturnType, overriddenReturnType)
|
||||
|
||||
if (!isReturnTypeOkForOverride) {
|
||||
return overriddenDeclaration
|
||||
@@ -207,7 +207,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
member: FirCallableSymbol<*>,
|
||||
containingClass: FirClass,
|
||||
reporter: DiagnosticReporter,
|
||||
typeCheckerContext: AbstractTypeCheckerContext,
|
||||
typeCheckerState: TypeCheckerState,
|
||||
firTypeScope: FirTypeScope,
|
||||
context: CheckerContext
|
||||
) {
|
||||
@@ -268,7 +268,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
|
||||
val restriction = member.checkReturnType(
|
||||
overriddenSymbols = overriddenMemberSymbols,
|
||||
typeCheckerContext = typeCheckerContext,
|
||||
typeCheckerState = typeCheckerState,
|
||||
context = context,
|
||||
) ?: return
|
||||
when (member) {
|
||||
|
||||
+1
-1
@@ -695,7 +695,7 @@ class CallAndReferenceGenerator(
|
||||
// If the type of the argument is already an explicitly subtype of the type of the parameter, we don't need SAM conversion.
|
||||
if (argument.typeRef !is FirResolvedTypeRef ||
|
||||
AbstractTypeChecker.isSubtypeOf(
|
||||
session.inferenceComponents.ctx.newBaseTypeCheckerContext(
|
||||
session.inferenceComponents.ctx.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false, stubTypesEqualToAnything = true
|
||||
),
|
||||
argument.typeRef.coneType,
|
||||
|
||||
@@ -537,7 +537,7 @@ fun FirExpression.isFunctional(
|
||||
val returnTypeCompatible =
|
||||
expectedReturnType is ConeTypeParameterType ||
|
||||
AbstractTypeChecker.isSubtypeOf(
|
||||
session.inferenceComponents.ctx.newBaseTypeCheckerContext(
|
||||
session.inferenceComponents.ctx.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
),
|
||||
@@ -557,7 +557,7 @@ fun FirExpression.isFunctional(
|
||||
val expectedParameterType = expectedParameter.lowerBoundIfFlexible()
|
||||
expectedParameterType is ConeTypeParameterType ||
|
||||
AbstractTypeChecker.isSubtypeOf(
|
||||
session.inferenceComponents.ctx.newBaseTypeCheckerContext(
|
||||
session.inferenceComponents.ctx.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
),
|
||||
|
||||
+1
-1
@@ -649,7 +649,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
if (originalType !is ConeClassLikeType) return type
|
||||
val baseFirClass = originalType.lookupTag.toSymbol(session)?.fir ?: return type
|
||||
val isSubtype = AbstractTypeChecker.isSubtypeOfClass(
|
||||
session.typeContext.newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true),
|
||||
session.typeContext.newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true),
|
||||
originalType.lookupTag,
|
||||
type.lookupTag
|
||||
)
|
||||
|
||||
+3
-4
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
|
||||
class FirTypeIntersectionScope private constructor(
|
||||
session: FirSession,
|
||||
@@ -35,7 +34,7 @@ class FirTypeIntersectionScope private constructor(
|
||||
private val absentProperties: MutableSet<Name> = mutableSetOf()
|
||||
private val absentClassifiers: MutableSet<Name> = mutableSetOf()
|
||||
|
||||
private val typeCheckerContext = session.typeContext.newBaseTypeCheckerContext(false, false)
|
||||
private val typeCheckerState = session.typeContext.newTypeCheckerState(false, false)
|
||||
|
||||
private val overriddenSymbols: MutableMap<FirCallableSymbol<*>, Collection<MemberWithBaseScope<out FirCallableSymbol<*>>>> =
|
||||
mutableMapOf()
|
||||
@@ -420,7 +419,7 @@ class FirTypeIntersectionScope private constructor(
|
||||
require(bFir is FirProperty) { "b is " + b.javaClass }
|
||||
// TODO: if (!OverridingUtil.isAccessorMoreSpecific(pa.getSetter(), pb.getSetter())) return false
|
||||
return if (aFir.isVar && bFir.isVar) {
|
||||
AbstractTypeChecker.equalTypes(typeCheckerContext as AbstractTypeCheckerContext, aReturnType, bReturnType)
|
||||
AbstractTypeChecker.equalTypes(typeCheckerState, aReturnType, bReturnType)
|
||||
} else { // both vals or var vs val: val can't be more specific then var
|
||||
!(!aFir.isVar && bFir.isVar) && isTypeMoreSpecific(aReturnType, bReturnType)
|
||||
}
|
||||
@@ -429,7 +428,7 @@ class FirTypeIntersectionScope private constructor(
|
||||
}
|
||||
|
||||
private fun isTypeMoreSpecific(a: ConeKotlinType, b: ConeKotlinType): Boolean =
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerContext as AbstractTypeCheckerContext, a, b)
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerState, a, b)
|
||||
|
||||
private fun <D : FirCallableSymbol<*>> findMemberWithMaxVisibility(members: Collection<MemberWithBaseScope<D>>): MemberWithBaseScope<D> {
|
||||
assert(members.isNotEmpty())
|
||||
|
||||
@@ -106,11 +106,11 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
return ConeStarProjection
|
||||
}
|
||||
|
||||
override fun newBaseTypeCheckerContext(
|
||||
override fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): ConeTypeCheckerContext =
|
||||
ConeTypeCheckerContext(errorTypesEqualToAnything, stubTypesEqualToAnything, this)
|
||||
): ConeTypeCheckerState =
|
||||
ConeTypeCheckerState(errorTypesEqualToAnything, stubTypesEqualToAnything, this)
|
||||
|
||||
override fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean {
|
||||
require(this is ConeKotlinType)
|
||||
@@ -198,7 +198,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
override fun Collection<KotlinTypeMarker>.singleBestRepresentative(): KotlinTypeMarker? {
|
||||
if (this.size == 1) return this.first()
|
||||
|
||||
val context = newBaseTypeCheckerContext(errorTypesEqualToAnything = true, stubTypesEqualToAnything = true)
|
||||
val context = newTypeCheckerState(errorTypesEqualToAnything = true, stubTypesEqualToAnything = true)
|
||||
return this.firstOrNull { candidate ->
|
||||
this.all { other ->
|
||||
// We consider error types equal to anything here, so that intersections like
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
|
||||
object ConeNullabilityChecker {
|
||||
fun isSubtypeOfAny(context: ConeTypeContext, type: ConeKotlinType): Boolean {
|
||||
val actualType = with(context) { type.lowerBoundIfFlexible() }
|
||||
return with(AbstractNullabilityChecker) {
|
||||
context.newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
.hasNotNullSupertype(actualType, AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible)
|
||||
context.newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
.hasNotNullSupertype(actualType, TypeCheckerState.SupertypesPolicy.LowerIfFlexible)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext.SupertypesPolicy.DoCustomTransform
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.DoCustomTransform
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.LowerIfFlexible
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
@@ -567,12 +567,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
}
|
||||
}
|
||||
|
||||
class ConeTypeCheckerContext(
|
||||
class ConeTypeCheckerState(
|
||||
override val isErrorTypeEqualsToAnything: Boolean,
|
||||
override val isStubTypeEqualsToAnything: Boolean,
|
||||
override val typeSystemContext: ConeInferenceContext,
|
||||
val kotlinTypePreparator: ConeTypePreparator = ConeTypePreparator.getDefault(typeSystemContext.session),
|
||||
) : AbstractTypeCheckerContext() {
|
||||
) : TypeCheckerState() {
|
||||
|
||||
val session: FirSession = typeSystemContext.session
|
||||
|
||||
@@ -595,7 +595,7 @@ class ConeTypeCheckerContext(
|
||||
ConeSubstitutor.Empty
|
||||
}
|
||||
return object : DoCustomTransform() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
val lowerBound = type.lowerBoundIfFlexible()
|
||||
require(lowerBound is ConeKotlinType)
|
||||
return substitutor.substituteOrSelf(lowerBound) as SimpleTypeMarker
|
||||
|
||||
+16
-16
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.typeContext
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
@@ -29,24 +29,24 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
||||
): List<ConeClassLikeType>? {
|
||||
if (type !is ConeClassLikeType || supertypeConstructor !is ConeClassLikeLookupTag) return null
|
||||
|
||||
val context = session.typeContext.newBaseTypeCheckerContext(
|
||||
val typeCheckerState = session.typeContext.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
)
|
||||
|
||||
val lookupTag = type.lookupTag
|
||||
if (lookupTag == supertypeConstructor) return listOf(captureType(type, context.typeSystemContext))
|
||||
if (lookupTag == supertypeConstructor) return listOf(captureType(type, typeCheckerState.typeSystemContext))
|
||||
if (lookupTag !in cache) {
|
||||
cache[lookupTag] = computeSupertypesMap(lookupTag, context)
|
||||
cache[lookupTag] = computeSupertypesMap(lookupTag, typeCheckerState)
|
||||
}
|
||||
|
||||
val resultTypes = cache[lookupTag]?.getOrDefault(supertypeConstructor, emptyList()) ?: return null
|
||||
if (type.typeArguments.isEmpty()) return resultTypes
|
||||
|
||||
val capturedType = captureType(type, context.typeSystemContext)
|
||||
val substitutionSupertypePolicy = context.substitutionSupertypePolicy(capturedType)
|
||||
val capturedType = captureType(type, typeCheckerState.typeSystemContext)
|
||||
val substitutionSupertypePolicy = typeCheckerState.substitutionSupertypePolicy(capturedType)
|
||||
return resultTypes.map {
|
||||
substitutionSupertypePolicy.transformType(context, it) as ConeClassLikeType
|
||||
substitutionSupertypePolicy.transformType(typeCheckerState, it) as ConeClassLikeType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
||||
|
||||
private fun computeSupertypesMap(
|
||||
subtypeLookupTag: ConeClassLikeLookupTag,
|
||||
context: ConeTypeCheckerContext
|
||||
state: ConeTypeCheckerState
|
||||
): Map<ConeClassLikeLookupTag, List<ConeClassLikeType>>? {
|
||||
val resultingMap = HashMap<ConeClassLikeLookupTag, List<ConeClassLikeType>>()
|
||||
|
||||
@@ -68,10 +68,10 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
||||
isNullable = false
|
||||
)
|
||||
|
||||
if (context.anySupertype(
|
||||
if (state.anySupertype(
|
||||
defaultType,
|
||||
{ it !is ConeClassLikeType || it.lookupTag.toSymbol(session) !is FirClassLikeSymbol<*> }
|
||||
) { supertype -> computeSupertypePolicyAndPutInMap(supertype, resultingMap, context) }
|
||||
) { supertype -> computeSupertypePolicyAndPutInMap(supertype, resultingMap, state) }
|
||||
) {
|
||||
return null
|
||||
}
|
||||
@@ -84,20 +84,20 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
||||
private fun computeSupertypePolicyAndPutInMap(
|
||||
supertype: SimpleTypeMarker,
|
||||
resultingMap: MutableMap<ConeClassLikeLookupTag, List<ConeClassLikeType>>,
|
||||
context: ConeTypeCheckerContext
|
||||
): AbstractTypeCheckerContext.SupertypesPolicy {
|
||||
state: ConeTypeCheckerState
|
||||
): TypeCheckerState.SupertypesPolicy {
|
||||
val supertypeLookupTag = (supertype as ConeClassLikeType).lookupTag
|
||||
val captured =
|
||||
context.typeSystemContext.captureFromArguments(supertype, CaptureStatus.FOR_SUBTYPING) as ConeClassLikeType? ?: supertype
|
||||
state.typeSystemContext.captureFromArguments(supertype, CaptureStatus.FOR_SUBTYPING) as ConeClassLikeType? ?: supertype
|
||||
|
||||
resultingMap[supertypeLookupTag] = listOf(captured)
|
||||
|
||||
return when {
|
||||
with(context.typeSystemContext) { captured.argumentsCount() } == 0 -> {
|
||||
AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible
|
||||
with(state.typeSystemContext) { captured.argumentsCount() } == 0 -> {
|
||||
TypeCheckerState.SupertypesPolicy.LowerIfFlexible
|
||||
}
|
||||
else -> {
|
||||
context.substitutionSupertypePolicy(captured)
|
||||
state.substitutionSupertypePolicy(captured)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ fun ConeDefinitelyNotNullType.Companion.create(
|
||||
return when {
|
||||
original is ConeDefinitelyNotNullType -> original
|
||||
typeContext
|
||||
.newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = false)
|
||||
.newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = false)
|
||||
.makesSenseToBeDefinitelyNotNull(original, useCorrectedNullabilityForFlexibleTypeParameters) ->
|
||||
|
||||
ConeDefinitelyNotNullType(
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
@@ -151,7 +151,7 @@ fun FirTypeProjection.toConeTypeProjection(): ConeTypeProjection =
|
||||
else -> error("!")
|
||||
}
|
||||
|
||||
fun AbstractTypeCheckerContext.makesSenseToBeDefinitelyNotNull(
|
||||
fun TypeCheckerState.makesSenseToBeDefinitelyNotNull(
|
||||
type: ConeKotlinType,
|
||||
useCorrectedNullabilityForFlexibleTypeParameters: Boolean
|
||||
): Boolean {
|
||||
|
||||
+3
-3
@@ -164,7 +164,7 @@ class JavaNullabilityChecker(val upperBoundChecker: UpperBoundChecker) : Additio
|
||||
|
||||
var metWrongNullabilityInsideArguments = false
|
||||
|
||||
val typeContext: AbstractTypeCheckerContext = object : ClassicTypeCheckerContext(errorTypeEqualsToAnything = true) {
|
||||
val typeState: TypeCheckerState = object : ClassicTypeCheckerState(errorTypeEqualsToAnything = true) {
|
||||
private var expectsTypeArgument = false
|
||||
override fun customIsSubtypeOf(subType: KotlinTypeMarker, superType: KotlinTypeMarker): Boolean {
|
||||
|
||||
@@ -183,7 +183,7 @@ class JavaNullabilityChecker(val upperBoundChecker: UpperBoundChecker) : Additio
|
||||
}
|
||||
}
|
||||
|
||||
AbstractTypeChecker.isSubtypeOf(typeContext, expressionType, c.expectedType)
|
||||
AbstractTypeChecker.isSubtypeOf(typeState, expressionType, c.expectedType)
|
||||
|
||||
return metWrongNullabilityInsideArguments
|
||||
}
|
||||
@@ -194,7 +194,7 @@ class JavaNullabilityChecker(val upperBoundChecker: UpperBoundChecker) : Additio
|
||||
): Boolean {
|
||||
if (superType !is NotNullTypeVariable) return false
|
||||
return !AbstractNullabilityChecker.isSubtypeOfAny(
|
||||
ClassicTypeCheckerContext(errorTypeEqualsToAnything = true) as AbstractTypeCheckerContext,
|
||||
ClassicTypeCheckerState(errorTypeEqualsToAnything = true) as TypeCheckerState,
|
||||
subType
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerState
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
@@ -232,7 +232,7 @@ class BuilderInferenceSupport(
|
||||
|
||||
with(NewKotlinTypeChecker.Default) {
|
||||
val parameterType = getEffectiveExpectedType(argumentMatch.valueParameter, valueArgument, context)
|
||||
BuilderInferenceTypeCheckerContext(allowOnlyTrivialConstraints = false).isSubtypeOf(kotlinType.unwrap(), parameterType.unwrap())
|
||||
BuilderInferenceTypeCheckerState(allowOnlyTrivialConstraints = false).isSubtypeOf(kotlinType.unwrap(), parameterType.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,16 +245,16 @@ class BuilderInferenceSupport(
|
||||
|
||||
resultingCall.extensionReceiver?.let { actualReceiver ->
|
||||
with(NewKotlinTypeChecker.Default) {
|
||||
BuilderInferenceTypeCheckerContext(allowOnlyTrivialConstraints = allowOnlyTrivialConstraintsForReceiver).isSubtypeOf(
|
||||
BuilderInferenceTypeCheckerState(allowOnlyTrivialConstraints = allowOnlyTrivialConstraintsForReceiver).isSubtypeOf(
|
||||
actualReceiver.type.unwrap(), extensionReceiver.value.type.unwrap()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class BuilderInferenceTypeCheckerContext(
|
||||
private class BuilderInferenceTypeCheckerState(
|
||||
private val allowOnlyTrivialConstraints: Boolean
|
||||
) : ClassicTypeCheckerContext(errorTypeEqualsToAnything = true) {
|
||||
) : ClassicTypeCheckerState(errorTypeEqualsToAnything = true) {
|
||||
|
||||
override fun addSubtypeConstraint(subType: KotlinTypeMarker, superType: KotlinTypeMarker, isFromNullabilityConstraint: Boolean): Boolean? {
|
||||
require(subType is UnwrappedType)
|
||||
|
||||
+8
-8
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@@ -215,7 +215,7 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
if (superFun.typeParameters.size != overridingFun.typeParameters.size) return false
|
||||
if (superFun.valueParameters.size != overridingFun.valueParameters.size) return false
|
||||
|
||||
val typeChecker = createTypeChecker(superFun, overridingFun)
|
||||
val typeChecker = createTypeCheckerState(superFun, overridingFun)
|
||||
|
||||
// Note that type parameters equivalence check doesn't really happen on collection stubs
|
||||
// (because members of Kotlin built-in collection classes don't have type parameters of their own),
|
||||
@@ -228,8 +228,8 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
return true
|
||||
}
|
||||
|
||||
private fun createTypeChecker(overrideFun: IrSimpleFunction, parentFun: IrSimpleFunction): AbstractTypeCheckerContext =
|
||||
IrTypeCheckerContext(
|
||||
private fun createTypeCheckerState(overrideFun: IrSimpleFunction, parentFun: IrSimpleFunction): TypeCheckerState =
|
||||
IrTypeCheckerState(
|
||||
IrTypeSystemContextWithAdditionalAxioms(
|
||||
context.typeSystem,
|
||||
overrideFun.typeParameters,
|
||||
@@ -240,7 +240,7 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
private fun areTypeParametersEquivalent(
|
||||
overrideFun: IrSimpleFunction,
|
||||
parentFun: IrSimpleFunction,
|
||||
typeChecker: AbstractTypeCheckerContext
|
||||
typeChecker: TypeCheckerState
|
||||
): Boolean =
|
||||
overrideFun.typeParameters.zip(parentFun.typeParameters)
|
||||
.all { (typeParameter1, typeParameter2) ->
|
||||
@@ -253,7 +253,7 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
private fun areValueParametersEquivalent(
|
||||
overrideFun: IrSimpleFunction,
|
||||
parentFun: IrSimpleFunction,
|
||||
typeChecker: AbstractTypeCheckerContext
|
||||
typeChecker: TypeCheckerState
|
||||
): Boolean =
|
||||
overrideFun.valueParameters.zip(parentFun.valueParameters)
|
||||
.all { (valueParameter1, valueParameter2) ->
|
||||
@@ -263,7 +263,7 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
internal fun isReturnTypeOverrideCompliant(
|
||||
overrideFun: IrSimpleFunction,
|
||||
parentFun: IrSimpleFunction,
|
||||
typeChecker: AbstractTypeCheckerContext
|
||||
typeChecker: TypeCheckerState
|
||||
): Boolean =
|
||||
AbstractTypeChecker.isSubtypeOf(typeChecker, overrideFun.returnType, parentFun.returnType)
|
||||
|
||||
@@ -476,4 +476,4 @@ internal class CollectionStubComputer(val context: JvmBackendContext) {
|
||||
stubs.none { other -> it.readOnlyClass != other.readOnlyClass && other.readOnlyClass.isSubtypeOfClass(it.readOnlyClass) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
@@ -20,7 +19,7 @@ import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.incompatible
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
abstract class FakeOverrideBuilderStrategy {
|
||||
@@ -439,14 +438,14 @@ class IrOverridingUtil(
|
||||
return if (a == null || b == null) true else isVisibilityMoreSpecific(a, b)
|
||||
}
|
||||
|
||||
private fun IrTypeCheckerContext.isSubtypeOf(a: IrType, b: IrType) =
|
||||
AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, a, b)
|
||||
private fun IrTypeCheckerState.isSubtypeOf(a: IrType, b: IrType) =
|
||||
AbstractTypeChecker.isSubtypeOf(this as TypeCheckerState, a, b)
|
||||
|
||||
private fun IrTypeCheckerContext.equalTypes(a: IrType, b: IrType) =
|
||||
AbstractTypeChecker.equalTypes(this as AbstractTypeCheckerContext, a, b)
|
||||
private fun IrTypeCheckerState.equalTypes(a: IrType, b: IrType) =
|
||||
AbstractTypeChecker.equalTypes(this as TypeCheckerState, a, b)
|
||||
|
||||
private fun createTypeChecker(a: List<IrTypeParameter>, b: List<IrTypeParameter>) =
|
||||
IrTypeCheckerContext(IrTypeSystemContextWithAdditionalAxioms(typeSystem, a, b))
|
||||
private fun createTypeCheckerState(a: List<IrTypeParameter>, b: List<IrTypeParameter>) =
|
||||
IrTypeCheckerState(IrTypeSystemContextWithAdditionalAxioms(typeSystem, a, b))
|
||||
|
||||
private fun isReturnTypeMoreSpecific(
|
||||
a: IrOverridableMember,
|
||||
@@ -454,7 +453,7 @@ class IrOverridingUtil(
|
||||
b: IrOverridableMember,
|
||||
bReturnType: IrType
|
||||
): Boolean {
|
||||
val typeCheckerContext = createTypeChecker(a.typeParameters, b.typeParameters)
|
||||
val typeCheckerContext = createTypeCheckerState(a.typeParameters, b.typeParameters)
|
||||
return typeCheckerContext.isSubtypeOf(aReturnType, bReturnType)
|
||||
}
|
||||
|
||||
@@ -479,7 +478,7 @@ class IrOverridingUtil(
|
||||
)
|
||||
) return false
|
||||
return if (pa.isVar && pb.isVar) {
|
||||
createTypeChecker(
|
||||
createTypeCheckerState(
|
||||
a.getter!!.typeParameters,
|
||||
b.getter!!.typeParameters
|
||||
).equalTypes(aReturnType, bReturnType)
|
||||
@@ -674,8 +673,8 @@ class IrOverridingUtil(
|
||||
return incompatible("Type parameter number mismatch")
|
||||
}
|
||||
|
||||
val typeCheckerContext =
|
||||
IrTypeCheckerContext(
|
||||
val typeCheckerState =
|
||||
IrTypeCheckerState(
|
||||
IrTypeSystemContextWithAdditionalAxioms(
|
||||
typeSystem,
|
||||
superTypeParameters,
|
||||
@@ -698,7 +697,7 @@ class IrOverridingUtil(
|
||||
|
||||
superValueParameters.forEachIndexed { index, parameter ->
|
||||
if (!AbstractTypeChecker.equalTypes(
|
||||
typeCheckerContext as AbstractTypeCheckerContext,
|
||||
typeCheckerState as TypeCheckerState,
|
||||
subValueParameters[index].type,
|
||||
parameter.type
|
||||
)
|
||||
@@ -711,7 +710,7 @@ class IrOverridingUtil(
|
||||
|
||||
if (checkReturnType) {
|
||||
if (!AbstractTypeChecker.isSubtypeOf(
|
||||
typeCheckerContext as AbstractTypeCheckerContext,
|
||||
typeCheckerState as TypeCheckerState,
|
||||
subMember.returnType,
|
||||
superMember.returnType
|
||||
)
|
||||
|
||||
+3
-3
@@ -7,11 +7,11 @@ package org.jetbrains.kotlin.ir.types
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
|
||||
open class IrTypeCheckerContext(override val typeSystemContext: IrTypeSystemContext): AbstractTypeCheckerContext() {
|
||||
open class IrTypeCheckerState(override val typeSystemContext: IrTypeSystemContext): TypeCheckerState() {
|
||||
|
||||
val irBuiltIns: IrBuiltIns get() = typeSystemContext.irBuiltIns
|
||||
|
||||
@@ -21,7 +21,7 @@ open class IrTypeCheckerContext(override val typeSystemContext: IrTypeSystemCont
|
||||
val typeSubstitutor = IrTypeSubstitutor(parameters, type.arguments, irBuiltIns)
|
||||
|
||||
return object : SupertypesPolicy.DoCustomTransform() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
require(type is IrType)
|
||||
return typeSubstitutor.substitute(type) as IrSimpleType
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
@@ -501,10 +501,10 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
}
|
||||
|
||||
|
||||
override fun newBaseTypeCheckerContext(
|
||||
override fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): AbstractTypeCheckerContext = IrTypeCheckerContext(this)
|
||||
): TypeCheckerState = IrTypeCheckerState(this)
|
||||
|
||||
override fun KotlinTypeMarker.isUninferredParameter(): Boolean = false
|
||||
override fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker {
|
||||
|
||||
@@ -30,7 +30,7 @@ fun IrType.isSubtypeOfClass(superClass: IrClassSymbol): Boolean =
|
||||
this is IrSimpleType && classifier.isSubtypeOfClass(superClass)
|
||||
|
||||
fun IrType.isSubtypeOf(superType: IrType, typeSystem: IrTypeSystemContext): Boolean =
|
||||
AbstractTypeChecker.isSubtypeOf(IrTypeCheckerContext(typeSystem), this, superType)
|
||||
AbstractTypeChecker.isSubtypeOf(IrTypeCheckerState(typeSystem), this, superType)
|
||||
|
||||
fun IrType.isNullable(): Boolean =
|
||||
when (this) {
|
||||
|
||||
+31
-31
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibi
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
object NewCommonSuperTypeCalculator {
|
||||
@@ -47,14 +47,14 @@ object NewCommonSuperTypeCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
val contextStubTypesEqualToAnything = newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
val contextStubTypesNotEqual = newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = false)
|
||||
val stateStubTypesEqualToAnything = newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
val stateStubTypesNotEqual = newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = false)
|
||||
|
||||
val lowerSuperType = commonSuperTypeForSimpleTypes(lowers, depth, contextStubTypesEqualToAnything, contextStubTypesNotEqual)
|
||||
val lowerSuperType = commonSuperTypeForSimpleTypes(lowers, depth, stateStubTypesEqualToAnything, stateStubTypesNotEqual)
|
||||
if (!thereIsFlexibleTypes) return lowerSuperType
|
||||
|
||||
val upperSuperType = commonSuperTypeForSimpleTypes(
|
||||
types.map { it.upperBoundIfFlexible() }, depth, contextStubTypesEqualToAnything, contextStubTypesNotEqual
|
||||
types.map { it.upperBoundIfFlexible() }, depth, stateStubTypesEqualToAnything, stateStubTypesNotEqual
|
||||
)
|
||||
|
||||
if (!isTopLevelType) {
|
||||
@@ -78,8 +78,8 @@ object NewCommonSuperTypeCalculator {
|
||||
private fun TypeSystemCommonSuperTypesContext.commonSuperTypeForSimpleTypes(
|
||||
types: List<SimpleTypeMarker>,
|
||||
depth: Int,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext,
|
||||
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState,
|
||||
stateStubTypesNotEqual: TypeCheckerState
|
||||
): SimpleTypeMarker {
|
||||
if (types.any { it.isError() }) {
|
||||
return createErrorType("CST(${types.joinToString()}")
|
||||
@@ -87,10 +87,10 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
// i.e. result type also should be marked nullable
|
||||
val notAllNotNull =
|
||||
types.any { !isTypeVariable(it) && !AbstractNullabilityChecker.isSubtypeOfAny(contextStubTypesEqualToAnything, it) }
|
||||
types.any { !isTypeVariable(it) && !AbstractNullabilityChecker.isSubtypeOfAny(stateStubTypesEqualToAnything, it) }
|
||||
val notNullTypes = if (notAllNotNull) types.map { it.withNullability(false) } else types
|
||||
|
||||
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth, contextStubTypesEqualToAnything, contextStubTypesNotEqual)
|
||||
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth, stateStubTypesEqualToAnything, stateStubTypesNotEqual)
|
||||
return if (notAllNotNull)
|
||||
refineNullabilityForUndefinedNullability(types, commonSuperType) ?: commonSuperType.withNullability(true)
|
||||
else
|
||||
@@ -115,12 +115,12 @@ object NewCommonSuperTypeCalculator {
|
||||
// Makes representative sample, i.e. (A, B, A) -> (A, B)
|
||||
private fun TypeSystemCommonSuperTypesContext.uniquify(
|
||||
types: List<SimpleTypeMarker>,
|
||||
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
||||
stateStubTypesNotEqual: TypeCheckerState
|
||||
): List<SimpleTypeMarker> {
|
||||
val uniqueTypes = arrayListOf<SimpleTypeMarker>()
|
||||
for (type in types) {
|
||||
val isNewUniqueType = uniqueTypes.all {
|
||||
val equalsModuloFlexibility = AbstractTypeChecker.equalTypes(contextStubTypesNotEqual, it, type) &&
|
||||
val equalsModuloFlexibility = AbstractTypeChecker.equalTypes(stateStubTypesNotEqual, it, type) &&
|
||||
!it.typeConstructor().isIntegerLiteralTypeConstructor()
|
||||
|
||||
!equalsModuloFlexibility || hasDifferentFlexibilityAtDepth(listOf(it, type))
|
||||
@@ -136,7 +136,7 @@ object NewCommonSuperTypeCalculator {
|
||||
// Explanation: consider types (A : A0, B : B0, A0, B0), then CST(A, B, A0, B0) == CST(CST(A, A0), CST(B, B0)) == CST(A0, B0)
|
||||
private fun TypeSystemCommonSuperTypesContext.filterSupertypes(
|
||||
list: List<SimpleTypeMarker>,
|
||||
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
||||
stateStubTypesNotEqual: TypeCheckerState
|
||||
): List<SimpleTypeMarker> {
|
||||
val supertypes = list.toMutableList()
|
||||
val iterator = supertypes.iterator()
|
||||
@@ -144,7 +144,7 @@ object NewCommonSuperTypeCalculator {
|
||||
val potentialSubtype = iterator.next()
|
||||
val isSubtype = supertypes.any { supertype ->
|
||||
supertype !== potentialSubtype &&
|
||||
AbstractTypeChecker.isSubtypeOf(contextStubTypesNotEqual, potentialSubtype, supertype) &&
|
||||
AbstractTypeChecker.isSubtypeOf(stateStubTypesNotEqual, potentialSubtype, supertype) &&
|
||||
!hasDifferentFlexibilityAtDepth(listOf(potentialSubtype, supertype))
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ object NewCommonSuperTypeCalculator {
|
||||
private fun TypeSystemCommonSuperTypesContext.commonSuperTypeForNotNullTypes(
|
||||
types: List<SimpleTypeMarker>,
|
||||
depth: Int,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext,
|
||||
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState,
|
||||
stateStubTypesNotEqual: TypeCheckerState
|
||||
): SimpleTypeMarker {
|
||||
if (types.size == 1) return types.single()
|
||||
|
||||
@@ -187,20 +187,20 @@ object NewCommonSuperTypeCalculator {
|
||||
if (uniqueStubTypes.size > 1) return nullableAnyType()
|
||||
|
||||
if (stubTypeVariables.none { it.isDefinitelyNotNullType() }) {
|
||||
return uniquify(stubTypeVariables.ifEmpty { types }, contextStubTypesNotEqual).singleOrNull() ?: return nullableAnyType()
|
||||
return uniquify(stubTypeVariables.ifEmpty { types }, stateStubTypesNotEqual).singleOrNull() ?: return nullableAnyType()
|
||||
}
|
||||
}
|
||||
|
||||
val uniqueTypes = uniquify(nonTypeVariables, contextStubTypesNotEqual)
|
||||
val uniqueTypes = uniquify(nonTypeVariables, stateStubTypesNotEqual)
|
||||
if (uniqueTypes.size == 1) return uniqueTypes.single()
|
||||
|
||||
val explicitSupertypes = filterSupertypes(uniqueTypes, contextStubTypesNotEqual)
|
||||
val explicitSupertypes = filterSupertypes(uniqueTypes, stateStubTypesNotEqual)
|
||||
if (explicitSupertypes.size == 1) return explicitSupertypes.single()
|
||||
findErrorTypeInSupertypes(explicitSupertypes, contextStubTypesEqualToAnything)?.let { return it }
|
||||
findErrorTypeInSupertypes(explicitSupertypes, stateStubTypesEqualToAnything)?.let { return it }
|
||||
|
||||
findCommonIntegerLiteralTypesSuperType(explicitSupertypes)?.let { return it }
|
||||
|
||||
return findSuperTypeConstructorsAndIntersectResult(explicitSupertypes, depth, contextStubTypesEqualToAnything)
|
||||
return findSuperTypeConstructorsAndIntersectResult(explicitSupertypes, depth, stateStubTypesEqualToAnything)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.isTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||
@@ -215,10 +215,10 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.findErrorTypeInSupertypes(
|
||||
types: List<SimpleTypeMarker>,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState
|
||||
): SimpleTypeMarker? {
|
||||
for (type in types) {
|
||||
collectAllSupertypes(type, contextStubTypesEqualToAnything).firstOrNull { it.isError() }?.let { return it.toErrorType() }
|
||||
collectAllSupertypes(type, stateStubTypesEqualToAnything).firstOrNull { it.isError() }?.let { return it.toErrorType() }
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -226,10 +226,10 @@ object NewCommonSuperTypeCalculator {
|
||||
private fun TypeSystemCommonSuperTypesContext.findSuperTypeConstructorsAndIntersectResult(
|
||||
types: List<SimpleTypeMarker>,
|
||||
depth: Int,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState
|
||||
): SimpleTypeMarker =
|
||||
intersectTypes(
|
||||
allCommonSuperTypeConstructors(types, contextStubTypesEqualToAnything)
|
||||
allCommonSuperTypeConstructors(types, stateStubTypesEqualToAnything)
|
||||
.map { superTypeWithGivenConstructor(types, it, depth) }
|
||||
)
|
||||
|
||||
@@ -238,14 +238,14 @@ object NewCommonSuperTypeCalculator {
|
||||
*/
|
||||
private fun TypeSystemCommonSuperTypesContext.allCommonSuperTypeConstructors(
|
||||
types: List<SimpleTypeMarker>,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState
|
||||
): List<TypeConstructorMarker> {
|
||||
val result = collectAllSupertypes(types.first(), contextStubTypesEqualToAnything)
|
||||
val result = collectAllSupertypes(types.first(), stateStubTypesEqualToAnything)
|
||||
// retain all super constructors of the first type that are present in the supertypes of all other types
|
||||
for (type in types) {
|
||||
if (type === types.first()) continue
|
||||
|
||||
result.retainAll(collectAllSupertypes(type, contextStubTypesEqualToAnything))
|
||||
result.retainAll(collectAllSupertypes(type, stateStubTypesEqualToAnything))
|
||||
}
|
||||
// remove all constructors that have subtype(s) with constructors from the resulting set - they are less precise
|
||||
return result.filterNot { target ->
|
||||
@@ -257,13 +257,13 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.collectAllSupertypes(
|
||||
type: SimpleTypeMarker,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
|
||||
stateStubTypesEqualToAnything: TypeCheckerState
|
||||
) =
|
||||
LinkedHashSet<TypeConstructorMarker>().apply {
|
||||
contextStubTypesEqualToAnything.anySupertype(
|
||||
stateStubTypesEqualToAnything.anySupertype(
|
||||
type,
|
||||
{ add(it.typeConstructor()); false },
|
||||
{ AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible }
|
||||
{ TypeCheckerState.SupertypesPolicy.LowerIfFlexible }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ object NewCommonSuperTypeCalculator {
|
||||
nullable = false
|
||||
)
|
||||
|
||||
val typeCheckerContext = newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
val typeCheckerContext = newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
|
||||
/**
|
||||
* Sometimes one type can have several supertypes with given type constructor, suppose A <: List<Int> and A <: List<Double>.
|
||||
|
||||
+35
-35
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.*
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
@@ -43,23 +43,23 @@ class ConstraintInjector(
|
||||
|
||||
fun addInitialSubtypeConstraint(c: Context, lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition) {
|
||||
val initialConstraint = InitialConstraint(lowerType, upperType, UPPER, position).also { c.addInitialConstraint(it) }
|
||||
val typeCheckerContext = TypeCheckerContext(c, IncorporationConstraintPosition(position, initialConstraint))
|
||||
val typeCheckerState = TypeCheckerStateForConstraintInjector(c, IncorporationConstraintPosition(position, initialConstraint))
|
||||
|
||||
updateAllowedTypeDepth(c, lowerType)
|
||||
updateAllowedTypeDepth(c, upperType)
|
||||
|
||||
addSubTypeConstraintAndIncorporateIt(c, lowerType, upperType, typeCheckerContext)
|
||||
addSubTypeConstraintAndIncorporateIt(c, lowerType, upperType, typeCheckerState)
|
||||
}
|
||||
|
||||
private fun Context.addInitialEqualityConstraintThroughSubtyping(
|
||||
a: KotlinTypeMarker,
|
||||
b: KotlinTypeMarker,
|
||||
typeCheckerContext: TypeCheckerContext
|
||||
typeCheckerState: TypeCheckerStateForConstraintInjector
|
||||
) {
|
||||
updateAllowedTypeDepth(this, a)
|
||||
updateAllowedTypeDepth(this, b)
|
||||
addSubTypeConstraintAndIncorporateIt(this, a, b, typeCheckerContext)
|
||||
addSubTypeConstraintAndIncorporateIt(this, b, a, typeCheckerContext)
|
||||
addSubTypeConstraintAndIncorporateIt(this, a, b, typeCheckerState)
|
||||
addSubTypeConstraintAndIncorporateIt(this, b, a, typeCheckerState)
|
||||
}
|
||||
|
||||
fun addInitialEqualityConstraint(c: Context, a: KotlinTypeMarker, b: KotlinTypeMarker, position: ConstraintPosition) = with(c) {
|
||||
@@ -69,32 +69,32 @@ class ConstraintInjector(
|
||||
else -> return
|
||||
}
|
||||
val initialConstraint = InitialConstraint(typeVariable, equalType, EQUALITY, position).also { c.addInitialConstraint(it) }
|
||||
val typeCheckerContext = TypeCheckerContext(c, IncorporationConstraintPosition(position, initialConstraint))
|
||||
val typeCheckerState = TypeCheckerStateForConstraintInjector(c, IncorporationConstraintPosition(position, initialConstraint))
|
||||
|
||||
// We add constraints like `T? == Foo!` in the old way
|
||||
if (!typeVariable.isSimpleType() || typeVariable.isMarkedNullable()) {
|
||||
addInitialEqualityConstraintThroughSubtyping(typeVariable, equalType, typeCheckerContext)
|
||||
addInitialEqualityConstraintThroughSubtyping(typeVariable, equalType, typeCheckerState)
|
||||
return
|
||||
}
|
||||
|
||||
updateAllowedTypeDepth(c, equalType)
|
||||
addEqualityConstraintAndIncorporateIt(c, typeVariable, equalType, typeCheckerContext)
|
||||
addEqualityConstraintAndIncorporateIt(c, typeVariable, equalType, typeCheckerState)
|
||||
}
|
||||
|
||||
private fun addSubTypeConstraintAndIncorporateIt(
|
||||
c: Context,
|
||||
lowerType: KotlinTypeMarker,
|
||||
upperType: KotlinTypeMarker,
|
||||
typeCheckerContext: TypeCheckerContext
|
||||
typeCheckerState: TypeCheckerStateForConstraintInjector
|
||||
) {
|
||||
typeCheckerContext.setConstrainingTypesToPrintDebugInfo(lowerType, upperType)
|
||||
typeCheckerContext.runIsSubtypeOf(lowerType, upperType)
|
||||
typeCheckerState.setConstrainingTypesToPrintDebugInfo(lowerType, upperType)
|
||||
typeCheckerState.runIsSubtypeOf(lowerType, upperType)
|
||||
|
||||
// Missed constraints are constraints which we skipped in the constraints processor by mistake (incorrect optimization)
|
||||
val missedConstraints = processConstraints(c, typeCheckerContext)
|
||||
val missedConstraints = processConstraints(c, typeCheckerState)
|
||||
|
||||
if (missedConstraints != null) {
|
||||
c.addMissedConstraints(typeCheckerContext.position, missedConstraints)
|
||||
c.addMissedConstraints(typeCheckerState.position, missedConstraints)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,16 +102,16 @@ class ConstraintInjector(
|
||||
c: Context,
|
||||
typeVariable: KotlinTypeMarker,
|
||||
equalType: KotlinTypeMarker,
|
||||
typeCheckerContext: TypeCheckerContext
|
||||
typeCheckerState: TypeCheckerStateForConstraintInjector
|
||||
) {
|
||||
typeCheckerContext.setConstrainingTypesToPrintDebugInfo(typeVariable, equalType)
|
||||
typeCheckerContext.addEqualityConstraint(typeVariable.typeConstructor(c), equalType)
|
||||
typeCheckerState.setConstrainingTypesToPrintDebugInfo(typeVariable, equalType)
|
||||
typeCheckerState.addEqualityConstraint(typeVariable.typeConstructor(c), equalType)
|
||||
|
||||
// Missed constraints are constraints which we skipped in the constraints processor by mistake (incorrect optimization)
|
||||
val missedConstraints = processConstraints(c, typeCheckerContext)
|
||||
val missedConstraints = processConstraints(c, typeCheckerState)
|
||||
|
||||
if (missedConstraints != null) {
|
||||
c.addMissedConstraints(typeCheckerContext.position, missedConstraints)
|
||||
c.addMissedConstraints(typeCheckerState.position, missedConstraints)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,23 +126,23 @@ class ConstraintInjector(
|
||||
// If proper constraints processing is enabled, then we don't have missed constraints
|
||||
if (properConstraintsProcessingEnabled) return
|
||||
|
||||
val typeCheckerContext = TypeCheckerContext(c, position)
|
||||
val typeCheckerState = TypeCheckerStateForConstraintInjector(c, position)
|
||||
for ((variable, constraint) in missedConstraints) {
|
||||
typeCheckerContext.addPossibleNewConstraint(variable, constraint)
|
||||
typeCheckerState.addPossibleNewConstraint(variable, constraint)
|
||||
}
|
||||
processConstraints(c, typeCheckerContext, skipProperEqualityConstraints = false)
|
||||
processConstraints(c, typeCheckerState, skipProperEqualityConstraints = false)
|
||||
}
|
||||
|
||||
private fun processConstraints(
|
||||
c: Context,
|
||||
typeCheckerContext: TypeCheckerContext,
|
||||
typeCheckerState: TypeCheckerStateForConstraintInjector,
|
||||
skipProperEqualityConstraints: Boolean = true
|
||||
): MutableList<Pair<TypeVariableMarker, Constraint>>? {
|
||||
val properConstraintsProcessingEnabled =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.ProperTypeInferenceConstraintsProcessing)
|
||||
|
||||
while (typeCheckerContext.hasConstraintsToProcess()) {
|
||||
processGivenConstraints(c, typeCheckerContext, typeCheckerContext.extractAllConstraints()!!)
|
||||
while (typeCheckerState.hasConstraintsToProcess()) {
|
||||
processGivenConstraints(c, typeCheckerState, typeCheckerState.extractAllConstraints()!!)
|
||||
|
||||
val contextOps = c as? ConstraintSystemOperation
|
||||
|
||||
@@ -157,21 +157,21 @@ class ConstraintInjector(
|
||||
}
|
||||
}
|
||||
|
||||
if (hasProperEqualityConstraintForEachVariable) return typeCheckerContext.extractAllConstraints()
|
||||
if (hasProperEqualityConstraintForEachVariable) return typeCheckerState.extractAllConstraints()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun processGivenConstraints(
|
||||
c: Context,
|
||||
typeCheckerContext: TypeCheckerContext,
|
||||
typeCheckerState: TypeCheckerStateForConstraintInjector,
|
||||
constraintsToProcess: MutableList<Pair<TypeVariableMarker, Constraint>>
|
||||
) {
|
||||
for ((typeVariable, constraint) in constraintsToProcess) {
|
||||
if (c.shouldWeSkipConstraint(typeVariable, constraint)) continue
|
||||
|
||||
val constraints =
|
||||
c.notFixedTypeVariables[typeVariable.freshTypeConstructor(c)] ?: typeCheckerContext.fixedTypeVariable(typeVariable)
|
||||
c.notFixedTypeVariables[typeVariable.freshTypeConstructor(c)] ?: typeCheckerState.fixedTypeVariable(typeVariable)
|
||||
|
||||
// it is important, that we add constraint here(not inside TypeCheckerContext), because inside incorporation we read constraints
|
||||
val (addedOrNonRedundantExistedConstraint, wasAdded) = constraints.addConstraint(constraint)
|
||||
@@ -184,7 +184,7 @@ class ConstraintInjector(
|
||||
}
|
||||
|
||||
if (constraintToIncorporate != null) {
|
||||
constraintIncorporator.incorporate(typeCheckerContext, typeVariable, constraintToIncorporate)
|
||||
constraintIncorporator.incorporate(typeCheckerState, typeVariable, constraintToIncorporate)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,8 +217,8 @@ class ConstraintInjector(
|
||||
private fun Context.isAllowedType(type: KotlinTypeMarker) =
|
||||
type.typeDepth() <= maxTypeDepthFromInitialConstraints + ALLOWED_DEPTH_DELTA_FOR_INCORPORATION
|
||||
|
||||
private inner class TypeCheckerContext(val c: Context, val position: IncorporationConstraintPosition) :
|
||||
AbstractTypeCheckerContextForConstraintSystem(c), ConstraintIncorporator.Context, TypeSystemInferenceExtensionContext by c {
|
||||
private inner class TypeCheckerStateForConstraintInjector(val c: Context, val position: IncorporationConstraintPosition) :
|
||||
TypeCheckerStateForConstraintSystem(c), ConstraintIncorporator.Context, TypeSystemInferenceExtensionContext by c {
|
||||
// We use `var` intentionally to avoid extra allocations as this property is quite "hot"
|
||||
private var possibleNewConstraints: MutableList<Pair<TypeVariableMarker, Constraint>>? = null
|
||||
|
||||
@@ -245,10 +245,10 @@ class ConstraintInjector(
|
||||
baseUpperType = upperType
|
||||
}
|
||||
|
||||
val baseContext: AbstractTypeCheckerContext = newBaseTypeCheckerContext(isErrorTypeEqualsToAnything, isStubTypeEqualsToAnything)
|
||||
val baseState: TypeCheckerState = newTypeCheckerState(isErrorTypeEqualsToAnything, isStubTypeEqualsToAnything)
|
||||
|
||||
override fun substitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy {
|
||||
return baseContext.substitutionSupertypePolicy(type)
|
||||
return baseState.substitutionSupertypePolicy(type)
|
||||
}
|
||||
|
||||
override fun refineType(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||
@@ -257,7 +257,7 @@ class ConstraintInjector(
|
||||
}
|
||||
}
|
||||
|
||||
override fun prepareType(type: KotlinTypeMarker) = baseContext.prepareType(type)
|
||||
override fun prepareType(type: KotlinTypeMarker) = baseState.prepareType(type)
|
||||
|
||||
fun runIsSubtypeOf(
|
||||
lowerType: KotlinTypeMarker,
|
||||
@@ -267,7 +267,7 @@ class ConstraintInjector(
|
||||
) {
|
||||
fun isSubtypeOf(upperType: KotlinTypeMarker) =
|
||||
AbstractTypeChecker.isSubtypeOf(
|
||||
this@TypeCheckerContext as AbstractTypeCheckerContext,
|
||||
this@TypeCheckerStateForConstraintInjector as TypeCheckerState,
|
||||
lowerType,
|
||||
upperType,
|
||||
isFromNullabilityConstraint
|
||||
|
||||
+6
-6
@@ -7,11 +7,11 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
abstract class AbstractTypeCheckerContextForConstraintSystem(override val typeSystemContext: TypeSystemInferenceExtensionContext) :
|
||||
AbstractTypeCheckerContext() {
|
||||
abstract class TypeCheckerStateForConstraintSystem(override val typeSystemContext: TypeSystemInferenceExtensionContext) :
|
||||
TypeCheckerState() {
|
||||
|
||||
override val KotlinTypeMarker.isAllowedTypeVariable: Boolean
|
||||
get() = false
|
||||
@@ -99,10 +99,10 @@ abstract class AbstractTypeCheckerContextForConstraintSystem(override val typeSy
|
||||
}
|
||||
|
||||
private fun KotlinTypeMarker.isTypeVariableWithExact() =
|
||||
with(typeSystemContext) { hasExactAnnotation() } && anyBound(this@AbstractTypeCheckerContextForConstraintSystem::isMyTypeVariable)
|
||||
with(typeSystemContext) { hasExactAnnotation() } && anyBound(this@TypeCheckerStateForConstraintSystem::isMyTypeVariable)
|
||||
|
||||
private fun KotlinTypeMarker.isTypeVariableWithNoInfer() =
|
||||
with(typeSystemContext) { hasNoInferAnnotation() } && anyBound(this@AbstractTypeCheckerContextForConstraintSystem::isMyTypeVariable)
|
||||
with(typeSystemContext) { hasNoInferAnnotation() } && anyBound(this@TypeCheckerStateForConstraintSystem::isMyTypeVariable)
|
||||
|
||||
private fun internalAddSubtypeConstraint(
|
||||
subType: KotlinTypeMarker,
|
||||
@@ -333,7 +333,7 @@ abstract class AbstractTypeCheckerContextForConstraintSystem(override val typeSy
|
||||
}
|
||||
|
||||
private fun isSubtypeOfByTypeChecker(subType: KotlinTypeMarker, superType: KotlinTypeMarker) =
|
||||
AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, subType, superType)
|
||||
AbstractTypeChecker.isSubtypeOf(this as TypeCheckerState, subType, superType)
|
||||
|
||||
private fun assertInputTypes(subType: KotlinTypeMarker, superType: KotlinTypeMarker) = with(typeSystemContext) {
|
||||
if (!AbstractTypeChecker.RUN_SLOW_ASSERTIONS) return
|
||||
-1
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.AbstractTypeCheckerContextForConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemUtilContext
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ abstract class AbstractTypeApproximator(
|
||||
val needApproximate = conf.localTypes && constructor.isLocalType()
|
||||
if (!needApproximate) return null
|
||||
val superConstructor = constructor.supertypes().first().typeConstructor()
|
||||
val typeCheckerContext = newBaseTypeCheckerContext(
|
||||
val typeCheckerContext = newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = false
|
||||
)
|
||||
|
||||
+1
-1
@@ -305,7 +305,7 @@ object ExpectedActualResolver {
|
||||
kotlinTypeRefiner: KotlinTypeRefiner,
|
||||
): Boolean {
|
||||
with(NewKotlinTypeCheckerImpl(kotlinTypeRefiner)) {
|
||||
return ClassicTypeCheckerContext(
|
||||
return ClassicTypeCheckerState(
|
||||
errorTypeEqualsToAnything = false,
|
||||
typeSystemContext = typeSystemContext,
|
||||
kotlinTypeRefiner = kotlinTypeRefiner,
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeIntersector
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerState
|
||||
|
||||
class SlowTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() {
|
||||
|
||||
@@ -45,7 +45,7 @@ class SlowTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() {
|
||||
try {
|
||||
val superType = TypeIntersector.intersectTypes(listOf(builtIns.charSequence.defaultType, builtIns.comparable.defaultType))
|
||||
AbstractNullabilityChecker.isPossibleSubtype(
|
||||
ClassicTypeCheckerContext(errorTypeEqualsToAnything = true), builtIns.annotationType,
|
||||
ClassicTypeCheckerState(errorTypeEqualsToAnything = true), builtIns.annotationType,
|
||||
superType as SimpleType
|
||||
)
|
||||
} catch (e: AssertionError) {
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.EffectiveVisibility.Permissiveness
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.TypeCheckerProviderContext
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
|
||||
@@ -261,7 +261,7 @@ internal fun containerRelation(
|
||||
}
|
||||
}
|
||||
|
||||
private fun TypeCheckerProviderContext.createTypeCheckerContext(): AbstractTypeCheckerContext = newBaseTypeCheckerContext(
|
||||
private fun TypeCheckerProviderContext.createTypeCheckerContext(): TypeCheckerState = newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
)
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext.LowerCapturedTypePolicy.*
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext.SupertypesPolicy
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.LowerCapturedTypePolicy.*
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
@@ -14,14 +14,14 @@ import java.util.*
|
||||
|
||||
/**
|
||||
* Context that defines how type-checker operates, stores type-checker state,
|
||||
* created by [TypeCheckerProviderContext.newBaseTypeCheckerContext] in most cases
|
||||
* created by [TypeCheckerProviderContext.newTypeCheckerState] in most cases
|
||||
*
|
||||
* Stateful and shouldn't be reused
|
||||
*
|
||||
* Once some type-checker operation is performed using a [TypeCheckerProviderContext], for example a [AbstractTypeChecker.isSubtypeOf],
|
||||
* new instance of particular [AbstractTypeCheckerContext] should be created, with properly specified type system context
|
||||
* new instance of particular [TypeCheckerState] should be created, with properly specified type system context
|
||||
*/
|
||||
abstract class AbstractTypeCheckerContext() {
|
||||
abstract class TypeCheckerState {
|
||||
|
||||
abstract val typeSystemContext: TypeSystemContext
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class AbstractTypeCheckerContext() {
|
||||
|
||||
protected var argumentsDepth = 0
|
||||
|
||||
internal inline fun <T> runWithArgumentsSettings(subArgument: KotlinTypeMarker, f: AbstractTypeCheckerContext.() -> T): T {
|
||||
internal inline fun <T> runWithArgumentsSettings(subArgument: KotlinTypeMarker, f: TypeCheckerState.() -> T): T {
|
||||
if (argumentsDepth > 100) {
|
||||
error("Arguments depth is too high. Some related argument: $subArgument")
|
||||
}
|
||||
@@ -134,21 +134,21 @@ abstract class AbstractTypeCheckerContext() {
|
||||
}
|
||||
|
||||
sealed class SupertypesPolicy {
|
||||
abstract fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker
|
||||
abstract fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker
|
||||
|
||||
object None : SupertypesPolicy() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker) =
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker) =
|
||||
throw UnsupportedOperationException("Should not be called")
|
||||
}
|
||||
|
||||
object UpperIfFlexible : SupertypesPolicy() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker) =
|
||||
with(context.typeSystemContext) { type.upperBoundIfFlexible() }
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker) =
|
||||
with(state.typeSystemContext) { type.upperBoundIfFlexible() }
|
||||
}
|
||||
|
||||
object LowerIfFlexible : SupertypesPolicy() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker) =
|
||||
with(context.typeSystemContext) { type.lowerBoundIfFlexible() }
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker) =
|
||||
with(state.typeSystemContext) { type.lowerBoundIfFlexible() }
|
||||
}
|
||||
|
||||
abstract class DoCustomTransform : SupertypesPolicy()
|
||||
@@ -168,7 +168,7 @@ object AbstractTypeChecker {
|
||||
context: TypeCheckerProviderContext,
|
||||
type: KotlinTypeMarker,
|
||||
stubTypesEqualToAnything: Boolean = true
|
||||
) = context.newBaseTypeCheckerContext(true, stubTypesEqualToAnything).prepareType(type)
|
||||
) = context.newTypeCheckerState(true, stubTypesEqualToAnything).prepareType(type)
|
||||
|
||||
fun isSubtypeOf(
|
||||
context: TypeCheckerProviderContext,
|
||||
@@ -176,18 +176,18 @@ object AbstractTypeChecker {
|
||||
superType: KotlinTypeMarker,
|
||||
stubTypesEqualToAnything: Boolean = true
|
||||
): Boolean {
|
||||
return isSubtypeOf(context.newBaseTypeCheckerContext(true, stubTypesEqualToAnything), subType, superType)
|
||||
return isSubtypeOf(context.newTypeCheckerState(true, stubTypesEqualToAnything), subType, superType)
|
||||
}
|
||||
|
||||
fun isSubtypeOfClass(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
typeConstructor: TypeConstructorMarker,
|
||||
superConstructor: TypeConstructorMarker
|
||||
): Boolean {
|
||||
if (typeConstructor == superConstructor) return true
|
||||
with(context.typeSystemContext) {
|
||||
with(state.typeSystemContext) {
|
||||
for (superType in typeConstructor.supertypes()) {
|
||||
if (isSubtypeOfClass(context, superType.typeConstructor(), superConstructor)) {
|
||||
if (isSubtypeOfClass(state, superType.typeConstructor(), superConstructor)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -201,29 +201,29 @@ object AbstractTypeChecker {
|
||||
b: KotlinTypeMarker,
|
||||
stubTypesEqualToAnything: Boolean = true
|
||||
): Boolean {
|
||||
return equalTypes(context.newBaseTypeCheckerContext(false, stubTypesEqualToAnything), a, b)
|
||||
return equalTypes(context.newTypeCheckerState(false, stubTypesEqualToAnything), a, b)
|
||||
}
|
||||
|
||||
fun isSubtypeOf(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: KotlinTypeMarker,
|
||||
superType: KotlinTypeMarker,
|
||||
isFromNullabilityConstraint: Boolean = false
|
||||
): Boolean {
|
||||
if (subType === superType) return true
|
||||
|
||||
if (!context.customIsSubtypeOf(subType, superType)) return false
|
||||
if (!state.customIsSubtypeOf(subType, superType)) return false
|
||||
|
||||
return completeIsSubTypeOf(context, subType, superType, isFromNullabilityConstraint)
|
||||
return completeIsSubTypeOf(state, subType, superType, isFromNullabilityConstraint)
|
||||
}
|
||||
|
||||
fun equalTypes(context: AbstractTypeCheckerContext, a: KotlinTypeMarker, b: KotlinTypeMarker): Boolean =
|
||||
with(context.typeSystemContext) {
|
||||
fun equalTypes(state: TypeCheckerState, a: KotlinTypeMarker, b: KotlinTypeMarker): Boolean =
|
||||
with(state.typeSystemContext) {
|
||||
if (a === b) return true
|
||||
|
||||
if (isCommonDenotableType(a) && isCommonDenotableType(b)) {
|
||||
val refinedA = context.prepareType(context.refineType(a))
|
||||
val refinedB = context.prepareType(context.refineType(b))
|
||||
val refinedA = state.prepareType(state.refineType(a))
|
||||
val refinedB = state.prepareType(state.refineType(b))
|
||||
val simpleA = refinedA.lowerBoundIfFlexible()
|
||||
if (!areEqualTypeConstructors(refinedA.typeConstructor(), refinedB.typeConstructor())) return false
|
||||
if (simpleA.argumentsCount() == 0) {
|
||||
@@ -233,40 +233,40 @@ object AbstractTypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
return isSubtypeOf(context, a, b) && isSubtypeOf(context, b, a)
|
||||
return isSubtypeOf(state, a, b) && isSubtypeOf(state, b, a)
|
||||
}
|
||||
|
||||
|
||||
private fun completeIsSubTypeOf(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: KotlinTypeMarker,
|
||||
superType: KotlinTypeMarker,
|
||||
isFromNullabilityConstraint: Boolean
|
||||
): Boolean = with(context.typeSystemContext) {
|
||||
val preparedSubType = context.prepareType(context.refineType(subType))
|
||||
val preparedSuperType = context.prepareType(context.refineType(superType))
|
||||
): Boolean = with(state.typeSystemContext) {
|
||||
val preparedSubType = state.prepareType(state.refineType(subType))
|
||||
val preparedSuperType = state.prepareType(state.refineType(superType))
|
||||
|
||||
checkSubtypeForSpecialCases(context, preparedSubType.lowerBoundIfFlexible(), preparedSuperType.upperBoundIfFlexible())?.let {
|
||||
context.addSubtypeConstraint(preparedSubType, preparedSuperType, isFromNullabilityConstraint)
|
||||
checkSubtypeForSpecialCases(state, preparedSubType.lowerBoundIfFlexible(), preparedSuperType.upperBoundIfFlexible())?.let {
|
||||
state.addSubtypeConstraint(preparedSubType, preparedSuperType, isFromNullabilityConstraint)
|
||||
return it
|
||||
}
|
||||
|
||||
// we should add constraints with flexible types, otherwise we never get flexible type as answer in constraint system
|
||||
context.addSubtypeConstraint(preparedSubType, preparedSuperType, isFromNullabilityConstraint)?.let { return it }
|
||||
state.addSubtypeConstraint(preparedSubType, preparedSuperType, isFromNullabilityConstraint)?.let { return it }
|
||||
|
||||
return isSubtypeOfForSingleClassifierType(context, preparedSubType.lowerBoundIfFlexible(), preparedSuperType.upperBoundIfFlexible())
|
||||
return isSubtypeOfForSingleClassifierType(state, preparedSubType.lowerBoundIfFlexible(), preparedSuperType.upperBoundIfFlexible())
|
||||
}
|
||||
|
||||
private fun checkSubtypeForIntegerLiteralType(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: SimpleTypeMarker,
|
||||
superType: SimpleTypeMarker
|
||||
): Boolean? = with(context.typeSystemContext) {
|
||||
): Boolean? = with(state.typeSystemContext) {
|
||||
if (!subType.isIntegerLiteralType() && !superType.isIntegerLiteralType()) return null
|
||||
|
||||
fun isTypeInIntegerLiteralType(integerLiteralType: SimpleTypeMarker, type: SimpleTypeMarker, checkSupertypes: Boolean): Boolean =
|
||||
integerLiteralType.possibleIntegerTypes().any { possibleType ->
|
||||
(possibleType.typeConstructor() == type.typeConstructor()) || (checkSupertypes && isSubtypeOf(context, type, possibleType))
|
||||
(possibleType.typeConstructor() == type.typeConstructor()) || (checkSupertypes && isSubtypeOf(state, type, possibleType))
|
||||
}
|
||||
|
||||
fun isIntegerLiteralTypeInIntersectionComponents(type: SimpleTypeMarker): Boolean {
|
||||
@@ -299,12 +299,12 @@ object AbstractTypeChecker {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun hasNothingSupertype(context: AbstractTypeCheckerContext, type: SimpleTypeMarker): Boolean = with(context.typeSystemContext) {
|
||||
private fun hasNothingSupertype(state: TypeCheckerState, type: SimpleTypeMarker): Boolean = with(state.typeSystemContext) {
|
||||
val typeConstructor = type.typeConstructor()
|
||||
if (typeConstructor.isClassTypeConstructor()) {
|
||||
return typeConstructor.isNothingConstructor()
|
||||
}
|
||||
return context.anySupertype(type, { it.typeConstructor().isNothingConstructor() }) {
|
||||
return state.anySupertype(type, { it.typeConstructor().isNothingConstructor() }) {
|
||||
if (it.isClassType()) {
|
||||
SupertypesPolicy.None
|
||||
} else {
|
||||
@@ -314,23 +314,23 @@ object AbstractTypeChecker {
|
||||
}
|
||||
|
||||
private fun isSubtypeOfForSingleClassifierType(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: SimpleTypeMarker,
|
||||
superType: SimpleTypeMarker
|
||||
): Boolean = with(context.typeSystemContext) {
|
||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||
assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || context.isAllowedTypeVariable(subType)) {
|
||||
): Boolean = with(state.typeSystemContext) {
|
||||
if (RUN_SLOW_ASSERTIONS) {
|
||||
assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || state.isAllowedTypeVariable(subType)) {
|
||||
"Not singleClassifierType and not intersection subType: $subType"
|
||||
}
|
||||
assert(superType.isSingleClassifierType() || context .isAllowedTypeVariable(superType)) {
|
||||
assert(superType.isSingleClassifierType() || state .isAllowedTypeVariable(superType)) {
|
||||
"Not singleClassifierType superType: $superType"
|
||||
}
|
||||
}
|
||||
|
||||
if (!AbstractNullabilityChecker.isPossibleSubtype(context, subType, superType)) return false
|
||||
if (!AbstractNullabilityChecker.isPossibleSubtype(state, subType, superType)) return false
|
||||
|
||||
checkSubtypeForIntegerLiteralType(context, subType.lowerBoundIfFlexible(), superType.upperBoundIfFlexible())?.let {
|
||||
context.addSubtypeConstraint(subType, superType)
|
||||
checkSubtypeForIntegerLiteralType(state, subType.lowerBoundIfFlexible(), superType.upperBoundIfFlexible())?.let {
|
||||
state.addSubtypeConstraint(subType, superType)
|
||||
return it
|
||||
}
|
||||
|
||||
@@ -339,11 +339,11 @@ object AbstractTypeChecker {
|
||||
if (areEqualTypeConstructors(subType.typeConstructor(), superConstructor) && superConstructor.parametersCount() == 0) return true
|
||||
if (superType.typeConstructor().isAnyConstructor()) return true
|
||||
|
||||
val supertypesWithSameConstructor = findCorrespondingSupertypes(context, subType, superConstructor)
|
||||
.map { context.prepareType(it).asSimpleType() ?: it }
|
||||
val supertypesWithSameConstructor = findCorrespondingSupertypes(state, subType, superConstructor)
|
||||
.map { state.prepareType(it).asSimpleType() ?: it }
|
||||
when (supertypesWithSameConstructor.size) {
|
||||
0 -> return hasNothingSupertype(context, subType) // todo Nothing & Array<Number> <: Array<String>
|
||||
1 -> return context.isSubtypeForSameConstructor(supertypesWithSameConstructor.first().asArgumentList(), superType)
|
||||
0 -> return hasNothingSupertype(state, subType) // todo Nothing & Array<Number> <: Array<String>
|
||||
1 -> return state.isSubtypeForSameConstructor(supertypesWithSameConstructor.first().asArgumentList(), superType)
|
||||
|
||||
else -> { // at least 2 supertypes with same constructors. Such case is rare
|
||||
val newArguments = ArgumentList(superConstructor.parametersCount())
|
||||
@@ -361,10 +361,10 @@ object AbstractTypeChecker {
|
||||
newArguments.add(intersection)
|
||||
}
|
||||
|
||||
if (!anyNonOutParameter && context.isSubtypeForSameConstructor(newArguments, superType)) return true
|
||||
if (!anyNonOutParameter && state.isSubtypeForSameConstructor(newArguments, superType)) return true
|
||||
|
||||
// TODO: rethink this; now components order in intersection type affects semantic due to run subtyping (which can add constraints) only until the first successful candidate
|
||||
return supertypesWithSameConstructor.any { context.isSubtypeForSameConstructor(it.asArgumentList(), superType) }
|
||||
return supertypesWithSameConstructor.any { state.isSubtypeForSameConstructor(it.asArgumentList(), superType) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,7 @@ object AbstractTypeChecker {
|
||||
return typeVariableConstructor.typeParameter?.hasRecursiveBounds(selfConstructor) == true
|
||||
}
|
||||
|
||||
fun AbstractTypeCheckerContext.isSubtypeForSameConstructor(
|
||||
fun TypeCheckerState.isSubtypeForSameConstructor(
|
||||
capturedSubArguments: TypeArgumentListMarker,
|
||||
superType: SimpleTypeMarker
|
||||
): Boolean = with(this.typeSystemContext) {
|
||||
@@ -474,12 +474,12 @@ object AbstractTypeChecker {
|
||||
}
|
||||
|
||||
private fun checkSubtypeForSpecialCases(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: SimpleTypeMarker,
|
||||
superType: SimpleTypeMarker
|
||||
): Boolean? = with(context.typeSystemContext) {
|
||||
): Boolean? = with(state.typeSystemContext) {
|
||||
if (subType.isError() || superType.isError()) {
|
||||
if (context.isErrorTypeEqualsToAnything) return true
|
||||
if (state.isErrorTypeEqualsToAnything) return true
|
||||
|
||||
if (subType.isMarkedNullable() && !superType.isMarkedNullable()) return false
|
||||
|
||||
@@ -491,10 +491,10 @@ object AbstractTypeChecker {
|
||||
}
|
||||
|
||||
if (subType.isStubTypeForBuilderInference() && superType.isStubTypeForBuilderInference())
|
||||
return isStubTypeSubtypeOfAnother(subType, superType) || context.isStubTypeEqualsToAnything
|
||||
return isStubTypeSubtypeOfAnother(subType, superType) || state.isStubTypeEqualsToAnything
|
||||
|
||||
if (subType.isStubType() || superType.isStubType())
|
||||
return context.isStubTypeEqualsToAnything
|
||||
return state.isStubTypeEqualsToAnything
|
||||
|
||||
// superType might be a definitely notNull type (see KT-42824)
|
||||
val superOriginalType = superType.asDefinitelyNotNullType()?.original() ?: superType
|
||||
@@ -508,9 +508,9 @@ object AbstractTypeChecker {
|
||||
} else {
|
||||
if (superType.isDefinitelyNotNullType()) lowerType.makeDefinitelyNotNullOrNotNull() else lowerType
|
||||
}
|
||||
when (context.getLowerCapturedTypePolicy(subType, superTypeCaptured)) {
|
||||
CHECK_ONLY_LOWER -> return isSubtypeOf(context, subType, nullableLowerType)
|
||||
CHECK_SUBTYPE_AND_LOWER -> if (isSubtypeOf(context, subType, nullableLowerType)) return true
|
||||
when (state.getLowerCapturedTypePolicy(subType, superTypeCaptured)) {
|
||||
CHECK_ONLY_LOWER -> return isSubtypeOf(state, subType, nullableLowerType)
|
||||
CHECK_SUBTYPE_AND_LOWER -> if (isSubtypeOf(state, subType, nullableLowerType)) return true
|
||||
SKIP_LOWER -> Unit
|
||||
}
|
||||
}
|
||||
@@ -519,7 +519,7 @@ object AbstractTypeChecker {
|
||||
if (superTypeConstructor.isIntersection()) {
|
||||
assert(!superType.isMarkedNullable()) { "Intersection type should not be marked nullable!: $superType" }
|
||||
|
||||
return superTypeConstructor.supertypes().all { isSubtypeOf(context, subType, it) }
|
||||
return superTypeConstructor.supertypes().all { isSubtypeOf(state, subType, it) }
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -532,7 +532,7 @@ object AbstractTypeChecker {
|
||||
if (subType is CapturedTypeMarker
|
||||
|| (subTypeConstructor.isIntersection() && subTypeConstructor.supertypes().all { it is CapturedTypeMarker })) {
|
||||
val typeParameter =
|
||||
context.typeSystemContext.getTypeParameterForArgumentInBaseIfItEqualToTarget(baseType = superType, targetType = subType)
|
||||
state.typeSystemContext.getTypeParameterForArgumentInBaseIfItEqualToTarget(baseType = superType, targetType = subType)
|
||||
if (typeParameter != null && typeParameter.hasRecursiveBounds(superType.typeConstructor())) {
|
||||
return true
|
||||
}
|
||||
@@ -561,10 +561,10 @@ object AbstractTypeChecker {
|
||||
}
|
||||
|
||||
private fun collectAllSupertypesWithGivenTypeConstructor(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: SimpleTypeMarker,
|
||||
superConstructor: TypeConstructorMarker
|
||||
): List<SimpleTypeMarker> = with(context.typeSystemContext) {
|
||||
): List<SimpleTypeMarker> = with(state.typeSystemContext) {
|
||||
subType.fastCorrespondingSupertypes(superConstructor)?.let {
|
||||
return it
|
||||
}
|
||||
@@ -580,7 +580,7 @@ object AbstractTypeChecker {
|
||||
|
||||
val result: MutableList<SimpleTypeMarker> = SmartList()
|
||||
|
||||
context.anySupertype(subType, { false }) {
|
||||
state.anySupertype(subType, { false }) {
|
||||
|
||||
val current = captureFromArguments(it, CaptureStatus.FOR_SUBTYPING) ?: it
|
||||
|
||||
@@ -593,7 +593,7 @@ object AbstractTypeChecker {
|
||||
SupertypesPolicy.LowerIfFlexible
|
||||
}
|
||||
else -> {
|
||||
context.substitutionSupertypePolicy(current)
|
||||
state.substitutionSupertypePolicy(current)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -602,11 +602,11 @@ object AbstractTypeChecker {
|
||||
}
|
||||
|
||||
private fun collectAndFilter(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
classType: SimpleTypeMarker,
|
||||
constructor: TypeConstructorMarker
|
||||
) =
|
||||
selectOnlyPureKotlinSupertypes(context, collectAllSupertypesWithGivenTypeConstructor(context, classType, constructor))
|
||||
selectOnlyPureKotlinSupertypes(state, collectAllSupertypesWithGivenTypeConstructor(state, classType, constructor))
|
||||
|
||||
|
||||
/**
|
||||
@@ -620,9 +620,9 @@ object AbstractTypeChecker {
|
||||
* More tests: javaAndKotlinSuperType & purelyImplementedCollection folder
|
||||
*/
|
||||
private fun selectOnlyPureKotlinSupertypes(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
supertypes: List<SimpleTypeMarker>
|
||||
): List<SimpleTypeMarker> = with(context.typeSystemContext) {
|
||||
): List<SimpleTypeMarker> = with(state.typeSystemContext) {
|
||||
if (supertypes.size < 2) return supertypes
|
||||
|
||||
val allPureSupertypes = supertypes.filter {
|
||||
@@ -635,22 +635,22 @@ object AbstractTypeChecker {
|
||||
// nullability was checked earlier via nullabilityChecker
|
||||
// should be used only if you really sure that it is correct
|
||||
fun findCorrespondingSupertypes(
|
||||
context: AbstractTypeCheckerContext,
|
||||
state: TypeCheckerState,
|
||||
subType: SimpleTypeMarker,
|
||||
superConstructor: TypeConstructorMarker
|
||||
): List<SimpleTypeMarker> = with(context.typeSystemContext) {
|
||||
): List<SimpleTypeMarker> = with(state.typeSystemContext) {
|
||||
if (subType.isClassType()) {
|
||||
return collectAndFilter(context, subType, superConstructor)
|
||||
return collectAndFilter(state, subType, superConstructor)
|
||||
}
|
||||
|
||||
// i.e. superType is not a classType
|
||||
if (!superConstructor.isClassTypeConstructor() && !superConstructor.isIntegerLiteralTypeConstructor()) {
|
||||
return collectAllSupertypesWithGivenTypeConstructor(context, subType, superConstructor)
|
||||
return collectAllSupertypesWithGivenTypeConstructor(state, subType, superConstructor)
|
||||
}
|
||||
|
||||
// todo add tests
|
||||
val classTypeSupertypes = SmartList<SimpleTypeMarker>()
|
||||
context.anySupertype(subType, { false }) {
|
||||
state.anySupertype(subType, { false }) {
|
||||
if (it.isClassType()) {
|
||||
classTypeSupertypes.add(it)
|
||||
SupertypesPolicy.None
|
||||
@@ -659,42 +659,42 @@ object AbstractTypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
return classTypeSupertypes.flatMap { collectAndFilter(context, it, superConstructor) }
|
||||
return classTypeSupertypes.flatMap { collectAndFilter(state, it, superConstructor) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object AbstractNullabilityChecker {
|
||||
// this method checks only nullability
|
||||
fun isPossibleSubtype(context: AbstractTypeCheckerContext, subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean =
|
||||
runIsPossibleSubtype(context, subType, superType)
|
||||
fun isPossibleSubtype(state: TypeCheckerState, subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean =
|
||||
runIsPossibleSubtype(state, subType, superType)
|
||||
|
||||
fun isSubtypeOfAny(context: TypeCheckerProviderContext, type: KotlinTypeMarker): Boolean =
|
||||
AbstractNullabilityChecker.isSubtypeOfAny(
|
||||
context.newBaseTypeCheckerContext(
|
||||
context.newTypeCheckerState(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
),
|
||||
type
|
||||
)
|
||||
|
||||
fun isSubtypeOfAny(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): Boolean =
|
||||
with(context.typeSystemContext) {
|
||||
context.hasNotNullSupertype(type.lowerBoundIfFlexible(), SupertypesPolicy.LowerIfFlexible)
|
||||
fun isSubtypeOfAny(state: TypeCheckerState, type: KotlinTypeMarker): Boolean =
|
||||
with(state.typeSystemContext) {
|
||||
state.hasNotNullSupertype(type.lowerBoundIfFlexible(), SupertypesPolicy.LowerIfFlexible)
|
||||
}
|
||||
|
||||
private fun runIsPossibleSubtype(context: AbstractTypeCheckerContext, subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean =
|
||||
with(context.typeSystemContext) {
|
||||
private fun runIsPossibleSubtype(state: TypeCheckerState, subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean =
|
||||
with(state.typeSystemContext) {
|
||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||
// it makes for case String? & Any <: String
|
||||
assert(
|
||||
subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || context.isAllowedTypeVariable(
|
||||
subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || state.isAllowedTypeVariable(
|
||||
subType
|
||||
)
|
||||
) {
|
||||
"Not singleClassifierType and not intersection subType: $subType"
|
||||
}
|
||||
assert(superType.isSingleClassifierType() || context.isAllowedTypeVariable(superType)) {
|
||||
assert(superType.isSingleClassifierType() || state.isAllowedTypeVariable(superType)) {
|
||||
"Not singleClassifierType superType: $superType"
|
||||
}
|
||||
}
|
||||
@@ -709,13 +709,13 @@ object AbstractNullabilityChecker {
|
||||
if (subType is CapturedTypeMarker && subType.isProjectionNotNull()) return true
|
||||
|
||||
// i.e. subType is not-nullable
|
||||
if (context.hasNotNullSupertype(subType, SupertypesPolicy.LowerIfFlexible)) return true
|
||||
if (state.hasNotNullSupertype(subType, SupertypesPolicy.LowerIfFlexible)) return true
|
||||
|
||||
// i.e. subType hasn't not-null supertype and isn't definitely not-null, but superType is definitely not-null
|
||||
if (superType.isDefinitelyNotNullType()) return false
|
||||
|
||||
// i.e subType hasn't not-null supertype, but superType has
|
||||
if (context.hasNotNullSupertype(superType, SupertypesPolicy.UpperIfFlexible)) return false
|
||||
if (state.hasNotNullSupertype(superType, SupertypesPolicy.UpperIfFlexible)) return false
|
||||
|
||||
// both superType and subType hasn't not-null supertype and are not definitely not null.
|
||||
|
||||
@@ -731,10 +731,10 @@ object AbstractNullabilityChecker {
|
||||
// classType cannot has special type in supertype list
|
||||
if (subType.isClassType()) return false
|
||||
|
||||
return hasPathByNotMarkedNullableNodes(context, subType, superType.typeConstructor())
|
||||
return hasPathByNotMarkedNullableNodes(state, subType, superType.typeConstructor())
|
||||
}
|
||||
|
||||
fun AbstractTypeCheckerContext.hasNotNullSupertype(type: SimpleTypeMarker, supertypesPolicy: SupertypesPolicy) =
|
||||
fun TypeCheckerState.hasNotNullSupertype(type: SimpleTypeMarker, supertypesPolicy: SupertypesPolicy) =
|
||||
with(typeSystemContext) {
|
||||
anySupertype(type, {
|
||||
(it.isClassType() && !it.isMarkedNullable()) || it.isDefinitelyNotNullType()
|
||||
@@ -745,24 +745,24 @@ object AbstractNullabilityChecker {
|
||||
|
||||
fun TypeCheckerProviderContext.hasPathByNotMarkedNullableNodes(start: SimpleTypeMarker, end: TypeConstructorMarker) =
|
||||
hasPathByNotMarkedNullableNodes(
|
||||
newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true), start, end
|
||||
newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true), start, end
|
||||
)
|
||||
|
||||
fun hasPathByNotMarkedNullableNodes(context: AbstractTypeCheckerContext, start: SimpleTypeMarker, end: TypeConstructorMarker) =
|
||||
with(context.typeSystemContext) {
|
||||
context.anySupertype(
|
||||
fun hasPathByNotMarkedNullableNodes(state: TypeCheckerState, start: SimpleTypeMarker, end: TypeConstructorMarker) =
|
||||
with(state.typeSystemContext) {
|
||||
state.anySupertype(
|
||||
start,
|
||||
{ isApplicableAsEndNode(context, it, end) },
|
||||
{ isApplicableAsEndNode(state, it, end) },
|
||||
{ if (it.isMarkedNullable()) SupertypesPolicy.None else SupertypesPolicy.LowerIfFlexible }
|
||||
)
|
||||
}
|
||||
|
||||
private fun isApplicableAsEndNode(context: AbstractTypeCheckerContext, type: SimpleTypeMarker, end: TypeConstructorMarker): Boolean =
|
||||
with(context.typeSystemContext) {
|
||||
private fun isApplicableAsEndNode(state: TypeCheckerState, type: SimpleTypeMarker, end: TypeConstructorMarker): Boolean =
|
||||
with(state.typeSystemContext) {
|
||||
if (type.isNothing()) return true
|
||||
if (type.isMarkedNullable()) return false
|
||||
|
||||
if (context.isStubTypeEqualsToAnything && type.isStubType()) return true
|
||||
if (state.isStubTypeEqualsToAnything && type.isStubType()) return true
|
||||
|
||||
return areEqualTypeConstructors(type.typeConstructor(), end)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types.model
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
@@ -91,14 +91,14 @@ interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory, that constructs [AbstractTypeCheckerContext], which defines type-checker behaviour
|
||||
* Factory, that constructs [TypeCheckerState], which defines type-checker behaviour
|
||||
* Implementation is recommended to be [TypeSystemContext]
|
||||
*/
|
||||
interface TypeCheckerProviderContext {
|
||||
fun newBaseTypeCheckerContext(
|
||||
fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): AbstractTypeCheckerContext
|
||||
): TypeCheckerState
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,11 +107,11 @@ interface TypeCheckerProviderContext {
|
||||
interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeFactoryContext, TypeCheckerProviderContext {
|
||||
|
||||
fun KotlinTypeMarker.anySuperTypeConstructor(predicate: (TypeConstructorMarker) -> Boolean) =
|
||||
newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
.anySupertype(
|
||||
lowerBoundIfFlexible(),
|
||||
{ predicate(it.typeConstructor()) },
|
||||
{ AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible }
|
||||
{ TypeCheckerState.SupertypesPolicy.LowerIfFlexible }
|
||||
)
|
||||
|
||||
fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.*;
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker;
|
||||
import org.jetbrains.kotlin.utils.SmartSet;
|
||||
|
||||
import java.util.*;
|
||||
@@ -309,7 +308,7 @@ public class OverridingUtil {
|
||||
return OverrideCompatibilityInfo.conflict("Type parameter number mismatch");
|
||||
}
|
||||
|
||||
Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);
|
||||
Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);
|
||||
|
||||
for (int i = 0; i < superTypeParameters.size(); i++) {
|
||||
if (!areTypeParametersEquivalent(
|
||||
@@ -385,7 +384,7 @@ public class OverridingUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> createTypeChecker(
|
||||
private Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> createTypeChecker(
|
||||
@NotNull List<TypeParameterDescriptor> firstParameters,
|
||||
@NotNull List<TypeParameterDescriptor> secondParameters
|
||||
) {
|
||||
@@ -393,19 +392,19 @@ public class OverridingUtil {
|
||||
"Should be the same number of type parameters: " + firstParameters + " vs " + secondParameters;
|
||||
|
||||
NewKotlinTypeCheckerImpl typeChecker = new NewKotlinTypeCheckerImpl(kotlinTypeRefiner, KotlinTypePreparator.Default.INSTANCE);
|
||||
ClassicTypeCheckerContext context = createTypeCheckerContext(firstParameters, secondParameters);
|
||||
ClassicTypeCheckerState context = createTypeCheckerContext(firstParameters, secondParameters);
|
||||
|
||||
return new Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext>(typeChecker, context);
|
||||
return new Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState>(typeChecker, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ClassicTypeCheckerContext createTypeCheckerContext(
|
||||
private ClassicTypeCheckerState createTypeCheckerContext(
|
||||
@NotNull List<TypeParameterDescriptor> firstParameters,
|
||||
@NotNull List<TypeParameterDescriptor> secondParameters
|
||||
) {
|
||||
if (firstParameters.isEmpty()) {
|
||||
return (ClassicTypeCheckerContext) new OverridingUtilTypeSystemContext(null, equalityAxioms, kotlinTypeRefiner)
|
||||
.newBaseTypeCheckerContext(true, true);
|
||||
return (ClassicTypeCheckerState) new OverridingUtilTypeSystemContext(null, equalityAxioms, kotlinTypeRefiner)
|
||||
.newTypeCheckerState(true, true);
|
||||
}
|
||||
|
||||
Map<TypeConstructor, TypeConstructor> matchingTypeConstructors = new HashMap<TypeConstructor, TypeConstructor>();
|
||||
@@ -413,8 +412,8 @@ public class OverridingUtil {
|
||||
matchingTypeConstructors.put(firstParameters.get(i).getTypeConstructor(), secondParameters.get(i).getTypeConstructor());
|
||||
}
|
||||
|
||||
return (ClassicTypeCheckerContext) new OverridingUtilTypeSystemContext(matchingTypeConstructors, equalityAxioms, kotlinTypeRefiner)
|
||||
.newBaseTypeCheckerContext(true, true);
|
||||
return (ClassicTypeCheckerState) new OverridingUtilTypeSystemContext(matchingTypeConstructors, equalityAxioms, kotlinTypeRefiner)
|
||||
.newTypeCheckerState(true, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -436,7 +435,7 @@ public class OverridingUtil {
|
||||
private boolean areTypesEquivalent(
|
||||
@NotNull KotlinType typeInSuper,
|
||||
@NotNull KotlinType typeInSub,
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> typeChecker
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> typeChecker
|
||||
) {
|
||||
boolean bothErrors = KotlinTypeKt.isError(typeInSuper) && KotlinTypeKt.isError(typeInSub);
|
||||
if (bothErrors) return true;
|
||||
@@ -447,7 +446,7 @@ public class OverridingUtil {
|
||||
private boolean areTypeParametersEquivalent(
|
||||
@NotNull TypeParameterDescriptor superTypeParameter,
|
||||
@NotNull TypeParameterDescriptor subTypeParameter,
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> typeChecker
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> typeChecker
|
||||
) {
|
||||
List<KotlinType> superBounds = superTypeParameter.getUpperBounds();
|
||||
List<KotlinType> subBounds = new ArrayList<KotlinType>(subTypeParameter.getUpperBounds());
|
||||
@@ -585,7 +584,7 @@ public class OverridingUtil {
|
||||
|
||||
if (!isVisibilityMoreSpecific(a, b)) return false;
|
||||
|
||||
Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> checker =
|
||||
Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> checker =
|
||||
DEFAULT.createTypeChecker(a.getTypeParameters(), b.getTypeParameters());
|
||||
|
||||
if (a instanceof FunctionDescriptor) {
|
||||
@@ -642,7 +641,7 @@ public class OverridingUtil {
|
||||
@NotNull KotlinType aReturnType,
|
||||
@NotNull CallableDescriptor b,
|
||||
@NotNull KotlinType bReturnType,
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerContext> typeChecker
|
||||
@NotNull Pair<NewKotlinTypeCheckerImpl, ClassicTypeCheckerState> typeChecker
|
||||
) {
|
||||
return typeChecker.getFirst().isSubtypeOf(typeChecker.getSecond(), aReturnType.unwrap(), bReturnType.unwrap());
|
||||
}
|
||||
|
||||
+6
-6
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerState
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
@@ -25,11 +25,11 @@ class OverridingUtilTypeSystemContext(
|
||||
return super.areEqualTypeConstructors(c1, c2) || areEqualTypeConstructorsByAxioms(c1, c2)
|
||||
}
|
||||
|
||||
override fun newBaseTypeCheckerContext(
|
||||
override fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): AbstractTypeCheckerContext {
|
||||
return ClassicTypeCheckerContext(
|
||||
): TypeCheckerState {
|
||||
return ClassicTypeCheckerState(
|
||||
errorTypesEqualToAnything,
|
||||
stubTypesEqualToAnything,
|
||||
allowedTypeVariable = true,
|
||||
@@ -45,4 +45,4 @@ class OverridingUtilTypeSystemContext(
|
||||
val img2 = matchingTypeConstructors[b]
|
||||
return img1 != null && img1 == b || img2 != null && img2 == a
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,14 +21,14 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
|
||||
open class ClassicTypeCheckerContext(
|
||||
open class ClassicTypeCheckerState(
|
||||
val errorTypeEqualsToAnything: Boolean,
|
||||
val stubTypeEqualsToAnything: Boolean = true,
|
||||
val allowedTypeVariable: Boolean = true,
|
||||
val kotlinTypeRefiner: KotlinTypeRefiner = KotlinTypeRefiner.Default,
|
||||
val kotlinTypePreparator: KotlinTypePreparator = KotlinTypePreparator.Default,
|
||||
override val typeSystemContext: ClassicTypeSystemContext = SimpleClassicTypeSystemContext
|
||||
) : AbstractTypeCheckerContext() {
|
||||
) : TypeCheckerState() {
|
||||
|
||||
@OptIn(TypeRefinement::class)
|
||||
override fun refineType(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||
@@ -59,7 +59,7 @@ open class ClassicTypeCheckerContext(
|
||||
val substitutor = TypeConstructorSubstitution.create(type).buildSubstitutor()
|
||||
|
||||
return object : SupertypesPolicy.DoCustomTransform() {
|
||||
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
return substitutor.safeSubstitute(
|
||||
type.lowerBoundIfFlexible() as KotlinType,
|
||||
Variance.INVARIANT
|
||||
@@ -388,11 +388,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
}
|
||||
|
||||
|
||||
override fun newBaseTypeCheckerContext(
|
||||
override fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): AbstractTypeCheckerContext {
|
||||
return ClassicTypeCheckerContext(errorTypesEqualToAnything, stubTypesEqualToAnything, typeSystemContext = this)
|
||||
): TypeCheckerState {
|
||||
return ClassicTypeCheckerState(errorTypesEqualToAnything, stubTypesEqualToAnything, typeSystemContext = this)
|
||||
}
|
||||
|
||||
override fun nullableNothingType(): SimpleTypeMarker {
|
||||
|
||||
@@ -21,14 +21,10 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructorImpl
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasNotNullSupertype
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext.SupertypesPolicy
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy
|
||||
|
||||
object SimpleClassicTypeSystemContext : ClassicTypeSystemContext
|
||||
|
||||
@@ -53,10 +49,10 @@ object StrictEqualityTypeChecker {
|
||||
|
||||
object ErrorTypesAreEqualToAnything : KotlinTypeChecker {
|
||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerContext(true).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) }
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerState(true).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) }
|
||||
|
||||
override fun equalTypes(a: KotlinType, b: KotlinType): Boolean =
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerContext(true).equalTypes(a.unwrap(), b.unwrap()) }
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerState(true).equalTypes(a.unwrap(), b.unwrap()) }
|
||||
}
|
||||
|
||||
interface NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
@@ -77,21 +73,21 @@ class NewKotlinTypeCheckerImpl(
|
||||
override val overridingUtil: OverridingUtil = OverridingUtil.createWithTypeRefiner(kotlinTypeRefiner)
|
||||
|
||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
||||
ClassicTypeCheckerContext(
|
||||
ClassicTypeCheckerState(
|
||||
true, kotlinTypeRefiner = kotlinTypeRefiner, kotlinTypePreparator = kotlinTypePreparator
|
||||
).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) // todo fix flag errorTypeEqualsToAnything
|
||||
|
||||
override fun equalTypes(a: KotlinType, b: KotlinType): Boolean =
|
||||
ClassicTypeCheckerContext(
|
||||
ClassicTypeCheckerState(
|
||||
false, kotlinTypeRefiner = kotlinTypeRefiner, kotlinTypePreparator = kotlinTypePreparator
|
||||
).equalTypes(a.unwrap(), b.unwrap())
|
||||
|
||||
fun ClassicTypeCheckerContext.equalTypes(a: UnwrappedType, b: UnwrappedType): Boolean {
|
||||
return AbstractTypeChecker.equalTypes(this as AbstractTypeCheckerContext, a, b)
|
||||
fun ClassicTypeCheckerState.equalTypes(a: UnwrappedType, b: UnwrappedType): Boolean {
|
||||
return AbstractTypeChecker.equalTypes(this as TypeCheckerState, a, b)
|
||||
}
|
||||
|
||||
fun ClassicTypeCheckerContext.isSubtypeOf(subType: UnwrappedType, superType: UnwrappedType): Boolean {
|
||||
return AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, subType, superType)
|
||||
fun ClassicTypeCheckerState.isSubtypeOf(subType: UnwrappedType, superType: UnwrappedType): Boolean {
|
||||
return AbstractTypeChecker.isSubtypeOf(this as TypeCheckerState, subType, superType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,18 +95,18 @@ object NullabilityChecker {
|
||||
|
||||
fun isSubtypeOfAny(type: UnwrappedType): Boolean =
|
||||
SimpleClassicTypeSystemContext
|
||||
.newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
.newTypeCheckerState(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)
|
||||
.hasNotNullSupertype(type.lowerIfFlexible(), SupertypesPolicy.LowerIfFlexible)
|
||||
}
|
||||
|
||||
fun UnwrappedType.hasSupertypeWithGivenTypeConstructor(typeConstructor: TypeConstructor) =
|
||||
ClassicTypeCheckerContext(false).anySupertype(lowerIfFlexible(), {
|
||||
ClassicTypeCheckerState(false).anySupertype(lowerIfFlexible(), {
|
||||
require(it is SimpleType)
|
||||
it.constructor == typeConstructor
|
||||
}, { SupertypesPolicy.LowerIfFlexible })
|
||||
|
||||
fun UnwrappedType.anySuperTypeConstructor(predicate: (TypeConstructor) -> Boolean) =
|
||||
ClassicTypeCheckerContext(false).anySupertype(lowerIfFlexible(), {
|
||||
ClassicTypeCheckerState(false).anySupertype(lowerIfFlexible(), {
|
||||
require(it is SimpleType)
|
||||
predicate(it.constructor)
|
||||
}, { SupertypesPolicy.LowerIfFlexible })
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtStarProjectionTypeArgument
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtTypeArgument
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerState
|
||||
import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.diagnostics.KT_DIAGNOSTIC_CONVERTER
|
||||
@@ -62,7 +62,7 @@ internal interface KtFirAnalysisSessionComponent {
|
||||
}
|
||||
}
|
||||
|
||||
fun createTypeCheckerContext() = ConeTypeCheckerContext(
|
||||
fun createTypeCheckerContext() = ConeTypeCheckerState(
|
||||
isErrorTypeEqualsToAnything = true,
|
||||
isStubTypeEqualsToAnything = true,
|
||||
analysisSession.firResolveState.rootModuleSession.typeContext //TODO use correct session here
|
||||
|
||||
+2
-3
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.types.KtFirType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
|
||||
internal class KtFirSubtypingComponent(
|
||||
override val analysisSession: KtFirAnalysisSession,
|
||||
@@ -24,7 +23,7 @@ internal class KtFirSubtypingComponent(
|
||||
check(first is KtFirType)
|
||||
check(second is KtFirType)
|
||||
return AbstractTypeChecker.equalTypes(
|
||||
createTypeCheckerContext() as AbstractTypeCheckerContext,
|
||||
createTypeCheckerContext(),
|
||||
first.coneType,
|
||||
second.coneType
|
||||
)
|
||||
@@ -35,7 +34,7 @@ internal class KtFirSubtypingComponent(
|
||||
check(subType is KtFirType)
|
||||
check(superType is KtFirType)
|
||||
return AbstractTypeChecker.isSubtypeOf(
|
||||
createTypeCheckerContext() as AbstractTypeCheckerContext,
|
||||
createTypeCheckerContext(),
|
||||
subType.coneType,
|
||||
superType.coneType
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user