[FIR] Introduce ConeTypeApproximator
This commit is contained in:
committed by
TeamCityServer
parent
1fac1fc5d3
commit
c271f953d7
+1
-2
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.psi2ir.generators.hasNoSideEffects
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
|
||||
class CallAndReferenceGenerator(
|
||||
@@ -50,7 +49,7 @@ class CallAndReferenceGenerator(
|
||||
private val conversionScope: Fir2IrConversionScope
|
||||
) : Fir2IrComponents by components {
|
||||
|
||||
private val approximator = object : AbstractTypeApproximator(session.typeContext) {}
|
||||
private val approximator = ConeTypeApproximator(session.typeContext)
|
||||
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
||||
private val samResolver = FirSamResolverImpl(session, scopeSession)
|
||||
|
||||
|
||||
+1
-1
@@ -243,5 +243,5 @@ class FirCallCompleter(
|
||||
private fun ConeKotlinType.approximateLambdaInputType(): ConeKotlinType =
|
||||
session.inferenceComponents.approximator.approximateToSuperType(
|
||||
this, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
|
||||
) as ConeKotlinType? ?: this
|
||||
) ?: this
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ package org.jetbrains.kotlin.fir.resolve.inference
|
||||
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeApproximator
|
||||
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 {
|
||||
@@ -18,7 +18,7 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
||||
get() = this@InferenceComponents.session
|
||||
}
|
||||
|
||||
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
||||
val approximator: ConeTypeApproximator = ConeTypeApproximator(ctx)
|
||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle, ConeConstraintSystemUtilContext)
|
||||
private val injector = ConstraintInjector(
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.typeConstructor
|
||||
@@ -161,7 +160,7 @@ data class ConeSubstitutorByMap(val substitution: Map<FirTypeParameterSymbol, Co
|
||||
if (type.isUnsafeVarianceType(session)) {
|
||||
return session.inferenceComponents.approximator.approximateToSuperType(
|
||||
result, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
|
||||
) as? ConeKotlinType ?: result
|
||||
) ?: result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
+1
-1
@@ -971,7 +971,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
access.resultType = typeFromCallee.withReplacedConeType(
|
||||
session.inferenceComponents.approximator.approximateToSuperType(
|
||||
typeFromCallee.type, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
|
||||
) as ConeKotlinType?
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.types
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
|
||||
class ConeTypeApproximator(inferenceContext: ConeInferenceContext) : AbstractTypeApproximator(inferenceContext) {
|
||||
fun approximateToSuperType(type: ConeKotlinType, conf: TypeApproximatorConfiguration): ConeKotlinType? {
|
||||
return super.approximateToSuperType(type, conf) as ConeKotlinType?
|
||||
}
|
||||
|
||||
fun approximateToSubType(type: ConeKotlinType, conf: TypeApproximatorConfiguration): ConeKotlinType? {
|
||||
return super.approximateToSubType(type, conf) as ConeKotlinType?
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
@@ -250,7 +249,7 @@ fun FirTypeRef.withReplacedConeType(
|
||||
}
|
||||
|
||||
fun FirTypeRef.approximated(
|
||||
typeApproximator: AbstractTypeApproximator,
|
||||
typeApproximator: ConeTypeApproximator,
|
||||
toSuper: Boolean,
|
||||
conf: TypeApproximatorConfiguration = TypeApproximatorConfiguration.PublicDeclaration
|
||||
): FirTypeRef {
|
||||
@@ -258,11 +257,11 @@ fun FirTypeRef.approximated(
|
||||
typeApproximator.approximateToSuperType(coneType, conf)
|
||||
else
|
||||
typeApproximator.approximateToSubType(coneType, conf)
|
||||
return withReplacedConeType(approximatedType as? ConeKotlinType)
|
||||
return withReplacedConeType(approximatedType)
|
||||
}
|
||||
|
||||
fun FirTypeRef.approximatedIfNeededOrSelf(
|
||||
approximator: AbstractTypeApproximator,
|
||||
approximator: ConeTypeApproximator,
|
||||
containingCallableVisibility: Visibility?,
|
||||
isInlineFunction: Boolean = false
|
||||
): FirTypeRef {
|
||||
@@ -273,7 +272,7 @@ fun FirTypeRef.approximatedIfNeededOrSelf(
|
||||
return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability()
|
||||
}
|
||||
|
||||
fun FirTypeRef.approximatedForPublicPosition(approximator: AbstractTypeApproximator): FirTypeRef =
|
||||
fun FirTypeRef.approximatedForPublicPosition(approximator: ConeTypeApproximator): FirTypeRef =
|
||||
if (this is FirResolvedTypeRef && type.requiresApproximationInPublicPosition())
|
||||
this.approximated(approximator, toSuper = true)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user