diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index 4de801f2c5e..521be758bb3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -30,8 +30,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs class ConstraintSystemCompleter(private val components: BodyResolveComponents) { - val inferenceComponents = components.session.inferenceComponents - val variableFixationFinder = VariableFixationFinder(inferenceComponents.trivialConstraintTypeInferenceOracle) + private val inferenceComponents + get() = components.session.inferenceComponents + val variableFixationFinder + get() = inferenceComponents.variableFixationFinder fun complete( c: ConstraintSystemCompletionContext, @@ -50,7 +52,7 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents) { val postponedAtoms = getOrderedNotAnalyzedPostponedArguments(topLevelAtoms) val variableForFixation = variableFixationFinder.findFirstVariableForFixation( - c, allTypeVariables, postponedAtoms, completionMode, candidateReturnType, inferenceCompatibilityMode = true + c, allTypeVariables, postponedAtoms, completionMode, candidateReturnType ) ?: break if ( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt index e4448ffcae4..cda54abaf28 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt @@ -5,22 +5,21 @@ package org.jetbrains.kotlin.fir.resolve.inference +import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSessionComponent import org.jetbrains.kotlin.fir.NoMutableState import org.jetbrains.kotlin.fir.types.ConeInferenceContext import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext -import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityChecker -import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintIncorporator -import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector -import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver -import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle +import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl import org.jetbrains.kotlin.types.AbstractTypeApproximator @NoMutableState class InferenceComponents(val session: FirSession) : FirSessionComponent { val ctx: ConeTypeCheckerContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = false, session) + val languageVersionSettings: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT // TODO val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {} val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx) @@ -28,14 +27,14 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent { private val injector = ConstraintInjector( incorporator, approximator, - object : InferenceCompatibilityChecker { - override val isCompatibilityModeEnabled = true - } + languageVersionSettings, ) val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle) val constraintSystemFactory = ConstraintSystemFactory() + val variableFixationFinder = VariableFixationFinder(trivialConstraintTypeInferenceOracle, languageVersionSettings) + fun createConstraintSystem(): NewConstraintSystemImpl { return NewConstraintSystemImpl(injector, ctx) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index f9bb124fc19..c4cbf08a06a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMapper import org.jetbrains.kotlin.container.* import org.jetbrains.kotlin.resolve.calls.checkers.* -import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityCheckerImpl import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.resolve.checkers.* import org.jetbrains.kotlin.resolve.lazy.DelegationFilter @@ -110,7 +109,6 @@ abstract class PlatformConfiguratorBase( override fun configureModuleDependentCheckers(container: StorageComponentContainer) { container.useImpl() - container.useImpl() } fun configureExtensionsAndCheckers(container: StorageComponentContainer) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt index e5b845273ab..2770be2db9a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt @@ -82,12 +82,9 @@ class CoroutineInferenceSession( return !storage.notFixedTypeVariables.keys.any { val variable = storage.allTypeVariables[it] val isPostponed = variable != null && variable in storage.postponedTypeVariables - val useInferenceCompatibilityMode = - topLevelCallContext.languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility) !isPostponed && !kotlinConstraintSystemCompleter.variableFixationFinder.isTypeVariableHasProperConstraint( system, it, - useInferenceCompatibilityMode ) } || candidate.getSubResolvedAtoms().any { it.hasPostponed() } } diff --git a/compiler/resolution.common/build.gradle.kts b/compiler/resolution.common/build.gradle.kts index 3fa6889434b..a4547cc0d5e 100644 --- a/compiler/resolution.common/build.gradle.kts +++ b/compiler/resolution.common/build.gradle.kts @@ -5,6 +5,7 @@ plugins { dependencies { api(project(":core:compiler.common")) + api(project(":compiler:util")) } sourceSets { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityChecker.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityChecker.kt deleted file mode 100644 index 0263ad00cf0..00000000000 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityChecker.kt +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * 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.resolve.calls.inference - -interface InferenceCompatibilityChecker { - val isCompatibilityModeEnabled: Boolean -} diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 7a04c644acb..f4e5d634464 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -6,8 +6,9 @@ package org.jetbrains.kotlin.resolve.calls.inference.components +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation -import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityChecker import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.* import org.jetbrains.kotlin.types.AbstractTypeApproximator @@ -21,7 +22,7 @@ import kotlin.math.max class ConstraintInjector( val constraintIncorporator: ConstraintIncorporator, val typeApproximator: AbstractTypeApproximator, - val inferenceCompatibilityChecker: InferenceCompatibilityChecker + private val languageVersionSettings: LanguageVersionSettings, ) { private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1 @@ -131,7 +132,7 @@ class ConstraintInjector( // We use `var` intentionally to avoid extra allocations as this property is quite "hot" private var possibleNewConstraints: MutableList>? = null - override val isInferenceCompatibilityEnabled = inferenceCompatibilityChecker.isCompatibilityModeEnabled + override val isInferenceCompatibilityEnabled = languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility) private var baseLowerType = position.initialConstraint.a private var baseUpperType = position.initialConstraint.b diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt index 41f331e319b..49fad366a6b 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.resolve.calls.inference.components +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode.PARTIAL import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition @@ -13,7 +15,8 @@ import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.model.* class VariableFixationFinder( - private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle + private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, + private val languageVersionSettings: LanguageVersionSettings, ) { interface Context : TypeSystemInferenceExtensionContext { val notFixedTypeVariables: Map @@ -33,9 +36,7 @@ class VariableFixationFinder( postponedKtPrimitives: List, completionMode: ConstraintSystemCompletionMode, topLevelType: KotlinTypeMarker, - inferenceCompatibilityMode: Boolean = false, - ): VariableForFixation? = - c.findTypeVariableForFixation(allTypeVariables, postponedKtPrimitives, completionMode, topLevelType, inferenceCompatibilityMode) + ): VariableForFixation? = c.findTypeVariableForFixation(allTypeVariables, postponedKtPrimitives, completionMode, topLevelType) enum class TypeVariableFixationReadiness { FORBIDDEN, @@ -50,10 +51,12 @@ class VariableFixationFinder( READY_FOR_FIXATION_REIFIED, } + private val inferenceCompatibilityModeEnabled: Boolean + get() = languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility) + private fun Context.getTypeVariableReadiness( variable: TypeConstructorMarker, dependencyProvider: TypeVariableDependencyInformationProvider, - inferenceCompatibilityMode: Boolean ): TypeVariableFixationReadiness = when { !notFixedTypeVariables.contains(variable) || dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN @@ -64,7 +67,7 @@ class VariableFixationFinder( variableHasOnlyIncorporatedConstraintsFromDeclaredUpperBound(variable) -> TypeVariableFixationReadiness.FROM_INCORPORATION_OF_DECLARED_UPPER_BOUND isReified(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_REIFIED - inferenceCompatibilityMode -> { + inferenceCompatibilityModeEnabled -> { when { variableHasLowerProperConstraint(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_LOWER else -> TypeVariableFixationReadiness.READY_FOR_FIXATION_UPPER @@ -76,13 +79,12 @@ class VariableFixationFinder( fun isTypeVariableHasProperConstraint( context: Context, typeVariable: TypeConstructorMarker, - inferenceCompatibilityMode: Boolean = false ): Boolean { return with(context) { val dependencyProvider = TypeVariableDependencyInformationProvider( notFixedTypeVariables, emptyList(), topLevelType = null, context ) - when (getTypeVariableReadiness(typeVariable, dependencyProvider, inferenceCompatibilityMode)) { + when (getTypeVariableReadiness(typeVariable, dependencyProvider)) { TypeVariableFixationReadiness.FORBIDDEN, TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> false else -> true } @@ -107,7 +109,6 @@ class VariableFixationFinder( postponedArguments: List, completionMode: ConstraintSystemCompletionMode, topLevelType: KotlinTypeMarker, - inferenceCompatibilityMode: Boolean, ): VariableForFixation? { if (allTypeVariables.isEmpty()) return null @@ -116,9 +117,9 @@ class VariableFixationFinder( ) val candidate = - allTypeVariables.maxByOrNull { getTypeVariableReadiness(it, dependencyProvider, inferenceCompatibilityMode) } ?: return null + allTypeVariables.maxByOrNull { getTypeVariableReadiness(it, dependencyProvider) } ?: return null - return when (getTypeVariableReadiness(candidate, dependencyProvider, inferenceCompatibilityMode)) { + return when (getTypeVariableReadiness(candidate, dependencyProvider)) { TypeVariableFixationReadiness.FORBIDDEN -> null TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> VariableForFixation(candidate, false) TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS -> diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityCheckerImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityCheckerImpl.kt deleted file mode 100644 index f9252502a4d..00000000000 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/InferenceCompatibilityCheckerImpl.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * 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.resolve.calls.inference - -import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.config.LanguageVersionSettings - -class InferenceCompatibilityCheckerImpl(val languageVersionSettings: LanguageVersionSettings) : InferenceCompatibilityChecker { - override val isCompatibilityModeEnabled: Boolean - get() = languageVersionSettings.getFeatureSupport(LanguageFeature.InferenceCompatibility) == LanguageFeature.State.ENABLED -} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt index dcfa97d5e65..82b3a94c25c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt @@ -5,8 +5,6 @@ package org.jetbrains.kotlin.resolve.calls.inference.components -import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.components.transformToResolvedLambda import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* @@ -21,7 +19,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs class KotlinConstraintSystemCompleter( private val resultTypeResolver: ResultTypeResolver, val variableFixationFinder: VariableFixationFinder, - val languageVersionSettings: LanguageVersionSettings, ) { private val postponedArgumentInputTypesResolver = PostponedArgumentInputTypesResolver(resultTypeResolver, variableFixationFinder) @@ -108,7 +105,6 @@ class KotlinConstraintSystemCompleter( topLevelType, topLevelAtoms, dependencyProvider, - inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(), ) if (wasFixedSomeVariable) @@ -262,7 +258,6 @@ class KotlinConstraintSystemCompleter( postponedArguments, completionMode, topLevelType, - inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(), ) ?: break if (!variableForFixation.hasProperConstraint && completionMode == ConstraintSystemCompletionMode.PARTIAL) @@ -373,12 +368,8 @@ class KotlinConstraintSystemCompleter( postponedArguments, completionMode, topLevelType, - inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(), ) != null - private fun isInferenceCompatibilityModeEnabled(): Boolean = - languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility) - companion object { fun getOrderedNotAnalyzedPostponedArguments(topLevelAtoms: List): List { fun ResolvedAtom.process(to: MutableList) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt index 6c7928aea90..3fc40ec10d3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt @@ -455,7 +455,6 @@ class PostponedArgumentInputTypesResolver( topLevelType: UnwrappedType, topLevelAtoms: List, dependencyProvider: TypeVariableDependencyInformationProvider, - inferenceCompatibilityMode: Boolean = false, ): Boolean { val expectedType = argument.run { safeAs()?.revisedExpectedType ?: expectedType } @@ -467,7 +466,6 @@ class PostponedArgumentInputTypesResolver( topLevelType, topLevelAtoms, dependencyProvider, - inferenceCompatibilityMode ) if (wasFixedSomeVariable) @@ -483,12 +481,11 @@ class PostponedArgumentInputTypesResolver( topLevelType: UnwrappedType, topLevelAtoms: List, dependencyProvider: TypeVariableDependencyInformationProvider, - inferenceCompatibilityMode: Boolean, ): Boolean { val relatedVariables = type.getPureArgumentsForFunctionalTypeOrSubtype() .flatMap { getAllDeeplyRelatedTypeVariables(it, dependencyProvider) } val variableForFixation = variableFixationFinder.findFirstVariableForFixation( - this, relatedVariables, postponedArguments, ConstraintSystemCompletionMode.FULL, topLevelType, inferenceCompatibilityMode + this, relatedVariables, postponedArguments, ConstraintSystemCompletionMode.FULL, topLevelType ) if (variableForFixation == null || !variableForFixation.hasProperConstraint) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/caches/resolve/CompositeResolverForModuleFactory.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/caches/resolve/CompositeResolverForModuleFactory.kt index 761cd482671..7b9f2e11be7 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/caches/resolve/CompositeResolverForModuleFactory.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/caches/resolve/CompositeResolverForModuleFactory.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.frontend.di.configureStandardResolveComponents import org.jetbrains.kotlin.frontend.java.di.configureJavaSpecificComponents import org.jetbrains.kotlin.frontend.java.di.initializeJavaSpecificComponents import org.jetbrains.kotlin.idea.project.IdeaEnvironment -import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl import org.jetbrains.kotlin.load.kotlin.PackagePartProvider @@ -36,7 +35,6 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatform import org.jetbrains.kotlin.platform.konan.NativePlatform import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.resolve.* -import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityCheckerImpl import org.jetbrains.kotlin.resolve.checkers.ExperimentalMarkerDeclarationAnnotationChecker import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters @@ -254,6 +252,5 @@ class CompositePlatformConigurator(private val componentConfigurators: List() - container.useImpl() } } \ No newline at end of file