FIR: move down inference session handling in PostponedArgumentsAnalyzer
After this commit the handling of inference session in similar for FIR and FE 1.0
This commit is contained in:
committed by
teamcity
parent
bd6fef7841
commit
7f62d1bc5a
+22
-22
@@ -26,10 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerC
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.BuilderInferencePosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.BuilderInferencePosition
|
||||||
import org.jetbrains.kotlin.types.model.StubTypeMarker
|
import org.jetbrains.kotlin.types.model.*
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
|
||||||
import org.jetbrains.kotlin.types.model.freshTypeConstructor
|
|
||||||
import org.jetbrains.kotlin.types.model.safeSubstitute
|
|
||||||
|
|
||||||
data class ReturnArgumentsAnalysisResult(
|
data class ReturnArgumentsAnalysisResult(
|
||||||
val returnArguments: Collection<FirStatement>,
|
val returnArguments: Collection<FirStatement>,
|
||||||
@@ -165,26 +162,8 @@ class PostponedArgumentsAnalyzer(
|
|||||||
substitute: (ConeKotlinType) -> ConeKotlinType = c.createSubstituteFunctorForLambdaAnalysis()
|
substitute: (ConeKotlinType) -> ConeKotlinType = c.createSubstituteFunctorForLambdaAnalysis()
|
||||||
) {
|
) {
|
||||||
val (returnArguments, inferenceSession) = results
|
val (returnArguments, inferenceSession) = results
|
||||||
if (inferenceSession != null) {
|
|
||||||
val storageSnapshot = c.getBuilder().currentStorage()
|
|
||||||
|
|
||||||
val postponedVariables = inferenceSession.inferPostponedVariables(lambda, storageSnapshot, completionMode)
|
|
||||||
|
|
||||||
if (postponedVariables == null) {
|
|
||||||
c.getBuilder().removePostponedVariables()
|
|
||||||
} else {
|
|
||||||
for ((constructor, resultType) in postponedVariables) {
|
|
||||||
val variableWithConstraints = storageSnapshot.notFixedTypeVariables[constructor] ?: continue
|
|
||||||
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
|
|
||||||
|
|
||||||
c.getBuilder().unmarkPostponedVariable(variable)
|
|
||||||
c.getBuilder().addEqualityConstraint(variable.defaultType, resultType, BuilderInferencePosition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
returnArguments.forEach { c.addSubsystemFromExpression(it) }
|
returnArguments.forEach { c.addSubsystemFromExpression(it) }
|
||||||
|
|
||||||
val checkerSink: CheckerSink = CheckerSinkImpl(candidate)
|
val checkerSink: CheckerSink = CheckerSinkImpl(candidate)
|
||||||
|
|
||||||
val lastExpression = lambda.atom.body?.statements?.lastOrNull() as? FirExpression
|
val lastExpression = lambda.atom.body?.statements?.lastOrNull() as? FirExpression
|
||||||
@@ -223,6 +202,27 @@ class PostponedArgumentsAnalyzer(
|
|||||||
|
|
||||||
lambda.analyzed = true
|
lambda.analyzed = true
|
||||||
lambda.returnStatements = returnArguments
|
lambda.returnStatements = returnArguments
|
||||||
|
|
||||||
|
if (inferenceSession != null) {
|
||||||
|
val storageSnapshot = c.getBuilder().currentStorage()
|
||||||
|
|
||||||
|
val postponedVariables = inferenceSession.inferPostponedVariables(lambda, storageSnapshot, completionMode)
|
||||||
|
|
||||||
|
if (postponedVariables == null) {
|
||||||
|
c.getBuilder().removePostponedVariables()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for ((constructor, resultType) in postponedVariables) {
|
||||||
|
val variableWithConstraints = storageSnapshot.notFixedTypeVariables[constructor] ?: continue
|
||||||
|
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
|
||||||
|
|
||||||
|
c.getBuilder().unmarkPostponedVariable(variable)
|
||||||
|
c.getBuilder().addSubtypeConstraint(resultType, variable.defaultType(c), BuilderInferencePosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.removePostponedTypeVariablesFromConstraints(postponedVariables.keys)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PostponedArgumentsAnalyzerContext.createSubstituteFunctorForLambdaAnalysis(): (ConeKotlinType) -> ConeKotlinType {
|
fun PostponedArgumentsAnalyzerContext.createSubstituteFunctorForLambdaAnalysis(): (ConeKotlinType) -> ConeKotlinType {
|
||||||
|
|||||||
Reference in New Issue
Block a user