[FIR] Use default language settings in inference components
Without settings common inference components require additional parameters to be passed explicitly from components not shared between FIR and FE10. Proper configuration can be postponed in FIR, defaults are good enough for now. ^KT-42080 In progress
This commit is contained in:
+5
-3
@@ -30,8 +30,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class ConstraintSystemCompleter(private val components: BodyResolveComponents) {
|
class ConstraintSystemCompleter(private val components: BodyResolveComponents) {
|
||||||
val inferenceComponents = components.session.inferenceComponents
|
private val inferenceComponents
|
||||||
val variableFixationFinder = VariableFixationFinder(inferenceComponents.trivialConstraintTypeInferenceOracle)
|
get() = components.session.inferenceComponents
|
||||||
|
val variableFixationFinder
|
||||||
|
get() = inferenceComponents.variableFixationFinder
|
||||||
|
|
||||||
fun complete(
|
fun complete(
|
||||||
c: ConstraintSystemCompletionContext,
|
c: ConstraintSystemCompletionContext,
|
||||||
@@ -50,7 +52,7 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents) {
|
|||||||
val postponedAtoms = getOrderedNotAnalyzedPostponedArguments(topLevelAtoms)
|
val postponedAtoms = getOrderedNotAnalyzedPostponedArguments(topLevelAtoms)
|
||||||
val variableForFixation =
|
val variableForFixation =
|
||||||
variableFixationFinder.findFirstVariableForFixation(
|
variableFixationFinder.findFirstVariableForFixation(
|
||||||
c, allTypeVariables, postponedAtoms, completionMode, candidateReturnType, inferenceCompatibilityMode = true
|
c, allTypeVariables, postponedAtoms, completionMode, candidateReturnType
|
||||||
) ?: break
|
) ?: break
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
+7
-8
@@ -5,22 +5,21 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.inference
|
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.FirSession
|
||||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||||
import org.jetbrains.kotlin.fir.NoMutableState
|
import org.jetbrains.kotlin.fir.NoMutableState
|
||||||
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
||||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceCompatibilityChecker
|
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||||
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.model.NewConstraintSystemImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
|
|
||||||
@NoMutableState
|
@NoMutableState
|
||||||
class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
||||||
val ctx: ConeTypeCheckerContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = false, session)
|
val ctx: ConeTypeCheckerContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = false, session)
|
||||||
|
val languageVersionSettings: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT // TODO
|
||||||
|
|
||||||
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
||||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||||
@@ -28,14 +27,14 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
|||||||
private val injector = ConstraintInjector(
|
private val injector = ConstraintInjector(
|
||||||
incorporator,
|
incorporator,
|
||||||
approximator,
|
approximator,
|
||||||
object : InferenceCompatibilityChecker {
|
languageVersionSettings,
|
||||||
override val isCompatibilityModeEnabled = true
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
||||||
|
|
||||||
val constraintSystemFactory = ConstraintSystemFactory()
|
val constraintSystemFactory = ConstraintSystemFactory()
|
||||||
|
|
||||||
|
val variableFixationFinder = VariableFixationFinder(trivialConstraintTypeInferenceOracle, languageVersionSettings)
|
||||||
|
|
||||||
fun createConstraintSystem(): NewConstraintSystemImpl {
|
fun createConstraintSystem(): NewConstraintSystemImpl {
|
||||||
return NewConstraintSystemImpl(injector, ctx)
|
return NewConstraintSystemImpl(injector, ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.resolve
|
|||||||
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMapper
|
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMapper
|
||||||
import org.jetbrains.kotlin.container.*
|
import org.jetbrains.kotlin.container.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.*
|
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.calls.results.TypeSpecificityComparator
|
||||||
import org.jetbrains.kotlin.resolve.checkers.*
|
import org.jetbrains.kotlin.resolve.checkers.*
|
||||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||||
@@ -110,7 +109,6 @@ abstract class PlatformConfiguratorBase(
|
|||||||
|
|
||||||
override fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
override fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
||||||
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
||||||
container.useImpl<InferenceCompatibilityCheckerImpl>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun configureExtensionsAndCheckers(container: StorageComponentContainer) {
|
fun configureExtensionsAndCheckers(container: StorageComponentContainer) {
|
||||||
|
|||||||
-3
@@ -82,12 +82,9 @@ class CoroutineInferenceSession(
|
|||||||
return !storage.notFixedTypeVariables.keys.any {
|
return !storage.notFixedTypeVariables.keys.any {
|
||||||
val variable = storage.allTypeVariables[it]
|
val variable = storage.allTypeVariables[it]
|
||||||
val isPostponed = variable != null && variable in storage.postponedTypeVariables
|
val isPostponed = variable != null && variable in storage.postponedTypeVariables
|
||||||
val useInferenceCompatibilityMode =
|
|
||||||
topLevelCallContext.languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility)
|
|
||||||
!isPostponed && !kotlinConstraintSystemCompleter.variableFixationFinder.isTypeVariableHasProperConstraint(
|
!isPostponed && !kotlinConstraintSystemCompleter.variableFixationFinder.isTypeVariableHasProperConstraint(
|
||||||
system,
|
system,
|
||||||
it,
|
it,
|
||||||
useInferenceCompatibilityMode
|
|
||||||
)
|
)
|
||||||
} || candidate.getSubResolvedAtoms().any { it.hasPostponed() }
|
} || candidate.getSubResolvedAtoms().any { it.hasPostponed() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(project(":core:compiler.common"))
|
api(project(":core:compiler.common"))
|
||||||
|
api(project(":compiler:util"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
-10
@@ -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
|
|
||||||
}
|
|
||||||
+4
-3
@@ -6,8 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
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.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.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.*
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
@@ -21,7 +22,7 @@ import kotlin.math.max
|
|||||||
class ConstraintInjector(
|
class ConstraintInjector(
|
||||||
val constraintIncorporator: ConstraintIncorporator,
|
val constraintIncorporator: ConstraintIncorporator,
|
||||||
val typeApproximator: AbstractTypeApproximator,
|
val typeApproximator: AbstractTypeApproximator,
|
||||||
val inferenceCompatibilityChecker: InferenceCompatibilityChecker
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
) {
|
) {
|
||||||
private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1
|
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"
|
// We use `var` intentionally to avoid extra allocations as this property is quite "hot"
|
||||||
private var possibleNewConstraints: MutableList<Pair<TypeVariableMarker, Constraint>>? = null
|
private var possibleNewConstraints: MutableList<Pair<TypeVariableMarker, Constraint>>? = null
|
||||||
|
|
||||||
override val isInferenceCompatibilityEnabled = inferenceCompatibilityChecker.isCompatibilityModeEnabled
|
override val isInferenceCompatibilityEnabled = languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility)
|
||||||
|
|
||||||
private var baseLowerType = position.initialConstraint.a
|
private var baseLowerType = position.initialConstraint.a
|
||||||
private var baseUpperType = position.initialConstraint.b
|
private var baseUpperType = position.initialConstraint.b
|
||||||
|
|||||||
+12
-11
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
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.components.ConstraintSystemCompletionMode.PARTIAL
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint
|
import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
|
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.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
|
|
||||||
class VariableFixationFinder(
|
class VariableFixationFinder(
|
||||||
private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle
|
private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle,
|
||||||
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
) {
|
) {
|
||||||
interface Context : TypeSystemInferenceExtensionContext {
|
interface Context : TypeSystemInferenceExtensionContext {
|
||||||
val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
|
val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
|
||||||
@@ -33,9 +36,7 @@ class VariableFixationFinder(
|
|||||||
postponedKtPrimitives: List<PostponedResolvedAtomMarker>,
|
postponedKtPrimitives: List<PostponedResolvedAtomMarker>,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
topLevelType: KotlinTypeMarker,
|
topLevelType: KotlinTypeMarker,
|
||||||
inferenceCompatibilityMode: Boolean = false,
|
): VariableForFixation? = c.findTypeVariableForFixation(allTypeVariables, postponedKtPrimitives, completionMode, topLevelType)
|
||||||
): VariableForFixation? =
|
|
||||||
c.findTypeVariableForFixation(allTypeVariables, postponedKtPrimitives, completionMode, topLevelType, inferenceCompatibilityMode)
|
|
||||||
|
|
||||||
enum class TypeVariableFixationReadiness {
|
enum class TypeVariableFixationReadiness {
|
||||||
FORBIDDEN,
|
FORBIDDEN,
|
||||||
@@ -50,10 +51,12 @@ class VariableFixationFinder(
|
|||||||
READY_FOR_FIXATION_REIFIED,
|
READY_FOR_FIXATION_REIFIED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val inferenceCompatibilityModeEnabled: Boolean
|
||||||
|
get() = languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility)
|
||||||
|
|
||||||
private fun Context.getTypeVariableReadiness(
|
private fun Context.getTypeVariableReadiness(
|
||||||
variable: TypeConstructorMarker,
|
variable: TypeConstructorMarker,
|
||||||
dependencyProvider: TypeVariableDependencyInformationProvider,
|
dependencyProvider: TypeVariableDependencyInformationProvider,
|
||||||
inferenceCompatibilityMode: Boolean
|
|
||||||
): TypeVariableFixationReadiness = when {
|
): TypeVariableFixationReadiness = when {
|
||||||
!notFixedTypeVariables.contains(variable) ||
|
!notFixedTypeVariables.contains(variable) ||
|
||||||
dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN
|
dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN
|
||||||
@@ -64,7 +67,7 @@ class VariableFixationFinder(
|
|||||||
variableHasOnlyIncorporatedConstraintsFromDeclaredUpperBound(variable) ->
|
variableHasOnlyIncorporatedConstraintsFromDeclaredUpperBound(variable) ->
|
||||||
TypeVariableFixationReadiness.FROM_INCORPORATION_OF_DECLARED_UPPER_BOUND
|
TypeVariableFixationReadiness.FROM_INCORPORATION_OF_DECLARED_UPPER_BOUND
|
||||||
isReified(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_REIFIED
|
isReified(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_REIFIED
|
||||||
inferenceCompatibilityMode -> {
|
inferenceCompatibilityModeEnabled -> {
|
||||||
when {
|
when {
|
||||||
variableHasLowerProperConstraint(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_LOWER
|
variableHasLowerProperConstraint(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_LOWER
|
||||||
else -> TypeVariableFixationReadiness.READY_FOR_FIXATION_UPPER
|
else -> TypeVariableFixationReadiness.READY_FOR_FIXATION_UPPER
|
||||||
@@ -76,13 +79,12 @@ class VariableFixationFinder(
|
|||||||
fun isTypeVariableHasProperConstraint(
|
fun isTypeVariableHasProperConstraint(
|
||||||
context: Context,
|
context: Context,
|
||||||
typeVariable: TypeConstructorMarker,
|
typeVariable: TypeConstructorMarker,
|
||||||
inferenceCompatibilityMode: Boolean = false
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return with(context) {
|
return with(context) {
|
||||||
val dependencyProvider = TypeVariableDependencyInformationProvider(
|
val dependencyProvider = TypeVariableDependencyInformationProvider(
|
||||||
notFixedTypeVariables, emptyList(), topLevelType = null, context
|
notFixedTypeVariables, emptyList(), topLevelType = null, context
|
||||||
)
|
)
|
||||||
when (getTypeVariableReadiness(typeVariable, dependencyProvider, inferenceCompatibilityMode)) {
|
when (getTypeVariableReadiness(typeVariable, dependencyProvider)) {
|
||||||
TypeVariableFixationReadiness.FORBIDDEN, TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> false
|
TypeVariableFixationReadiness.FORBIDDEN, TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> false
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
@@ -107,7 +109,6 @@ class VariableFixationFinder(
|
|||||||
postponedArguments: List<PostponedResolvedAtomMarker>,
|
postponedArguments: List<PostponedResolvedAtomMarker>,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
topLevelType: KotlinTypeMarker,
|
topLevelType: KotlinTypeMarker,
|
||||||
inferenceCompatibilityMode: Boolean,
|
|
||||||
): VariableForFixation? {
|
): VariableForFixation? {
|
||||||
if (allTypeVariables.isEmpty()) return null
|
if (allTypeVariables.isEmpty()) return null
|
||||||
|
|
||||||
@@ -116,9 +117,9 @@ class VariableFixationFinder(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val candidate =
|
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.FORBIDDEN -> null
|
||||||
TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> VariableForFixation(candidate, false)
|
TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT -> VariableForFixation(candidate, false)
|
||||||
TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS ->
|
TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS ->
|
||||||
|
|||||||
-14
@@ -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
|
|
||||||
}
|
|
||||||
-9
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
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.components.transformToResolvedLambda
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
@@ -21,7 +19,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
class KotlinConstraintSystemCompleter(
|
class KotlinConstraintSystemCompleter(
|
||||||
private val resultTypeResolver: ResultTypeResolver,
|
private val resultTypeResolver: ResultTypeResolver,
|
||||||
val variableFixationFinder: VariableFixationFinder,
|
val variableFixationFinder: VariableFixationFinder,
|
||||||
val languageVersionSettings: LanguageVersionSettings,
|
|
||||||
) {
|
) {
|
||||||
private val postponedArgumentInputTypesResolver = PostponedArgumentInputTypesResolver(resultTypeResolver, variableFixationFinder)
|
private val postponedArgumentInputTypesResolver = PostponedArgumentInputTypesResolver(resultTypeResolver, variableFixationFinder)
|
||||||
|
|
||||||
@@ -108,7 +105,6 @@ class KotlinConstraintSystemCompleter(
|
|||||||
topLevelType,
|
topLevelType,
|
||||||
topLevelAtoms,
|
topLevelAtoms,
|
||||||
dependencyProvider,
|
dependencyProvider,
|
||||||
inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (wasFixedSomeVariable)
|
if (wasFixedSomeVariable)
|
||||||
@@ -262,7 +258,6 @@ class KotlinConstraintSystemCompleter(
|
|||||||
postponedArguments,
|
postponedArguments,
|
||||||
completionMode,
|
completionMode,
|
||||||
topLevelType,
|
topLevelType,
|
||||||
inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(),
|
|
||||||
) ?: break
|
) ?: break
|
||||||
|
|
||||||
if (!variableForFixation.hasProperConstraint && completionMode == ConstraintSystemCompletionMode.PARTIAL)
|
if (!variableForFixation.hasProperConstraint && completionMode == ConstraintSystemCompletionMode.PARTIAL)
|
||||||
@@ -373,12 +368,8 @@ class KotlinConstraintSystemCompleter(
|
|||||||
postponedArguments,
|
postponedArguments,
|
||||||
completionMode,
|
completionMode,
|
||||||
topLevelType,
|
topLevelType,
|
||||||
inferenceCompatibilityMode = isInferenceCompatibilityModeEnabled(),
|
|
||||||
) != null
|
) != null
|
||||||
|
|
||||||
private fun isInferenceCompatibilityModeEnabled(): Boolean =
|
|
||||||
languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility)
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getOrderedNotAnalyzedPostponedArguments(topLevelAtoms: List<ResolvedAtom>): List<PostponedResolvedAtom> {
|
fun getOrderedNotAnalyzedPostponedArguments(topLevelAtoms: List<ResolvedAtom>): List<PostponedResolvedAtom> {
|
||||||
fun ResolvedAtom.process(to: MutableList<PostponedResolvedAtom>) {
|
fun ResolvedAtom.process(to: MutableList<PostponedResolvedAtom>) {
|
||||||
|
|||||||
+1
-4
@@ -455,7 +455,6 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
topLevelType: UnwrappedType,
|
topLevelType: UnwrappedType,
|
||||||
topLevelAtoms: List<ResolvedAtom>,
|
topLevelAtoms: List<ResolvedAtom>,
|
||||||
dependencyProvider: TypeVariableDependencyInformationProvider,
|
dependencyProvider: TypeVariableDependencyInformationProvider,
|
||||||
inferenceCompatibilityMode: Boolean = false,
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val expectedType = argument.run { safeAs<PostponedAtomWithRevisableExpectedType>()?.revisedExpectedType ?: expectedType }
|
val expectedType = argument.run { safeAs<PostponedAtomWithRevisableExpectedType>()?.revisedExpectedType ?: expectedType }
|
||||||
|
|
||||||
@@ -467,7 +466,6 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
topLevelType,
|
topLevelType,
|
||||||
topLevelAtoms,
|
topLevelAtoms,
|
||||||
dependencyProvider,
|
dependencyProvider,
|
||||||
inferenceCompatibilityMode
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (wasFixedSomeVariable)
|
if (wasFixedSomeVariable)
|
||||||
@@ -483,12 +481,11 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
topLevelType: UnwrappedType,
|
topLevelType: UnwrappedType,
|
||||||
topLevelAtoms: List<ResolvedAtom>,
|
topLevelAtoms: List<ResolvedAtom>,
|
||||||
dependencyProvider: TypeVariableDependencyInformationProvider,
|
dependencyProvider: TypeVariableDependencyInformationProvider,
|
||||||
inferenceCompatibilityMode: Boolean,
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val relatedVariables = type.getPureArgumentsForFunctionalTypeOrSubtype()
|
val relatedVariables = type.getPureArgumentsForFunctionalTypeOrSubtype()
|
||||||
.flatMap { getAllDeeplyRelatedTypeVariables(it, dependencyProvider) }
|
.flatMap { getAllDeeplyRelatedTypeVariables(it, dependencyProvider) }
|
||||||
val variableForFixation = variableFixationFinder.findFirstVariableForFixation(
|
val variableForFixation = variableFixationFinder.findFirstVariableForFixation(
|
||||||
this, relatedVariables, postponedArguments, ConstraintSystemCompletionMode.FULL, topLevelType, inferenceCompatibilityMode
|
this, relatedVariables, postponedArguments, ConstraintSystemCompletionMode.FULL, topLevelType
|
||||||
)
|
)
|
||||||
|
|
||||||
if (variableForFixation == null || !variableForFixation.hasProperConstraint)
|
if (variableForFixation == null || !variableForFixation.hasProperConstraint)
|
||||||
|
|||||||
-3
@@ -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.configureJavaSpecificComponents
|
||||||
import org.jetbrains.kotlin.frontend.java.di.initializeJavaSpecificComponents
|
import org.jetbrains.kotlin.frontend.java.di.initializeJavaSpecificComponents
|
||||||
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
|
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.ModuleClassResolver
|
||||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
|
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
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.NativePlatform
|
||||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||||
import org.jetbrains.kotlin.resolve.*
|
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.checkers.ExperimentalMarkerDeclarationAnnotationChecker
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
|
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||||
@@ -254,6 +252,5 @@ class CompositePlatformConigurator(private val componentConfigurators: List<Plat
|
|||||||
// Unfortunately, it is declared in base class, so repeating call to 'configureModuleDependentCheckers' will lead
|
// Unfortunately, it is declared in base class, so repeating call to 'configureModuleDependentCheckers' will lead
|
||||||
// to multiple registrrations.
|
// to multiple registrrations.
|
||||||
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
||||||
container.useImpl<InferenceCompatibilityCheckerImpl>()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user