diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt index 0f060730aa1..efd033acb22 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.returnExpressions import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirErrorFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirErrorPropertySymbol -import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind @@ -109,7 +109,7 @@ class CandidateFactory private constructor( } } -fun PostponedArgumentsAnalyzer.Context.addSubsystemFromExpression(statement: FirStatement) { +fun PostponedArgumentsAnalyzerContext.addSubsystemFromExpression(statement: FirStatement) { when (statement) { is FirFunctionCall, is FirQualifiedAccessExpression, 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 f334c23ec9d..692784f6f9e 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 @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.StoreNameReference import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef -import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition @@ -48,7 +48,7 @@ class PostponedArgumentsAnalyzer( ) { fun analyze( - c: PostponedArgumentsAnalyzer.Context, + c: PostponedArgumentsAnalyzerContext, argument: PostponedResolvedAtom, candidate: Candidate //diagnosticsHolder: KotlinDiagnosticsHolder @@ -96,7 +96,7 @@ class PostponedArgumentsAnalyzer( } private fun analyzeLambda( - c: PostponedArgumentsAnalyzer.Context, + c: PostponedArgumentsAnalyzerContext, lambda: ResolvedLambdaAtom, candidate: Candidate //diagnosticHolder: KotlinDiagnosticsHolder diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt index 929ca7905e0..909570073cd 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzer.kt @@ -11,10 +11,8 @@ import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType 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.ConstraintSystemCompletionMode -import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPositionImpl import org.jetbrains.kotlin.resolve.calls.model.* @@ -27,24 +25,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast class PostponedArgumentsAnalyzer( private val callableReferenceResolver: CallableReferenceResolver ) { - interface Context : TypeSystemInferenceExtensionContext { - fun buildCurrentSubstitutor(additionalBindings: Map): TypeSubstitutorMarker - fun buildNotFixedVariablesToStubTypesSubstitutor(): TypeSubstitutorMarker - fun bindingStubsForPostponedVariables(): Map - - // type can be proper if it not contains not fixed type variables - fun canBeProper(type: KotlinTypeMarker): Boolean - - fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean - - // mutable operations - fun addOtherSystem(otherSystem: ConstraintStorage) - - fun getBuilder(): ConstraintSystemBuilder - } fun analyze( - c: Context, + c: PostponedArgumentsAnalyzerContext, resolutionCallbacks: KotlinResolutionCallbacks, argument: ResolvedAtom, completionMode: ConstraintSystemCompletionMode, @@ -77,7 +60,7 @@ class PostponedArgumentsAnalyzer( val substitute: (KotlinType) -> UnwrappedType ) - fun Context.createSubstituteFunctorForLambdaAnalysis(): SubstitutorAndStubsForLambdaAnalysis { + fun PostponedArgumentsAnalyzerContext.createSubstituteFunctorForLambdaAnalysis(): SubstitutorAndStubsForLambdaAnalysis { val stubsForPostponedVariables = bindingStubsForPostponedVariables() val currentSubstitutor = buildCurrentSubstitutor(stubsForPostponedVariables.mapKeys { it.key.freshTypeConstructor(this) }) return SubstitutorAndStubsForLambdaAnalysis(stubsForPostponedVariables) { @@ -86,7 +69,7 @@ class PostponedArgumentsAnalyzer( } fun analyzeLambda( - c: Context, + c: PostponedArgumentsAnalyzerContext, resolutionCallbacks: KotlinResolutionCallbacks, lambda: ResolvedLambdaAtom, completionMode: ConstraintSystemCompletionMode, @@ -153,7 +136,7 @@ class PostponedArgumentsAnalyzer( } fun applyResultsOfAnalyzedLambdaToCandidateSystem( - c: Context, + c: PostponedArgumentsAnalyzerContext, lambda: ResolvedLambdaAtom, returnArgumentsAnalysisResult: ReturnArgumentsAnalysisResult, completionMode: ConstraintSystemCompletionMode, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt new file mode 100644 index 00000000000..35788d0fda6 --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.calls.components + +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder +import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.types.model.* + +interface PostponedArgumentsAnalyzerContext : TypeSystemInferenceExtensionContext { + fun buildCurrentSubstitutor(additionalBindings: Map): TypeSubstitutorMarker + fun buildNotFixedVariablesToStubTypesSubstitutor(): TypeSubstitutorMarker + fun bindingStubsForPostponedVariables(): Map + + // type can be proper if it not contains not fixed type variables + fun canBeProper(type: KotlinTypeMarker): Boolean + + fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean + + // mutable operations + fun addOtherSystem(otherSystem: ConstraintStorage) + + fun getBuilder(): ConstraintSystemBuilder +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/DescriptorRelatedInferenceUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/DescriptorRelatedInferenceUtils.kt index 0db48ad6ea1..2f609229046 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/DescriptorRelatedInferenceUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/DescriptorRelatedInferenceUtils.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.resolve.calls.inference import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgument @@ -61,7 +61,7 @@ fun CallableDescriptor.substituteAndApproximateTypes( return substitute(TypeSubstitutor.create(wrappedSubstitution)) ?: this } -fun PostponedArgumentsAnalyzer.Context.addSubsystemFromArgument(argument: KotlinCallArgument?): Boolean { +fun PostponedArgumentsAnalyzerContext.addSubsystemFromArgument(argument: KotlinCallArgument?): Boolean { return when (argument) { is SubKotlinCallArgument -> { addOtherSystem(argument.callResult.constraintSystem) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/NewConstraintSystem.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/NewConstraintSystem.kt index 3b8499253ab..8b3336731d2 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/NewConstraintSystem.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/NewConstraintSystem.kt @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.resolve.calls.inference -import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext import org.jetbrains.kotlin.resolve.calls.inference.components.PostponedArgumentInputTypesResolver import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage @@ -32,6 +32,6 @@ interface NewConstraintSystem { fun asReadOnlyStorage(): ConstraintStorage fun asConstraintSystemCompleterContext(): ConstraintSystemCompletionContext - fun asPostponedArgumentsAnalyzerContext(): PostponedArgumentsAnalyzer.Context + fun asPostponedArgumentsAnalyzerContext(): PostponedArgumentsAnalyzerContext fun asPostponedArgumentInputTypesResolverContext(): PostponedArgumentInputTypesResolver.Context } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index 494308f9a4b..5004e3b60c5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.model -import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.* import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom @@ -29,7 +29,7 @@ class NewConstraintSystemImpl( ResultTypeResolver.Context, ConstraintSystemCompletionContext, PostponedArgumentInputTypesResolver.Context, - PostponedArgumentsAnalyzer.Context { + PostponedArgumentsAnalyzerContext { private val storage = MutableConstraintStorage() private var state = State.BUILDING private val typeVariablesTransaction: MutableList = SmartList()