Get rid of FE 1.0 classes usage in ConstraintIncorporator

This commit is contained in:
Dmitriy Novozhilov
2020-08-26 13:06:16 +03:00
parent 1050f7f066
commit 64f0ee21c1
6 changed files with 56 additions and 6 deletions

View File

@@ -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
}
}

View File

@@ -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)

View File

@@ -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<CompilerDeserializationConfiguration>()
useImpl<ClassicTypeSystemContextForCS>()
useInstance(ClassicConstraintSystemUtilContext)
useInstance(ProgressManagerBasedCancellationChecker)
}

View File

@@ -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()
}
}

View File

@@ -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<A & Any> =>? B <: Inv<out Number & Any>
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,

View File

@@ -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
}