Drop isErrorTypeAllowed flag from type system context

The flag was used exclusively during calculation of common super type.
This change relies on assumption, that common super type is
NOT calculated in IR type system context.
This commit is contained in:
Pavel Kirpichenkov
2020-07-21 18:24:50 +03:00
parent 710659324c
commit 1ef17c6f3a
6 changed files with 6 additions and 15 deletions
@@ -25,8 +25,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
val symbolProvider: FirSymbolProvider get() = session.firSymbolProvider
override val isErrorTypeAllowed: Boolean get() = false
override fun nullableNothingType(): SimpleTypeMarker {
return session.builtinTypes.nullableNothingType.type//StandardClassIds.Nothing(symbolProvider).constructType(emptyArray(), true)
}
@@ -35,8 +35,6 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
val irBuiltIns: IrBuiltIns
override val isErrorTypeAllowed: Boolean get() = true
override fun KotlinTypeMarker.asSimpleType() = this as? SimpleTypeMarker
override fun KotlinTypeMarker.asFlexibleType() = this as? IrDynamicType
@@ -70,6 +70,8 @@ fun IrType.isSubtypeOf(superType: IrType, irBuiltIns: IrBuiltIns): Boolean {
return AbstractTypeChecker.isSubtypeOf(IrTypeCheckerContext(irBuiltIns) as AbstractTypeCheckerContext, this, superType)
}
// no searchable usages
// delete or FIXME: implement TypeConstructorMarker.isError and TypeConstructorMarker.toErrorType in IrTypeSystemContext
fun Collection<IrType>.commonSupertype(irBuiltIns: IrBuiltIns): IrType {
return NewCommonSuperTypeCalculator.run {
IrTypeCheckerContext(irBuiltIns).commonSuperType(map { it }) as IrType
@@ -191,7 +191,7 @@ object NewCommonSuperTypeCalculator {
val explicitSupertypes = filterSupertypes(uniqueTypes, contextStubTypesNotEqual)
if (explicitSupertypes.size == 1) return explicitSupertypes.single()
findErrorTypeInSupertypesIfItIsNeeded(explicitSupertypes, contextStubTypesEqualToAnything)?.let { return it }
findErrorTypeInSupertypes(explicitSupertypes, contextStubTypesEqualToAnything)?.let { return it }
findCommonIntegerLiteralTypesSuperType(explicitSupertypes)?.let { return it }
@@ -208,11 +208,10 @@ object NewCommonSuperTypeCalculator {
return projectedType.asSimpleType()?.isStubType() == true
}
private fun TypeSystemCommonSuperTypesContext.findErrorTypeInSupertypesIfItIsNeeded(
private fun TypeSystemCommonSuperTypesContext.findErrorTypeInSupertypes(
types: List<SimpleTypeMarker>,
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
): SimpleTypeMarker? {
if (isErrorTypeAllowed) return null
for (type in types) {
collectAllSupertypes(type, contextStubTypesEqualToAnything).firstOrNull { it.isError() }?.let { return it.toErrorType() }
}
@@ -243,7 +242,7 @@ object NewCommonSuperTypeCalculator {
result.retainAll(collectAllSupertypes(type, contextStubTypesEqualToAnything))
}
// remove all constructors that have subtype(s) with constructors from the resulting set - they are less precise
// remove all constructors that have subtype(s) with constructors from the resulting set - they are less precise
return result.filterNot { target ->
result.any { other ->
other != target && other.supertypes().any { it.typeConstructor() == target }
@@ -348,7 +347,7 @@ object NewCommonSuperTypeCalculator {
typeArgumentsForSuperConstructorParameter: List<TypeArgumentMarker>,
parameter: TypeParameterMarker,
): Boolean {
if (parameter.getVariance() == TypeVariance.IN)
if (parameter.getVariance() == TypeVariance.IN)
return false // arguments for contravariant parameters are intersected, recursion should not be possible
val originalTypesSet = originalTypesForCst.toSet()
@@ -33,8 +33,6 @@ import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
override val isErrorTypeAllowed: Boolean get() = false
override fun TypeConstructorMarker.isDenotable(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return this.isDenotable
@@ -78,10 +78,6 @@ interface TypeCheckerProviderContext {
}
interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeFactoryContext, TypeCheckerProviderContext {
/*
* If set in false then if there is an error supertype in input types list of `commonSuperType` it will be returned
*/
val isErrorTypeAllowed: Boolean
fun KotlinTypeMarker.anySuperTypeConstructor(predicate: (TypeConstructorMarker) -> Boolean) =
newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true)