[NI] Don't always complete builder inference lambda in FULL mode

#KT-41164 Fixed
This commit is contained in:
Dmitriy Novozhilov
2020-08-20 15:04:52 +03:00
parent 6a15e0410f
commit e98cbf81cf
21 changed files with 181 additions and 10 deletions
@@ -22,6 +22,7 @@ interface InferenceSession {
override fun inferPostponedVariables(
lambda: ResolvedLambdaAtom,
initialStorage: ConstraintStorage,
completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode,
diagnosticsHolder: KotlinDiagnosticsHolder
): Map<TypeConstructor, UnwrappedType> = emptyMap()
@@ -44,6 +45,7 @@ interface InferenceSession {
fun inferPostponedVariables(
lambda: ResolvedLambdaAtom,
initialStorage: ConstraintStorage,
completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode,
diagnosticsHolder: KotlinDiagnosticsHolder
): Map<TypeConstructor, UnwrappedType>?
@@ -64,4 +66,4 @@ interface CompletedCallInfo {
interface ErrorCallInfo {
val callResolutionResult: CallResolutionResult
}
}
@@ -115,6 +115,7 @@ class KotlinCallCompleter(
firstCandidate.getSystem().asPostponedArgumentsAnalyzerContext(),
resolutionCallbacks,
firstAtom,
ConstraintSystemCompletionMode.FULL,
diagnosticHolderForLambda,
)
@@ -124,6 +125,7 @@ class KotlinCallCompleter(
candidate.getSystem().asPostponedArgumentsAnalyzerContext(),
atom,
results,
ConstraintSystemCompletionMode.FULL,
diagnosticHolderForLambda
)
}
@@ -228,6 +230,7 @@ class KotlinCallCompleter(
constraintSystem.asPostponedArgumentsAnalyzerContext(),
resolutionCallbacks,
it,
completionMode,
diagnosticsHolder
)
}
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
@@ -47,15 +48,20 @@ class PostponedArgumentsAnalyzer(
c: Context,
resolutionCallbacks: KotlinResolutionCallbacks,
argument: ResolvedAtom,
completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode,
diagnosticsHolder: KotlinDiagnosticsHolder
) {
when (argument) {
is ResolvedLambdaAtom ->
analyzeLambda(c, resolutionCallbacks, argument, diagnosticsHolder)
analyzeLambda(c, resolutionCallbacks, argument, completionMode, diagnosticsHolder)
is LambdaWithTypeVariableAsExpectedTypeAtom ->
analyzeLambda(
c, resolutionCallbacks, argument.transformToResolvedLambda(c.getBuilder(), diagnosticsHolder), diagnosticsHolder
c,
resolutionCallbacks,
argument.transformToResolvedLambda(c.getBuilder(), diagnosticsHolder),
completionMode,
diagnosticsHolder
)
is ResolvedCallableReferenceAtom ->
@@ -84,6 +90,7 @@ class PostponedArgumentsAnalyzer(
c: Context,
resolutionCallbacks: KotlinResolutionCallbacks,
lambda: ResolvedLambdaAtom,
completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode,
diagnosticHolder: KotlinDiagnosticsHolder,
): ReturnArgumentsAnalysisResult {
val substitutorAndStubsForLambdaAnalysis = c.createSubstituteFunctorForLambdaAnalysis()
@@ -142,7 +149,7 @@ class PostponedArgumentsAnalyzer(
convertedAnnotations ?: Annotations.EMPTY,
substitutorAndStubsForLambdaAnalysis.stubsForPostponedVariables.cast(),
)
applyResultsOfAnalyzedLambdaToCandidateSystem(c, lambda, returnArgumentsAnalysisResult, diagnosticHolder, substitute)
applyResultsOfAnalyzedLambdaToCandidateSystem(c, lambda, returnArgumentsAnalysisResult, completionMode, diagnosticHolder, substitute)
return returnArgumentsAnalysisResult
}
@@ -150,6 +157,7 @@ class PostponedArgumentsAnalyzer(
c: Context,
lambda: ResolvedLambdaAtom,
returnArgumentsAnalysisResult: ReturnArgumentsAnalysisResult,
completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode,
diagnosticHolder: KotlinDiagnosticsHolder,
substitute: (KotlinType) -> UnwrappedType = c.createSubstituteFunctorForLambdaAnalysis().substitute
) {
@@ -191,7 +199,12 @@ class PostponedArgumentsAnalyzer(
if (inferenceSession != null && lambda.atom.hasBuilderInferenceAnnotation) {
val storageSnapshot = c.getBuilder().currentStorage()
val postponedVariables = inferenceSession.inferPostponedVariables(lambda, storageSnapshot, diagnosticHolder)
val postponedVariables = inferenceSession.inferPostponedVariables(
lambda,
storageSnapshot,
completionMode,
diagnosticHolder
)
if (postponedVariables == null) {
c.getBuilder().removePostponedVariables()
return
@@ -73,10 +73,11 @@ class KotlinConstraintSystemCompleter(
c: Context,
topLevelType: UnwrappedType,
topLevelAtoms: List<ResolvedAtom>,
completionMode: ConstraintSystemCompletionMode,
diagnosticsHolder: KotlinDiagnosticsHolder
) {
c.runCompletion(
ConstraintSystemCompletionMode.FULL,
completionMode,
topLevelAtoms,
topLevelType,
diagnosticsHolder,