K2: introduce fun interface PostponedAtomAnalyzer to make code cleaner
This commit is contained in:
committed by
Space Team
parent
9b2fc061e5
commit
8217aa9633
+14
-10
@@ -38,6 +38,10 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
private val postponedArgumentsInputTypesResolver = inferenceComponents.postponedArgumentInputTypesResolver
|
private val postponedArgumentsInputTypesResolver = inferenceComponents.postponedArgumentInputTypesResolver
|
||||||
private val languageVersionSettings = components.session.languageVersionSettings
|
private val languageVersionSettings = components.session.languageVersionSettings
|
||||||
|
|
||||||
|
fun interface PostponedAtomAnalyzer {
|
||||||
|
fun analyze(postponedResolvedAtom: PostponedResolvedAtom, withPCLASession: Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
fun complete(
|
fun complete(
|
||||||
c: ConstraintSystemCompletionContext,
|
c: ConstraintSystemCompletionContext,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
@@ -45,8 +49,8 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
candidateReturnType: ConeKotlinType,
|
candidateReturnType: ConeKotlinType,
|
||||||
context: ResolutionContext,
|
context: ResolutionContext,
|
||||||
collectVariablesFromContext: Boolean = false,
|
collectVariablesFromContext: Boolean = false,
|
||||||
analyze: (PostponedResolvedAtom, Boolean) -> Unit,
|
analyzer: PostponedAtomAnalyzer,
|
||||||
) = c.runCompletion(completionMode, topLevelAtoms, candidateReturnType, context, collectVariablesFromContext, analyze)
|
) = c.runCompletion(completionMode, topLevelAtoms, candidateReturnType, context, collectVariablesFromContext, analyzer)
|
||||||
|
|
||||||
private fun ConstraintSystemCompletionContext.runCompletion(
|
private fun ConstraintSystemCompletionContext.runCompletion(
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
@@ -54,7 +58,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
topLevelType: ConeKotlinType,
|
topLevelType: ConeKotlinType,
|
||||||
context: ResolutionContext,
|
context: ResolutionContext,
|
||||||
collectVariablesFromContext: Boolean = false,
|
collectVariablesFromContext: Boolean = false,
|
||||||
analyze: (PostponedResolvedAtom, Boolean) -> Unit,
|
analyzer: PostponedAtomAnalyzer,
|
||||||
) {
|
) {
|
||||||
val topLevelTypeVariables = topLevelType.extractTypeVariables()
|
val topLevelTypeVariables = topLevelType.extractTypeVariables()
|
||||||
|
|
||||||
@@ -74,7 +78,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
|
|
||||||
// Stage 1: analyze postponed arguments with fixed parameter types
|
// Stage 1: analyze postponed arguments with fixed parameter types
|
||||||
if (analyzeArgumentWithFixedParameterTypes(languageVersionSettings, postponedArguments) {
|
if (analyzeArgumentWithFixedParameterTypes(languageVersionSettings, postponedArguments) {
|
||||||
analyze(it, /* withPCLASession = */ false)
|
analyzer.analyze(it, withPCLASession = false)
|
||||||
}
|
}
|
||||||
) continue
|
) continue
|
||||||
|
|
||||||
@@ -142,7 +146,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
|
|
||||||
// Stage 5: analyze the next ready postponed argument
|
// Stage 5: analyze the next ready postponed argument
|
||||||
if (analyzeNextReadyPostponedArgument(languageVersionSettings, postponedArguments, completionMode) {
|
if (analyzeNextReadyPostponedArgument(languageVersionSettings, postponedArguments, completionMode) {
|
||||||
analyze(it, /* withPCLASession = */ false)
|
analyzer.analyze(it, withPCLASession = false)
|
||||||
}
|
}
|
||||||
) continue
|
) continue
|
||||||
|
|
||||||
@@ -152,7 +156,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
|
|
||||||
// Stage 7: try to complete call with the builder inference if there are uninferred type variables
|
// Stage 7: try to complete call with the builder inference if there are uninferred type variables
|
||||||
val areThereAppearedProperConstraintsForSomeVariable = tryToCompleteWithPCLA(
|
val areThereAppearedProperConstraintsForSomeVariable = tryToCompleteWithPCLA(
|
||||||
completionMode, postponedArguments, analyze,
|
completionMode, postponedArguments, analyzer,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (areThereAppearedProperConstraintsForSomeVariable)
|
if (areThereAppearedProperConstraintsForSomeVariable)
|
||||||
@@ -162,7 +166,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
// Complete all lambdas, maybe with fixing type variables used as top-level input types.
|
// Complete all lambdas, maybe with fixing type variables used as top-level input types.
|
||||||
// It's necessary because we need to process all data-flow info before going to the next statement.
|
// It's necessary because we need to process all data-flow info before going to the next statement.
|
||||||
if (analyzeRemainingNotAnalyzedPostponedArgument(postponedArguments) {
|
if (analyzeRemainingNotAnalyzedPostponedArgument(postponedArguments) {
|
||||||
analyze(it, /* withPCLASession = */ false)
|
analyzer.analyze(it, withPCLASession = false)
|
||||||
}
|
}
|
||||||
) continue
|
) continue
|
||||||
reportNotEnoughInformationForTypeVariablesRequiredForInputTypesOfLambdas(
|
reportNotEnoughInformationForTypeVariablesRequiredForInputTypesOfLambdas(
|
||||||
@@ -178,7 +182,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
// Stage 9: force analysis of remaining not analyzed postponed arguments and rerun stages if there are
|
// Stage 9: force analysis of remaining not analyzed postponed arguments and rerun stages if there are
|
||||||
if (completionMode.allLambdasShouldBeAnalyzed) {
|
if (completionMode.allLambdasShouldBeAnalyzed) {
|
||||||
if (analyzeRemainingNotAnalyzedPostponedArgument(postponedArguments) {
|
if (analyzeRemainingNotAnalyzedPostponedArgument(postponedArguments) {
|
||||||
analyze(it, /* withPCLASession = */ false)
|
analyzer.analyze(it, withPCLASession = false)
|
||||||
}
|
}
|
||||||
) continue
|
) continue
|
||||||
}
|
}
|
||||||
@@ -239,7 +243,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
private fun ConstraintSystemCompletionContext.tryToCompleteWithPCLA(
|
private fun ConstraintSystemCompletionContext.tryToCompleteWithPCLA(
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
postponedArguments: List<PostponedResolvedAtom>,
|
postponedArguments: List<PostponedResolvedAtom>,
|
||||||
analyze: (PostponedResolvedAtom, Boolean) -> Unit,
|
analyzer: PostponedAtomAnalyzer,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!completionMode.allLambdasShouldBeAnalyzed) return false
|
if (!completionMode.allLambdasShouldBeAnalyzed) return false
|
||||||
|
|
||||||
@@ -253,7 +257,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents) {
|
|||||||
val notFixedInputTypeVariables = argument.inputTypes.flatMap { it.extractTypeVariables() }.filter { it !in fixedTypeVariables }
|
val notFixedInputTypeVariables = argument.inputTypes.flatMap { it.extractTypeVariables() }.filter { it !in fixedTypeVariables }
|
||||||
|
|
||||||
if (notFixedInputTypeVariables.isEmpty()) continue
|
if (notFixedInputTypeVariables.isEmpty()) continue
|
||||||
analyze(argument, /* withPCLASession = */ true)
|
analyzer.analyze(argument, withPCLASession = true)
|
||||||
|
|
||||||
anyAnalyzed = true
|
anyAnalyzed = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user