FE approximator conf: simplify typeVariable/HandleAsTypeVariable
Related to KT-58618
This commit is contained in:
committed by
Space Team
parent
6e58ba8f33
commit
5ae3a93084
+1
-10
@@ -375,7 +375,7 @@ abstract class AbstractTypeApproximator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeConstructor is TypeVariableTypeConstructorMarker) {
|
if (typeConstructor is TypeVariableTypeConstructorMarker) {
|
||||||
return if (shouldHandleAsTypeVariable(conf, typeConstructor)) null else type.defaultResult(toSuper)
|
return if (conf.shouldKeepTypeVariableBasedType(typeConstructor, isK2)) null else type.defaultResult(toSuper)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeConstructor.isIntegerLiteralConstantTypeConstructor()) {
|
if (typeConstructor.isIntegerLiteralConstantTypeConstructor()) {
|
||||||
@@ -393,15 +393,6 @@ abstract class AbstractTypeApproximator(
|
|||||||
return approximateLocalTypes(type, conf, toSuper, depth) // simple classifier type
|
return approximateLocalTypes(type, conf, toSuper, depth) // simple classifier type
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldHandleAsTypeVariable(
|
|
||||||
conf: TypeApproximatorConfiguration,
|
|
||||||
typeConstructorMarker: TypeVariableTypeConstructorMarker,
|
|
||||||
): Boolean = when (conf.typeVariable(typeConstructorMarker)) {
|
|
||||||
TypeApproximatorConfiguration.HandleAsTypeVariable.ALWAYS -> true
|
|
||||||
TypeApproximatorConfiguration.HandleAsTypeVariable.K2_ONLY -> isK2
|
|
||||||
TypeApproximatorConfiguration.HandleAsTypeVariable.NEVER -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun approximateDefinitelyNotNullType(
|
private fun approximateDefinitelyNotNullType(
|
||||||
type: DefinitelyNotNullTypeMarker,
|
type: DefinitelyNotNullTypeMarker,
|
||||||
conf: TypeApproximatorConfiguration,
|
conf: TypeApproximatorConfiguration,
|
||||||
|
|||||||
+12
-10
@@ -38,13 +38,15 @@ open class TypeApproximatorConfiguration {
|
|||||||
*/
|
*/
|
||||||
open val anonymous = false
|
open val anonymous = false
|
||||||
|
|
||||||
internal enum class HandleAsTypeVariable {
|
/**
|
||||||
ALWAYS,
|
* This function determines the approximator behavior if a type variable based type is encountered.
|
||||||
K2_ONLY,
|
*
|
||||||
NEVER
|
* @param marker type variable encountered
|
||||||
}
|
* @param isK2 true for K2 compiler, false for K1 compiler
|
||||||
|
* @return true if the type variable based type should be kept, false if it should be approximated
|
||||||
|
*/
|
||||||
|
internal open fun shouldKeepTypeVariableBasedType(marker: TypeVariableTypeConstructorMarker, isK2: Boolean): Boolean = false
|
||||||
|
|
||||||
internal open val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable = { HandleAsTypeVariable.NEVER }
|
|
||||||
open fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean =
|
open fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean =
|
||||||
true // false means that this type we can leave as is
|
true // false means that this type we can leave as is
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ open class TypeApproximatorConfiguration {
|
|||||||
override val integerLiteralConstantType: Boolean get() = true
|
override val integerLiteralConstantType: Boolean get() = true
|
||||||
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
||||||
|
|
||||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.K2_ONLY }
|
override fun shouldKeepTypeVariableBasedType(marker: TypeVariableTypeConstructorMarker, isK2: Boolean): Boolean = isK2
|
||||||
}
|
}
|
||||||
|
|
||||||
open class PublicDeclaration(override val localTypes: Boolean, override val anonymous: Boolean) : AllFlexibleSameValue() {
|
open class PublicDeclaration(override val localTypes: Boolean, override val anonymous: Boolean) : AllFlexibleSameValue() {
|
||||||
@@ -73,7 +75,7 @@ open class TypeApproximatorConfiguration {
|
|||||||
override val integerLiteralConstantType: Boolean get() = true
|
override val integerLiteralConstantType: Boolean get() = true
|
||||||
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
||||||
|
|
||||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.K2_ONLY }
|
override fun shouldKeepTypeVariableBasedType(marker: TypeVariableTypeConstructorMarker, isK2: Boolean): Boolean = isK2
|
||||||
|
|
||||||
object SaveAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = false)
|
object SaveAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = false)
|
||||||
object ApproximateAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = true)
|
object ApproximateAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = true)
|
||||||
@@ -89,7 +91,7 @@ open class TypeApproximatorConfiguration {
|
|||||||
approximatedCapturedStatus != null && type.captureStatus(ctx) == approximatedCapturedStatus
|
approximatedCapturedStatus != null && type.captureStatus(ctx) == approximatedCapturedStatus
|
||||||
|
|
||||||
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
||||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.ALWAYS }
|
override fun shouldKeepTypeVariableBasedType(marker: TypeVariableTypeConstructorMarker, isK2: Boolean): Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
object IncorporationConfiguration : AbstractCapturedTypesApproximation(CaptureStatus.FOR_INCORPORATION)
|
object IncorporationConfiguration : AbstractCapturedTypesApproximation(CaptureStatus.FOR_INCORPORATION)
|
||||||
@@ -118,7 +120,7 @@ open class TypeApproximatorConfiguration {
|
|||||||
override val integerLiteralConstantType: Boolean get() = true
|
override val integerLiteralConstantType: Boolean get() = true
|
||||||
override val allFlexible: Boolean get() = true
|
override val allFlexible: Boolean get() = true
|
||||||
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
||||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.ALWAYS }
|
override fun shouldKeepTypeVariableBasedType(marker: TypeVariableTypeConstructorMarker, isK2: Boolean): Boolean = true
|
||||||
override val errorType: Boolean get() = true
|
override val errorType: Boolean get() = true
|
||||||
|
|
||||||
override fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean = false
|
override fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean = false
|
||||||
|
|||||||
Reference in New Issue
Block a user