From 64f0ee21c19a99a0fc5dad376294b4d32c6606d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 26 Aug 2020 13:06:16 +0300 Subject: [PATCH] Get rid of FE 1.0 classes usage in ConstraintIncorporator --- .../ConeConstraintSystemUtilContext.kt | 16 ++++++++++++++++ .../resolve/inference/InferenceComponents.kt | 2 +- .../jetbrains/kotlin/frontend/di/injection.kt | 2 ++ .../ClassicConstraintSystemUtilContext.kt | 16 ++++++++++++++++ .../components/ConstraintIncorporator.kt | 9 ++++----- .../components/ConstraintSystemUtilContext.kt | 17 +++++++++++++++++ 6 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeConstraintSystemUtilContext.kt create mode 100644 compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ClassicConstraintSystemUtilContext.kt create mode 100644 compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemUtilContext.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeConstraintSystemUtilContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeConstraintSystemUtilContext.kt new file mode 100644 index 00000000000..5bd57d15b6f --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeConstraintSystemUtilContext.kt @@ -0,0 +1,16 @@ +/* + * 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.fir.resolve.inference + +import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemUtilContext +import org.jetbrains.kotlin.types.model.TypeVariableMarker + +object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext { + override fun TypeVariableMarker.shouldBeFlexible(): Boolean { + // TODO + return false + } +} 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 a9265c5cb09..d2bb9163331 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 @@ -26,7 +26,7 @@ class InferenceComponents( ) { val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {} val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx) - private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle) + private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle, ConeConstraintSystemUtilContext) private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default) val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt index e5020540a3c..b70d49fde31 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.platform.TargetPlatformVersion import org.jetbrains.kotlin.platform.isCommon import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS +import org.jetbrains.kotlin.resolve.calls.inference.components.ClassicConstraintSystemUtilContext import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactoryImpl import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionStatelessCallbacksImpl import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker @@ -100,6 +101,7 @@ private fun StorageComponentContainer.configurePlatformIndependentComponents() { useImpl() useImpl() + useInstance(ClassicConstraintSystemUtilContext) useInstance(ProgressManagerBasedCancellationChecker) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ClassicConstraintSystemUtilContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ClassicConstraintSystemUtilContext.kt new file mode 100644 index 00000000000..ca741d91aae --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ClassicConstraintSystemUtilContext.kt @@ -0,0 +1,16 @@ +/* + * 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.components + +import org.jetbrains.kotlin.resolve.calls.components.CreateFreshVariablesSubstitutor.shouldBeFlexible +import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor +import org.jetbrains.kotlin.types.model.TypeVariableMarker + +object ClassicConstraintSystemUtilContext : ConstraintSystemUtilContext { + override fun TypeVariableMarker.shouldBeFlexible(): Boolean { + return this is TypeVariableFromCallableDescriptor && this.originalTypeParameter.shouldBeFlexible() + } +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt index 524759d1138..91479efbf73 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.resolve.calls.inference.components -import org.jetbrains.kotlin.resolve.calls.components.CreateFreshVariablesSubstitutor.shouldBeFlexible import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.types.AbstractTypeApproximator import org.jetbrains.kotlin.types.TypeApproximatorConfiguration @@ -19,7 +18,8 @@ import java.util.* // todo problem: intersection types in constrains: A <: Number, B <: Inv =>? B <: Inv class ConstraintIncorporator( val typeApproximator: AbstractTypeApproximator, - val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle + val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, + val utilContext: ConstraintSystemUtilContext ) { interface Context : TypeSystemInferenceExtensionContext { @@ -66,8 +66,7 @@ class ConstraintIncorporator( typeVariable: TypeVariableMarker, constraint: Constraint ) { - val shouldBeTypeVariableFlexible = - typeVariable is TypeVariableFromCallableDescriptor && typeVariable.originalTypeParameter.shouldBeFlexible() + val shouldBeTypeVariableFlexible = with(utilContext) { typeVariable.shouldBeFlexible() } // \alpha <: constraint.type if (constraint.kind != ConstraintKind.LOWER) { @@ -83,7 +82,7 @@ class ConstraintIncorporator( getConstraintsForVariable(typeVariable).forEach { if (it.kind != ConstraintKind.LOWER) { val isFromDeclaredUpperBound = - it.position.from is DeclaredUpperBoundConstraintPosition<*> && it.type.typeConstructor() !is TypeVariableTypeConstructor + it.position.from is DeclaredUpperBoundConstraintPosition<*> && !it.type.typeConstructor().isTypeVariable() addNewIncorporatedConstraint( constraint.type, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemUtilContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemUtilContext.kt new file mode 100644 index 00000000000..b347833e25f --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemUtilContext.kt @@ -0,0 +1,17 @@ +/* + * 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.components + +import org.jetbrains.kotlin.types.model.TypeVariableMarker + +/* + * Functions from this context can not be moved to TypeSystemInferenceExtensionContext, because + * it's classic implementation, ClassicTypeSystemContext lays in :core:descriptors, + * but we need access classes from :compiler:resolution for this function implementation + */ +interface ConstraintSystemUtilContext { + fun TypeVariableMarker.shouldBeFlexible(): Boolean +}