From 1ef17c6f3ab85dcfc8166c4246daf62b3240f422 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Tue, 21 Jul 2020 18:24:50 +0300 Subject: [PATCH] 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. --- .../jetbrains/kotlin/fir/types/ConeInferenceContext.kt | 2 -- .../org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt | 2 -- .../src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt | 2 ++ .../kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt | 9 ++++----- .../kotlin/types/checker/ClassicTypeSystemContext.kt | 2 -- .../jetbrains/kotlin/types/model/TypeSystemContext.kt | 4 ---- 6 files changed, 6 insertions(+), 15 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index b148d5cec2b..ca6f3d03f00 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -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) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index db40bab9be3..21a166d82ae 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -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 diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt index fc317d0720f..626d90bb17b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt @@ -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.commonSupertype(irBuiltIns: IrBuiltIns): IrType { return NewCommonSuperTypeCalculator.run { IrTypeCheckerContext(irBuiltIns).commonSuperType(map { it }) as IrType diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt index d0c8274d877..1cb45dc647e 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt @@ -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, 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, 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() diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 5a843347d43..6862ef8f30f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -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 diff --git a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index 4b43b045002..d4dde15b306 100644 --- a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -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)