diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt index 0a8e0212e11..a73d5579b4b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt @@ -13,10 +13,8 @@ import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.candidate import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor -import org.jetbrains.kotlin.fir.resolve.transformers.FirCallCompletionResultsWriterTransformer import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.coneTypeUnsafe -import org.jetbrains.kotlin.fir.visitors.transformSingle import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt index f46564b1a10..897cd2747ba 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.TypeVariableDirec import org.jetbrains.kotlin.resolve.calls.inference.components.VariableFixationFinder import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints -import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtom import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker @@ -97,12 +96,13 @@ private fun Candidate.hasProperNonTrivialLowerConstraints(components: InferenceC class ConstraintSystemCompleter(val components: InferenceComponents) { private val variableFixationFinder = VariableFixationFinder(components.trivialConstraintTypeInferenceOracle) + fun complete( c: KotlinConstraintSystemCompleter.Context, completionMode: KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode, topLevelAtoms: List, candidateReturnType: ConeKotlinType, - analyze: (PostponedResolvedAtomMarker) -> Unit + analyze: (PostponedResolvedAtom) -> Unit ) { while (true) { @@ -198,7 +198,7 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { private fun analyzePostponeArgumentIfPossible( c: KotlinConstraintSystemCompleter.Context, topLevelAtoms: List, - analyze: (PostponedResolvedAtomMarker) -> Unit + analyze: (PostponedResolvedAtom) -> Unit ): Boolean { for (argument in getOrderedNotAnalyzedPostponedArguments(topLevelAtoms)) { if (canWeAnalyzeIt(c, argument)) { @@ -209,8 +209,8 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { return false } - private fun getOrderedNotAnalyzedPostponedArguments(topLevelAtoms: List): List { - val notAnalyzedArguments = arrayListOf() + private fun getOrderedNotAnalyzedPostponedArguments(topLevelAtoms: List): List { + val notAnalyzedArguments = arrayListOf() for (primitive in topLevelAtoms) { primitive.processAllContainingCallCandidates( // TODO: remove this argument and relevant parameter @@ -218,7 +218,7 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { processBlocks = true ) { candidate -> candidate.postponedAtoms.forEach { - notAnalyzedArguments.addIfNotNull(it.safeAs()?.takeUnless { it.analyzed }) + notAnalyzedArguments.addIfNotNull(it.safeAs()?.takeUnless { it.analyzed }) } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index 9b24984b1c1..bc83ada8948 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -44,11 +44,6 @@ fun Candidate.preprocessLambdaArgument( // TODO: add SAM conversion processing val lambdaType = createFunctionalType(resolvedArgument.parameters, resolvedArgument.receiver, resolvedArgument.returnType) csBuilder.addSubtypeConstraint(lambdaType, expectedType, SimpleConstraintSystemConstraintPosition) -// val lambdaType = createFunctionType( -// csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver, -// resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend -// ) -// csBuilder.addSubtypeConstraint(lambdaType, expectedType, ArgumentConstraintPosition(argument)) } postponedAtoms += resolvedArgument @@ -203,6 +198,12 @@ private fun ConeKotlinType.extractParametersForFunctionalType( class TypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, name: String) : ConeTypeVariable(name) +sealed class PostponedResolvedAtom : PostponedResolvedAtomMarker { + abstract override val inputTypes: Collection + abstract override val outputType: ConeKotlinType? + override var analyzed: Boolean = false +} + class ResolvedLambdaAtom( val atom: FirAnonymousFunction, val isSuspend: Boolean, @@ -210,21 +211,9 @@ class ResolvedLambdaAtom( val parameters: List, val returnType: ConeKotlinType, val typeVariableForLambdaReturnType: TypeVariableForLambdaReturnType? -) : PostponedResolvedAtomMarker { - override var analyzed: Boolean = false +) : PostponedResolvedAtom() { lateinit var returnStatements: Collection -// lateinit var resultArguments: List -// private set - -// fun setAnalyzedResults( -// resultArguments: List, -// subResolvedAtoms: List -// ) { -// this.resultArguments = resultArguments -// setAnalyzedResults(subResolvedAtoms) -// } - override val inputTypes: Collection get() = receiver?.let { parameters + it } ?: parameters override val outputType: ConeKotlinType get() = returnType } @@ -234,8 +223,7 @@ class ResolvedCallableReferenceAtom( val expectedType: ConeKotlinType?, val lhs: DoubleColonLHS?, private val session: FirSession -) : PostponedResolvedAtomMarker { - override var analyzed: Boolean = false +) : PostponedResolvedAtom() { var postponed: Boolean = false var resultingCandidate: Pair? = null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt index e8799d745c1..b32167b1285 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt @@ -49,8 +49,7 @@ class PostponedArgumentsAnalyzer( fun analyze( c: PostponedArgumentsAnalyzer.Context, -// resolutionCallbacks: KotlinResolutionCallbacks, - argument: PostponedResolvedAtomMarker, + argument: PostponedResolvedAtom, candidate: Candidate //diagnosticsHolder: KotlinDiagnosticsHolder ) { @@ -66,8 +65,6 @@ class PostponedArgumentsAnalyzer( is ResolvedCallableReferenceAtom -> processCallableReference(argument, candidate) // // is ResolvedCollectionLiteralAtom -> TODO("Not supported") - - else -> error("Unexpected resolved primitive: ${argument.javaClass.canonicalName}") } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeVariableDirectionCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeVariableDirectionCalculator.kt index e8f0f42e494..16b8d3c00aa 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeVariableDirectionCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeVariableDirectionCalculator.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints -import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtom +import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.model.FlexibleTypeMarker import org.jetbrains.kotlin.types.model.KotlinTypeMarker @@ -32,7 +32,7 @@ private typealias Variable = VariableWithConstraints class TypeVariableDirectionCalculator( private val c: VariableFixationFinder.Context, - private val postponedKtPrimitives: List, + private val postponedKtPrimitives: List, topLevelType: KotlinTypeMarker ) { enum class ResolveDirection {