Abstract NewInference & related from KotlinType

Cleanup TypeConstructors & KotlinTypes in VariableFixationFinder
Cleanup TypeConstructors & KotlinTypes in TypeVariableDirectionCalculator
Cleanup KotlinTypes in TypeCheckerContext for ConstraintSystem
Cleanup KotlinTypes in NewCommonSuperTypeCalculator
Cleanup KotlinTypes in TypeApproximator
Cleanup type substitution
Cleanup NewTypeVariable
Cleanup StubType
Cleanup TypeCheckerContext creation, extract common supertype context
Provide TypeSystemInferenceExtensionContext via dependency injection
This commit is contained in:
Simon Ogorodnik
2019-02-18 20:19:33 +03:00
parent 0ffded5bac
commit 3998e842f1
47 changed files with 1347 additions and 661 deletions
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.model.StubTypeMarker
// This type is used as a stub for postponed type variables, which are important for coroutine inference
class StubType(
@@ -16,7 +17,7 @@ class StubType(
ErrorUtils.createErrorTypeConstructor("Constructor for non fixed type: $originalTypeVariable"),
override val memberScope: MemberScope =
ErrorUtils.createErrorScope("Scope for non fixed type: $originalTypeVariable")
) : SimpleType() {
) : SimpleType(), StubTypeMarker {
override val arguments: List<TypeProjection>
get() = emptyList()
@@ -24,13 +24,9 @@ import org.jetbrains.kotlin.types.model.SimpleTypeMarker
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
open class ClassicTypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowedTypeVariable: Boolean = true) : ClassicTypeSystemContext, AbstractTypeCheckerContext() {
override fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker {
@Suppress("UNCHECKED_CAST")
return org.jetbrains.kotlin.types.checker.intersectTypes(types as List<UnwrappedType>)
}
override fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
return super.prepareType(transformToNewType((type as KotlinType).unwrap()))
return transformToNewType((type as KotlinType).unwrap())
}
override val isErrorTypeEqualsToAnything: Boolean
@@ -54,22 +50,26 @@ open class ClassicTypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val
}
override fun substitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy.DoCustomTransform {
require(type is SimpleType, type::errorMessage)
return classicSubstitutionSupertypePolicy(type)
}
val substitutor = TypeConstructorSubstitution.create(type).buildSubstitutor()
override val KotlinTypeMarker.isAllowedTypeVariable: Boolean get() = this is UnwrappedType && allowedTypeVariable && constructor is NewTypeVariableConstructor
return object : SupertypesPolicy.DoCustomTransform() {
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker {
return substitutor.safeSubstitute(
type.lowerBoundIfFlexible() as KotlinType,
Variance.INVARIANT
).asSimpleType()!!
companion object {
fun ClassicTypeSystemContext.classicSubstitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy.DoCustomTransform {
require(type is SimpleType, type::errorMessage)
val substitutor = TypeConstructorSubstitution.create(type).buildSubstitutor()
return object : SupertypesPolicy.DoCustomTransform() {
override fun transformType(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): SimpleTypeMarker {
return substitutor.safeSubstitute(
type.lowerBoundIfFlexible() as KotlinType,
Variance.INVARIANT
).asSimpleType()!!
}
}
}
}
override val KotlinTypeMarker.isAllowedTypeVariable: Boolean get() = this is UnwrappedType && allowedTypeVariable && constructor is NewTypeVariableConstructor
}
private fun Any.errorMessage(): String {
@@ -8,14 +8,18 @@ package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation
import org.jetbrains.kotlin.resolve.descriptorUtil.hasNoInferAnnotation
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.model.CaptureStatus
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.contains
interface ClassicTypeSystemContext : TypeSystemContext {
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
override fun TypeConstructorMarker.isDenotable(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return this.isDenotable
@@ -134,6 +138,13 @@ interface ClassicTypeSystemContext : TypeSystemContext {
}
private fun TypeVariance.convertVariance(): Variance {
return when (this) {
TypeVariance.INV -> Variance.INVARIANT
TypeVariance.IN -> Variance.IN_VARIANCE
TypeVariance.OUT -> Variance.OUT_VARIANCE
}
}
override fun TypeArgumentMarker.getType(): KotlinTypeMarker {
require(this is TypeProjection, this::errorMessage)
@@ -220,6 +231,11 @@ interface ClassicTypeSystemContext : TypeSystemContext {
return this.asTypeProjection()
}
override fun TypeConstructorMarker.isUnitTypeConstructor(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return KotlinBuiltIns.isTypeConstructorForGivenClass(this, FQ_NAMES.unit)
}
/**
*
* SingleClassifierType is one of the following types:
@@ -240,6 +256,231 @@ interface ClassicTypeSystemContext : TypeSystemContext {
require(this is KotlinType, this::errorMessage)
return typeConstructor().isNothingConstructor() && !TypeUtils.isNullableType(this)
}
override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean {
require(this is KotlinType, this::errorMessage)
return containsInternal(this, predicate)
}
override fun SimpleTypeMarker.typeDepth(): Int {
require(this is SimpleType, this::errorMessage)
return this.typeDepthInternal()
}
override fun KotlinTypeMarker.typeDepth(): Int {
require(this is UnwrappedType, this::errorMessage)
return this.typeDepthInternal()
}
override fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker {
@Suppress("UNCHECKED_CAST")
return org.jetbrains.kotlin.types.checker.intersectTypes(types as List<UnwrappedType>)
}
override fun intersectTypes(types: List<SimpleTypeMarker>): SimpleTypeMarker {
@Suppress("UNCHECKED_CAST")
return org.jetbrains.kotlin.types.checker.intersectTypes(types as List<SimpleType>)
}
override fun Collection<KotlinTypeMarker>.singleBestRepresentative(): KotlinTypeMarker? {
@Suppress("UNCHECKED_CAST")
return singleBestRepresentative(this as Collection<KotlinType>)
}
override fun KotlinTypeMarker.isUnit(): Boolean {
require(this is UnwrappedType, this::errorMessage)
return KotlinBuiltIns.isUnit(this)
}
override fun createFlexibleType(lowerBound: SimpleTypeMarker, upperBound: SimpleTypeMarker): KotlinTypeMarker {
require(lowerBound is SimpleType, this::errorMessage)
require(upperBound is SimpleType, this::errorMessage)
return KotlinTypeFactory.flexibleType(lowerBound, upperBound)
}
override fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker {
return when (this) {
is SimpleTypeMarker -> this.withNullability(nullable)
is FlexibleTypeMarker -> createFlexibleType(lowerBound().withNullability(nullable), upperBound().withNullability(nullable))
else -> error("sealed")
}
}
override fun newBaseTypeCheckerContext(errorTypesEqualToAnything: Boolean): AbstractTypeCheckerContext {
return ClassicTypeCheckerContext(errorTypesEqualToAnything)
}
override fun nullableNothingType(): SimpleTypeMarker {
return builtIns.nullableNothingType
}
override fun nullableAnyType(): SimpleTypeMarker {
return builtIns.nullableAnyType
}
override fun nothingType(): SimpleTypeMarker {
return builtIns.nothingType
}
val builtIns: KotlinBuiltIns get() = throw UnsupportedOperationException("Not supported")
override fun KotlinTypeMarker.makeDefinitelyNotNullOrNotNull(): KotlinTypeMarker {
require(this is UnwrappedType, this::errorMessage)
return makeDefinitelyNotNullOrNotNullInternal(this)
}
override fun SimpleTypeMarker.makeSimpleTypeDefinitelyNotNullOrNotNull(): SimpleTypeMarker {
require(this is SimpleType, this::errorMessage)
return makeSimpleTypeDefinitelyNotNullOrNotNullInternal(this)
}
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
require(this is UnwrappedType, this::errorMessage)
return this.replaceAnnotations(Annotations.EMPTY)
}
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
require(this is UnwrappedType, this::errorMessage)
return hasExactInternal(this)
}
override fun KotlinTypeMarker.hasNoInferAnnotation(): Boolean {
require(this is UnwrappedType, this::errorMessage)
return hasNoInferInternal(this)
}
override fun TypeVariableMarker.freshTypeConstructor(): TypeConstructorMarker {
errorSupportedOnlyInTypeInference()
}
override fun CapturedTypeMarker.typeConstructorProjection(): TypeArgumentMarker {
require(this is NewCapturedType, this::errorMessage)
return this.constructor.projection
}
override fun KotlinTypeMarker.isNullableType(): Boolean {
require(this is KotlinType, this::errorMessage)
return TypeUtils.isNullableType(this)
}
override fun createSimpleType(
constructor: TypeConstructorMarker,
arguments: List<TypeArgumentMarker>,
nullable: Boolean
): SimpleTypeMarker {
require(constructor is TypeConstructor, constructor::errorMessage)
@Suppress("UNCHECKED_CAST")
return KotlinTypeFactory.simpleType(Annotations.EMPTY, constructor, arguments as List<TypeProjection>, nullable)
}
override fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker {
require(type is KotlinType, type::errorMessage)
return TypeProjectionImpl(variance.convertVariance(), type)
}
override fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker {
require(typeParameter is TypeParameterDescriptor, typeParameter::errorMessage)
return StarProjectionImpl(typeParameter)
}
override fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean {
require(this is UnwrappedType, this::errorMessage)
return constructor is NewTypeVariableConstructor ||
constructor.declarationDescriptor is TypeParameterDescriptor ||
this is NewCapturedType
}
override fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker {
require(this is SimpleType, this::errorMessage)
return this.replace(newArguments as List<TypeProjection>)
}
override fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
require(type is UnwrappedType, type::errorMessage)
return NewKotlinTypeChecker.transformToNewType(type)
}
override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker {
require(this is DefinitelyNotNullType, this::errorMessage)
return this.original
}
override fun createCapturedType(
constructorProjection: TypeArgumentMarker,
constructorSupertypes: List<KotlinTypeMarker>,
lowerType: KotlinTypeMarker?,
captureStatus: CaptureStatus
): CapturedTypeMarker {
errorSupportedOnlyInTypeInference()
}
override fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker {
errorSupportedOnlyInTypeInference()
}
override fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker {
errorSupportedOnlyInTypeInference()
}
override fun TypeVariableMarker.defaultType(): SimpleTypeMarker {
errorSupportedOnlyInTypeInference()
}
override fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker {
errorSupportedOnlyInTypeInference()
}
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? {
@Suppress("UNCHECKED_CAST")
explicitSupertypes as List<SimpleType>
return IntegerLiteralTypeConstructor.findCommonSuperType(explicitSupertypes)
}
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
require(this is IntegerLiteralTypeConstructor, this::errorMessage)
return this.getApproximatedType().unwrap()
}
}
private fun hasNoInferInternal(type: UnwrappedType): Boolean {
return type.hasNoInferAnnotation()
}
private fun hasExactInternal(type: UnwrappedType): Boolean {
return type.hasExactAnnotation()
}
private fun makeDefinitelyNotNullOrNotNullInternal(type: UnwrappedType): UnwrappedType {
return type.makeDefinitelyNotNullOrNotNull()
}
private fun makeSimpleTypeDefinitelyNotNullOrNotNullInternal(type: SimpleType): SimpleType {
return type.makeSimpleTypeDefinitelyNotNullOrNotNull()
}
private fun containsInternal(type: KotlinType, predicate: (KotlinTypeMarker) -> Boolean): Boolean = type.contains(predicate)
private fun singleBestRepresentative(collection: Collection<KotlinType>) = collection.singleBestRepresentative()
internal fun UnwrappedType.typeDepthInternal() =
when (this) {
is SimpleType -> typeDepthInternal()
is FlexibleType -> Math.max(lowerBound.typeDepthInternal(), upperBound.typeDepthInternal())
}
internal fun SimpleType.typeDepthInternal(): Int {
if (this is TypeUtils.SpecialType) return 0
val maxInArguments = arguments.asSequence().map {
if (it.isStarProjection) 1 else it.type.unwrap().typeDepthInternal()
}.max() ?: 0
return maxInArguments + 1
}
@@ -248,6 +489,10 @@ private inline fun Any.errorMessage(): String {
return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}"
}
private fun errorSupportedOnlyInTypeInference(): Nothing {
error("supported only in type inference context")
}
fun Variance.convertVariance(): TypeVariance {
return when (this) {
Variance.INVARIANT -> TypeVariance.INV
@@ -30,20 +30,21 @@ import org.jetbrains.kotlin.types.model.CaptureStatus
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.addToStdlib.cast
object SimpleClassicTypeSystemContext : ClassicTypeSystemContext
object StrictEqualityTypeChecker {
private val context = object : ClassicTypeSystemContext {}
/**
* String! != String & A<String!> != A<String>, also A<in Nothing> != A<out Any?>
* also A<*> != A<out Any?>
* different error types non-equals even errorTypeEqualToAnything
*/
fun strictEqualTypes(a: UnwrappedType, b: UnwrappedType): Boolean {
return AbstractStrictEqualityTypeChecker.strictEqualTypes(context, a, b)
return AbstractStrictEqualityTypeChecker.strictEqualTypes(SimpleClassicTypeSystemContext, a, b)
}
fun strictEqualTypes(a: SimpleType, b: SimpleType): Boolean {
return AbstractStrictEqualityTypeChecker.strictEqualTypes(context, a, b)
return AbstractStrictEqualityTypeChecker.strictEqualTypes(SimpleClassicTypeSystemContext, a, b)
}
}
@@ -64,11 +65,11 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
ClassicTypeCheckerContext(false).equalTypes(a.unwrap(), b.unwrap())
fun ClassicTypeCheckerContext.equalTypes(a: UnwrappedType, b: UnwrappedType): Boolean {
return AbstractTypeChecker.equalTypes(this, a, b)
return AbstractTypeChecker.equalTypes(this as AbstractTypeCheckerContext, a, b)
}
fun ClassicTypeCheckerContext.isSubtypeOf(subType: UnwrappedType, superType: UnwrappedType): Boolean {
return AbstractTypeChecker.isSubtypeOf(this, subType, superType)
return AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, subType, superType)
}
fun transformToNewType(type: SimpleType): SimpleType {
@@ -156,10 +157,9 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
object NullabilityChecker {
fun isSubtypeOfAny(type: UnwrappedType): Boolean =
ClassicTypeCheckerContext(false).hasNotNullSupertype(type.lowerIfFlexible(), SupertypesPolicy.LowerIfFlexible)
fun hasPathByNotMarkedNullableNodes(start: SimpleType, end: TypeConstructor) =
ClassicTypeCheckerContext(false).hasPathByNotMarkedNullableNodes(start, end)
SimpleClassicTypeSystemContext
.newBaseTypeCheckerContext(false)
.hasNotNullSupertype(type.lowerIfFlexible(), SupertypesPolicy.LowerIfFlexible)
}
fun UnwrappedType.hasSupertypeWithGivenTypeConstructor(typeConstructor: TypeConstructor) =
@@ -21,9 +21,7 @@ abstract class AbstractTypeCheckerContext : TypeSystemContext {
abstract fun areEqualTypeConstructors(a: TypeConstructorMarker, b: TypeConstructorMarker): Boolean
abstract fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker
open fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
override fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
return type
}
@@ -146,6 +144,15 @@ abstract class AbstractTypeCheckerContext : TypeSystemContext {
}
object AbstractTypeChecker {
fun isSubtypeOf(context: TypeCheckerProviderContext, subType: KotlinTypeMarker, superType: KotlinTypeMarker): Boolean {
return AbstractTypeChecker.isSubtypeOf(context.newBaseTypeCheckerContext(true), subType, superType)
}
fun equalTypes(context: TypeCheckerProviderContext, a: KotlinTypeMarker, b: KotlinTypeMarker): Boolean {
return AbstractTypeChecker.equalTypes(context.newBaseTypeCheckerContext(false), a, b)
}
fun isSubtypeOf(context: AbstractTypeCheckerContext, subType: KotlinTypeMarker, superType: KotlinTypeMarker): Boolean {
if (subType === superType) return true
return context.completeIsSubTypeOf(context.prepareType(subType), context.prepareType(superType))
@@ -312,7 +319,7 @@ object AbstractTypeChecker {
!type.isDynamic() && !type.isDefinitelyNotNullType() &&
type.lowerBoundIfFlexible().typeConstructor() == type.upperBoundIfFlexible().typeConstructor()
private fun effectiveVariance(declared: TypeVariance, useSite: TypeVariance): TypeVariance? {
fun effectiveVariance(declared: TypeVariance, useSite: TypeVariance): TypeVariance? {
if (declared == TypeVariance.INV) return useSite
if (useSite == TypeVariance.INV) return declared
@@ -453,6 +460,14 @@ object AbstractNullabilityChecker {
fun isPossibleSubtype(context: AbstractTypeCheckerContext, subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean =
context.runIsPossibleSubtype(subType, superType)
fun isSubtypeOfAny(context: TypeCheckerProviderContext, type: KotlinTypeMarker): Boolean =
AbstractNullabilityChecker.isSubtypeOfAny(context.newBaseTypeCheckerContext(false), type)
fun isSubtypeOfAny(context: AbstractTypeCheckerContext, type: KotlinTypeMarker): Boolean =
with(context) {
hasNotNullSupertype(type.lowerBoundIfFlexible(), SupertypesPolicy.LowerIfFlexible)
}
private fun AbstractTypeCheckerContext.runIsPossibleSubtype(subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean {
// it makes for case String? & Any <: String
assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || subType.isAllowedTypeVariable) {
@@ -501,6 +516,9 @@ object AbstractNullabilityChecker {
if (it.isMarkedNullable()) SupertypesPolicy.None else supertypesPolicy
}
fun TypeCheckerProviderContext.hasPathByNotMarkedNullableNodes(start: SimpleTypeMarker, end: TypeConstructorMarker) =
newBaseTypeCheckerContext(false).hasPathByNotMarkedNullableNodes(start, end)
fun AbstractTypeCheckerContext.hasPathByNotMarkedNullableNodes(start: SimpleTypeMarker, end: TypeConstructorMarker) =
anySupertype(start, {
it.isNotNullNothing() || (!it.isMarkedNullable() && isEqualTypeConstructors(it.typeConstructor(), end))
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.types.model
fun TypeVariableMarker.freshTypeConstructor(c: TypeSystemInferenceExtensionContext) = with(c) { freshTypeConstructor() }
fun TypeSubstitutorMarker.safeSubstitute(
c: TypeSystemInferenceExtensionContext,
type: KotlinTypeMarker
) = with(c) { safeSubstitute(type) }
fun TypeVariableMarker.defaultType(c: TypeSystemInferenceExtensionContext) = with(c) { defaultType() }
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.types.model
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
interface KotlinTypeMarker
interface TypeArgumentMarker
interface TypeConstructorMarker
@@ -17,14 +19,21 @@ interface DefinitelyNotNullTypeMarker : SimpleTypeMarker
interface FlexibleTypeMarker : KotlinTypeMarker
interface DynamicTypeMarker : FlexibleTypeMarker
interface RawTypeMarker : FlexibleTypeMarker
interface StubTypeMarker : SimpleTypeMarker
interface TypeArgumentListMarker
interface TypeVariableMarker
enum class TypeVariance {
IN,
OUT,
INV
interface TypeSubstitutorMarker
enum class TypeVariance(val presentation: String) {
IN("in"),
OUT("out"),
INV("");
override fun toString(): String = presentation
}
@@ -35,6 +44,96 @@ interface TypeSystemOptimizationContext {
fun identicalArguments(a: SimpleTypeMarker, b: SimpleTypeMarker) = false
}
interface TypeSystemBuiltInsContext {
fun nullableNothingType(): SimpleTypeMarker
fun nullableAnyType(): SimpleTypeMarker
fun nothingType(): SimpleTypeMarker
}
interface TypeSystemTypeFactoryContext {
fun createFlexibleType(lowerBound: SimpleTypeMarker, upperBound: SimpleTypeMarker): KotlinTypeMarker
fun createSimpleType(constructor: TypeConstructorMarker, arguments: List<TypeArgumentMarker>, nullable: Boolean): SimpleTypeMarker
fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker
fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker
}
interface TypeCheckerProviderContext {
fun newBaseTypeCheckerContext(errorTypesEqualToAnything: Boolean): AbstractTypeCheckerContext
}
interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeFactoryContext, TypeCheckerProviderContext {
fun KotlinTypeMarker.anySuperTypeConstructor(predicate: (TypeConstructorMarker) -> Boolean) =
newBaseTypeCheckerContext(false).anySupertype(lowerBoundIfFlexible(), {
predicate(it.typeConstructor())
}, { AbstractTypeCheckerContext.SupertypesPolicy.LowerIfFlexible })
fun KotlinTypeMarker.canHaveUndefinedNullability(): Boolean
fun SimpleTypeMarker.typeDepth(): Int
fun KotlinTypeMarker.typeDepth(): Int
fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker?
}
interface TypeSystemInferenceExtensionContextDelegate : TypeSystemInferenceExtensionContext
interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBuiltInsContext, TypeSystemCommonSuperTypesContext {
fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean
fun TypeConstructorMarker.isUnitTypeConstructor(): Boolean
fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker
fun Collection<KotlinTypeMarker>.singleBestRepresentative(): KotlinTypeMarker?
fun KotlinTypeMarker.isUnit(): Boolean
fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker
fun KotlinTypeMarker.makeDefinitelyNotNullOrNotNull(): KotlinTypeMarker
fun SimpleTypeMarker.makeSimpleTypeDefinitelyNotNullOrNotNull(): SimpleTypeMarker
fun createCapturedType(
constructorProjection: TypeArgumentMarker,
constructorSupertypes: List<KotlinTypeMarker>,
lowerType: KotlinTypeMarker?,
captureStatus: CaptureStatus
): CapturedTypeMarker
fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker
fun KotlinTypeMarker.hasExactAnnotation(): Boolean
fun KotlinTypeMarker.hasNoInferAnnotation(): Boolean
fun TypeVariableMarker.freshTypeConstructor(): TypeConstructorMarker
fun CapturedTypeMarker.typeConstructorProjection(): TypeArgumentMarker
fun KotlinTypeMarker.isNullableType(): Boolean
fun KotlinTypeMarker.isNullableAny() = this.typeConstructor().isAnyConstructor() && this.isNullableType()
fun KotlinTypeMarker.isNothing() = this.typeConstructor().isNothingConstructor() && !this.isNullableType()
fun KotlinTypeMarker.isNullableNothing() = this.typeConstructor().isNothingConstructor() && this.isNullableType()
fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker
fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker
fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker
fun TypeVariableMarker.defaultType(): SimpleTypeMarker
}
class ArgumentList(initialSize: Int) : ArrayList<TypeArgumentMarker>(initialSize), TypeArgumentListMarker
@@ -53,6 +152,8 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun FlexibleTypeMarker.lowerBound(): SimpleTypeMarker
fun SimpleTypeMarker.asCapturedType(): CapturedTypeMarker?
fun KotlinTypeMarker.isCapturedType() = asSimpleType()?.asCapturedType() != null
fun SimpleTypeMarker.asDefinitelyNotNullType(): DefinitelyNotNullTypeMarker?
fun SimpleTypeMarker.isMarkedNullable(): Boolean
fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker
@@ -66,7 +167,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
return null
}
fun SimpleTypeMarker.isStubType(): Boolean = false
fun SimpleTypeMarker.isStubType(): Boolean
fun KotlinTypeMarker.asTypeArgument(): TypeArgumentMarker
@@ -150,6 +251,13 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
* Such types can contains error types in our arguments, but type constructor isn't errorTypeConstructor
*/
fun SimpleTypeMarker.isSingleClassifierType(): Boolean
fun intersectTypes(types: List<KotlinTypeMarker>): KotlinTypeMarker
fun intersectTypes(types: List<SimpleTypeMarker>): SimpleTypeMarker
fun KotlinTypeMarker.isSimpleType() = asSimpleType() != null
fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker
}
enum class CaptureStatus {