From c324bbfc377bfe8cb7def319dc209c9ddcbadd68 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 17 Jan 2022 12:53:40 +0300 Subject: [PATCH] FIR: fold two last getOrderedAllTypeVariables calls into one (stage 7,8) This commit saves us some performance and fixes test for KT-35684. FIR-based constraint completer at this moment can't extract type variables from already completed calls. Folding allows us to extract ordered type variables before completion. --- .../inference/ConstraintSystemCompleter.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index bd063c2426e..e316cf9f3ff 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -149,8 +149,9 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c continue // Stage 7: try to complete call with the builder inference if there are uninferred type variables + val allTypeVariables = getOrderedAllTypeVariables(collectVariablesFromContext, topLevelAtoms) val areThereAppearedProperConstraintsForSomeVariable = tryToCompleteWithBuilderInference( - completionMode, topLevelAtoms, topLevelType, postponedArguments, collectVariablesFromContext, analyze + completionMode, topLevelType, postponedArguments, allTypeVariables, analyze ) if (areThereAppearedProperConstraintsForSomeVariable) @@ -158,7 +159,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c // Stage 8: report "not enough information" for uninferred type variables reportNotEnoughTypeInformation( - completionMode, topLevelAtoms, topLevelType, collectVariablesFromContext, postponedArguments + completionMode, topLevelAtoms, topLevelType, allTypeVariables, postponedArguments ) // Stage 9: force analysis of remaining not analyzed postponed arguments and rerun stages if there are @@ -173,10 +174,9 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c private fun ConstraintSystemCompletionContext.tryToCompleteWithBuilderInference( completionMode: ConstraintSystemCompletionMode, - topLevelAtoms: List, topLevelType: ConeKotlinType, postponedArguments: List, - collectVariablesFromContext: Boolean, + allTypeVariables: List, analyze: (PostponedResolvedAtom) -> Unit ): Boolean { if (completionMode == ConstraintSystemCompletionMode.PARTIAL) return false @@ -202,7 +202,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c } val variableForFixation = variableFixationFinder.findFirstVariableForFixation( - this, getOrderedAllTypeVariables(collectVariablesFromContext, topLevelAtoms), postponedArguments, completionMode, topLevelType + this, allTypeVariables, postponedArguments, completionMode, topLevelType ) // continue completion (rerun stages) only if ready for fixation variables with proper constraints have appeared @@ -267,13 +267,12 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c completionMode: ConstraintSystemCompletionMode, topLevelAtoms: List, topLevelType: ConeKotlinType, - collectVariablesFromContext: Boolean, + allTypeVariables: List, postponedArguments: List, ) { while (true) { val variableForFixation = variableFixationFinder.findFirstVariableForFixation( - this, getOrderedAllTypeVariables(collectVariablesFromContext, topLevelAtoms), - postponedArguments, completionMode, topLevelType, + this, allTypeVariables, postponedArguments, completionMode, topLevelType, ) ?: break assert(!variableForFixation.hasProperConstraint) {