diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt index 95be35525a4..bd63c95101c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors import org.jetbrains.kotlin.resolve.calls.components.* +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem @@ -112,7 +113,7 @@ class InferenceSessionForExistingCandidates( private val resolveReceiverIndependently: Boolean, override val parentSession: InferenceSession? ) : InferenceSession { - override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean { + override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean { return !ErrorUtils.isError(candidate.resolvedCall.candidateDescriptor) } @@ -135,7 +136,7 @@ class InferenceSessionForExistingCandidates( } override fun computeCompletionMode( - candidate: KotlinResolutionCandidate + candidate: ResolutionCandidate ): ConstraintSystemCompletionMode? = null override fun resolveReceiverIndependently(): Boolean = resolveReceiverIndependently diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt index 4579df69249..dfab56a5f2e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver import org.jetbrains.kotlin.resolve.calls.util.shouldBeSubstituteWithStubTypes import org.jetbrains.kotlin.resolve.calls.util.toOldSubstitution import org.jetbrains.kotlin.resolve.calls.components.* +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.resolve.calls.inference.model.* @@ -80,7 +81,7 @@ class BuilderInferenceSession( override val parentSession = topLevelCallContext.inferenceSession - override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean { + override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean { val system = candidate.getSystem() as NewConstraintSystemImpl if (system.hasContradiction) return true diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index bc4c710419e..91e11562efe 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -309,7 +309,7 @@ class KotlinResolutionCallbacksImpl( return convertSignedConstantToUnsigned(argumentExpression) } - override fun recordInlinabilityOfLambda(atom: Set>) { + override fun recordInlinabilityOfLambda(atom: Set>) { val call = atom.first().value.atom.psiCallArgument.valueArgument as? KtLambdaArgument ?: return val literal = call.getLambdaExpression()?.functionLiteral ?: return val isLambdaInline = atom.all { (candidate, atom) -> diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt index 9e843f0cf50..dd91baac8ec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.resolve.calls.components.* +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode @@ -40,7 +41,7 @@ abstract class ManyCandidatesResolver( // do nothing } - override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean { + override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean { return false } @@ -168,7 +169,7 @@ abstract class ManyCandidatesResolver( return allCandidates } - override fun computeCompletionMode(candidate: KotlinResolutionCandidate) = null + override fun computeCompletionMode(candidate: ResolutionCandidate) = null override fun resolveReceiverIndependently(): Boolean = false diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index d2371f4dbfb..89d8517a1eb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -487,6 +487,10 @@ class NewResolutionOldInference( } } + override fun createErrorCandidate(): MyCandidate { + throw IllegalStateException("Not supported creating error candidate for the old type inference candidate factory") + } + private fun createDiagnosticsForCandidate( towerCandidate: CandidateWithBoundDispatchReceiver, candidateCall: ResolvedCallImpl diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 5cff39fd473..7c99973fca1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.util.* import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver import org.jetbrains.kotlin.resolve.calls.components.InferenceSession import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor @@ -327,12 +328,12 @@ class PSICallResolver( private fun CallResolutionResult.isEmpty(): Boolean = diagnostics.firstIsInstanceOrNull() != null - private fun Collection.areAllFailed() = + private fun Collection.areAllFailed() = all { !it.resultingApplicability.isSuccess } - private fun Collection.areAllFailedWithInapplicableWrongReceiver() = + private fun Collection.areAllFailedWithInapplicableWrongReceiver() = all { it.resultingApplicability == CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER } @@ -458,18 +459,18 @@ class PSICallResolver( val context: BasicCallResolutionContext, val scopeTower: ImplicitScopeTower, val kotlinCall: PSIKotlinCallImpl - ) : CandidateFactoryProviderForInvoke { + ) : CandidateFactoryProviderForInvoke { init { assert(kotlinCall.dispatchReceiverForInvokeExtension == null) { kotlinCall } } override fun transformCandidate( - variable: KotlinResolutionCandidate, - invoke: KotlinResolutionCandidate + variable: ResolutionCandidate, + invoke: ResolutionCandidate ) = invoke - override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory { + override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory { val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name) return SimpleCandidateFactory( @@ -477,8 +478,8 @@ class PSICallResolver( ) } - override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean): - Pair>? { + override fun factoryForInvoke(variable: ResolutionCandidate, useExplicitReceiver: Boolean): + Pair>? { if (isRecursiveVariableResolution(variable)) return null assert(variable.isSuccessful) { @@ -500,13 +501,13 @@ class PSICallResolver( } // todo: create special check that there is no invoke on variable - private fun isRecursiveVariableResolution(variable: KotlinResolutionCandidate): Boolean { + private fun isRecursiveVariableResolution(variable: ResolutionCandidate): Boolean { val variableType = variable.resolvedCall.candidateDescriptor.returnType return variableType is DeferredType && variableType.isComputing } // todo: review - private fun createReceiverCallArgument(variable: KotlinResolutionCandidate): SimpleKotlinCallArgument { + private fun createReceiverCallArgument(variable: ResolutionCandidate): SimpleKotlinCallArgument { variable.forceResolution() val variableReceiver = createReceiverValueWithSmartCastInfo(variable) if (variableReceiver.hasTypesFromSmartCasts()) { @@ -528,7 +529,7 @@ class PSICallResolver( } // todo: decrease hacks count - private fun createReceiverValueWithSmartCastInfo(variable: KotlinResolutionCandidate): ReceiverValueWithSmartCastInfo { + private fun createReceiverValueWithSmartCastInfo(variable: ResolutionCandidate): ReceiverValueWithSmartCastInfo { val callForVariable = variable.resolvedCall.atom as PSIKotlinCallForVariable val calleeExpression = callForVariable.baseCall.psiCall.calleeExpression as? KtReferenceExpression ?: error("Unexpected call : ${callForVariable.baseCall.psiCall}") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt index e40ec30f72c..15e34487f9e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.Call import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.calls.CallTransformer +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo @@ -93,7 +94,7 @@ class PSIKotlinCallForVariable( class PSIKotlinCallForInvoke( val baseCall: PSIKotlinCallImpl, - val variableCall: KotlinResolutionCandidate, + val variableCall: ResolutionCandidate, override val explicitReceiver: ReceiverKotlinCallArgument, override val dispatchReceiverForInvokeExtension: SimpleKotlinCallArgument? ) : PSIKotlinCall() { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 70d3423a83f..604bdf4b69c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -21,10 +21,8 @@ import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator import org.jetbrains.kotlin.resolve.calls.util.toOldSubstitution import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext import org.jetbrains.kotlin.resolve.calls.commonSuperType -import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation -import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate -import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy -import org.jetbrains.kotlin.resolve.calls.components.isVararg +import org.jetbrains.kotlin.resolve.calls.components.* +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession @@ -401,7 +399,7 @@ class ResolvedAtomCompleter( } private fun extractCallableReferenceResultTypeInfoFromDescriptor( - callableCandidate: CallableReferenceCandidate, + callableCandidate: CallableReferenceResolutionCandidate, recordedDescriptor: CallableDescriptor ): CallableReferenceResultTypeInfo { val dispatchReceiver = recordedDescriptor.dispatchReceiverParameter?.value diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt index b118347753f..541f4b39752 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver import org.jetbrains.kotlin.resolve.calls.components.KotlinCallCompleter import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks import org.jetbrains.kotlin.resolve.calls.components.NewOverloadingConflictResolver +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.* @@ -32,7 +33,7 @@ class KotlinCallResolver( kotlinCall: KotlinCall, expectedType: UnwrappedType?, collectAllCandidates: Boolean, - createFactoryProviderForInvoke: () -> CandidateFactoryProviderForInvoke + createFactoryProviderForInvoke: () -> CandidateFactoryProviderForInvoke ): CallResolutionResult { ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() @@ -120,7 +121,7 @@ class KotlinCallResolver( candidateFactory: SimpleCandidateFactory, resolutionCallbacks: KotlinResolutionCallbacks, expectedType: UnwrappedType?, - candidates: Collection + candidates: Collection ): CallResolutionResult { var refinedCandidates = candidates if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.RefinedSamAdaptersPriority)) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt deleted file mode 100644 index 7a84a88869a..00000000000 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010-2021 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.descriptors.CallableDescriptor -import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor -import org.jetbrains.kotlin.resolve.calls.model.CompatibilityWarning -import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic -import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind -import org.jetbrains.kotlin.resolve.calls.tower.Candidate -import org.jetbrains.kotlin.resolve.calls.tower.getResultApplicability -import org.jetbrains.kotlin.resolve.calls.tower.isSuccess -import org.jetbrains.kotlin.types.UnwrappedType - -/** - * Suppose we have class A with staticM, memberM, memberExtM. - * For A::staticM both receivers will be null - * For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null - * For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver - * - * For class B with companion object B::companionM dispatchReceiver = BoundValueReference - */ -class CallableReferenceCandidate( - val candidate: CallableDescriptor, - val dispatchReceiver: CallableReceiver?, - val extensionReceiver: CallableReceiver?, - val explicitReceiverKind: ExplicitReceiverKind, - val reflectionCandidateType: UnwrappedType, - val callableReferenceAdaptation: CallableReferenceAdaptation?, - initialDiagnostics: List -) : Candidate { - private val mutableDiagnostics = initialDiagnostics.toMutableList() - val diagnostics: List = mutableDiagnostics - - override val resultingApplicability = getResultApplicability(diagnostics) - - override fun addCompatibilityWarning(other: Candidate) { - if (this !== other && other is CallableReferenceCandidate) { - mutableDiagnostics.add(CompatibilityWarning(other.candidate)) - } - } - - override val isSuccessful get() = resultingApplicability.isSuccess - - var freshSubstitutor: FreshVariableNewTypeSubstitutor? = null - internal set - - val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0 -} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt index d97f7389295..2c4bcb01d80 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt @@ -24,7 +24,7 @@ typealias CsCompleterContext = ConstraintSystemCompletionContext class CompletionModeCalculator { companion object { fun computeCompletionMode( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, expectedType: UnwrappedType?, returnType: UnwrappedType?, trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, @@ -53,7 +53,7 @@ class CompletionModeCalculator { } private class CalculatorForNestedCall( - private val candidate: KotlinResolutionCandidate, + private val candidate: ResolutionCandidate, private val returnType: UnwrappedType?, private val csCompleterContext: CsCompleterContext, private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 95812bb77e7..022fe3ae7aa 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -89,5 +89,5 @@ interface KotlinResolutionCallbacks { fun convertSignedConstantToUnsigned(argument: KotlinCallArgument): IntegerValueTypeConstant? - fun recordInlinabilityOfLambda(atom: Set>) + fun recordInlinabilityOfLambda(atom: Set>) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt index 1c3421e71c1..dd5ca10bc69 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.resolve.calls.components +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.model.* @@ -18,7 +19,7 @@ interface InferenceSession { val default = object : InferenceSession { override val parentSession: InferenceSession? = null - override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean = true + override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean = true override fun addPartialCallInfo(callInfo: PartialCallInfo) {} override fun addErrorCallInfo(callInfo: ErrorCallInfo) {} override fun addCompletedCallInfo(callInfo: CompletedCallInfo) {} @@ -36,14 +37,14 @@ interface InferenceSession { override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true override fun computeCompletionMode( - candidate: KotlinResolutionCandidate + candidate: ResolutionCandidate ): ConstraintSystemCompletionMode? = null override fun resolveReceiverIndependently(): Boolean = false } } - fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean + fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean fun addPartialCallInfo(callInfo: PartialCallInfo) fun addCompletedCallInfo(callInfo: CompletedCallInfo) fun addErrorCallInfo(callInfo: ErrorCallInfo) @@ -60,7 +61,7 @@ interface InferenceSession { fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean fun callCompleted(resolvedAtom: ResolvedAtom): Boolean fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom): Boolean - fun computeCompletionMode(candidate: KotlinResolutionCandidate): ConstraintSystemCompletionMode? + fun computeCompletionMode(candidate: ResolutionCandidate): ConstraintSystemCompletionMode? fun resolveReceiverIndependently(): Boolean } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index c0a7a44e4ea..0111ce3db30 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -9,6 +9,9 @@ import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.SimpleResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.addEqualityConstraintIfCompatible import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter @@ -31,8 +34,8 @@ class KotlinCallCompleter( ) { fun runCompletion( - factory: SimpleCandidateFactory, - candidates: Collection, + factory: CandidateFactory, + candidates: Collection, expectedType: UnwrappedType?, resolutionCallbacks: KotlinResolutionCallbacks ): CallResolutionResult { @@ -75,9 +78,9 @@ class KotlinCallCompleter( } fun chooseCandidateRegardingOverloadResolutionByLambdaReturnType( - candidates: Set, + candidates: Set, resolutionCallbacks: KotlinResolutionCallbacks - ): Set { + ): Set { val lambdas = candidates.flatMap { candidate -> candidate.getSubResolvedAtoms() .filter { it is ResolvedLambdaAtom && !it.analyzed } @@ -130,8 +133,8 @@ class KotlinCallCompleter( ) } - val errorCandidates = mutableSetOf() - val successfulCandidates = mutableSetOf() + val errorCandidates = mutableSetOf() + val successfulCandidates = mutableSetOf() for (candidate in candidates) { if (candidate.isSuccessful) { @@ -146,7 +149,7 @@ class KotlinCallCompleter( } } - private fun KotlinResolutionCandidate.getInputTypesOfLambdaAtom(atom: ResolvedLambdaAtom): List { + private fun SimpleResolutionCandidate.getInputTypesOfLambdaAtom(atom: ResolvedLambdaAtom): List { val result = mutableListOf() val substitutor = csBuilder.buildCurrentSubstitutor() val ctx = getSystem().asConstraintSystemCompleterContext() @@ -157,7 +160,7 @@ class KotlinCallCompleter( } - private fun KotlinResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) { + private fun ResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) { val samConversionPerArgumentWithWarningsForVarargAfterSam = callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument) && !callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitVarargAsArrayAfterSamArgument) @@ -174,7 +177,7 @@ class KotlinCallCompleter( } fun createAllCandidatesResult( - candidates: Collection, + candidates: Collection, expectedType: UnwrappedType?, resolutionCallbacks: KotlinResolutionCallbacks ): CallResolutionResult { @@ -199,7 +202,7 @@ class KotlinCallCompleter( return AllCandidatesResolutionResult(completedCandidates) } - private fun KotlinResolutionCandidate.runCompletion( + private fun ResolutionCandidate.runCompletion( completionMode: ConstraintSystemCompletionMode, diagnosticHolder: KotlinDiagnosticsHolder, resolutionCallbacks: KotlinResolutionCallbacks, @@ -240,10 +243,10 @@ class KotlinCallCompleter( } private fun prepareCandidateForCompletion( - factory: SimpleCandidateFactory, - candidates: Collection, + factory: CandidateFactory, + candidates: Collection, resolutionCallbacks: KotlinResolutionCallbacks - ): KotlinResolutionCandidate { + ): ResolutionCandidate { val candidate = candidates.singleOrNull() // this is needed at least for non-local return checker, because when we analyze lambda we should already bind descriptor for outer call @@ -260,12 +263,12 @@ class KotlinCallCompleter( return candidate ?: factory.createErrorCandidate().forceResolution() } - private fun KotlinResolutionCandidate.substitutedReturnType(): UnwrappedType? { + private fun ResolutionCandidate.substitutedReturnType(): UnwrappedType? { val returnType = resolvedCall.candidateDescriptor.returnType?.unwrap() ?: return null return resolvedCall.freshVariablesSubstitutor.safeSubstitute(returnType) } - private fun KotlinResolutionCandidate.addExpectedTypeConstraint( + private fun ResolutionCandidate.addExpectedTypeConstraint( returnType: UnwrappedType?, expectedType: UnwrappedType? ) { @@ -294,7 +297,7 @@ class KotlinCallCompleter( } } - private fun KotlinResolutionCandidate.addExpectedTypeFromCastConstraint( + private fun ResolutionCandidate.addExpectedTypeFromCastConstraint( returnType: UnwrappedType?, resolutionCallbacks: KotlinResolutionCallbacks ) { @@ -304,7 +307,7 @@ class KotlinCallCompleter( csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPositionImpl(resolvedCall.atom)) } - fun KotlinResolutionCandidate.asCallResolutionResult( + fun ResolutionCandidate.asCallResolutionResult( type: ConstraintSystemCompletionMode, diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder, forwardToInferenceSession: Boolean = false @@ -324,6 +327,6 @@ class KotlinCallCompleter( } } -internal fun KotlinResolutionCandidate.isErrorCandidate(): Boolean { +internal fun ResolutionCandidate.isErrorCandidate(): Boolean { return ErrorUtils.isError(resolvedCall.candidateDescriptor) || hasContradiction } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt index db8f2b9d41d..b5f8b2a8e00 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument -import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallArgument import org.jetbrains.kotlin.resolve.calls.results.* import org.jetbrains.kotlin.types.KotlinType @@ -37,7 +37,7 @@ class NewOverloadingConflictResolver( statelessCallbacks: KotlinResolutionStatelessCallbacks, constraintInjector: ConstraintInjector, kotlinTypeRefiner: KotlinTypeRefiner, -) : OverloadingConflictResolver( +) : OverloadingConflictResolver( builtIns, module, specificityComparator, @@ -56,7 +56,7 @@ class NewOverloadingConflictResolver( ) { companion object { - private fun createFlatSignature(candidate: KotlinResolutionCandidate): FlatSignature { + private fun createFlatSignature(candidate: ResolutionCandidate): FlatSignature { val resolvedCall = candidate.resolvedCall val originalDescriptor = resolvedCall.candidateDescriptor.original diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 1e9d90927f3..9d7724a0627 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -11,6 +11,8 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.components.* @@ -35,7 +37,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible import org.jetbrains.kotlin.utils.addToStdlib.safeAs internal object CheckVisibility : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val containingDescriptor = scopeTower.lexicalScope.ownerDescriptor val dispatchReceiverArgument = resolvedCall.dispatchReceiverArgument @@ -62,7 +64,7 @@ internal object CheckVisibility : ResolutionPart() { } internal object MapTypeArguments : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { resolvedCall.typeArgumentMappingByOriginal = callComponents.typeArgumentsToParametersMapper.mapTypeArguments(kotlinCall, candidateDescriptor.original).also { it.diagnostics.forEach(this@process::addDiagnostic) @@ -71,7 +73,7 @@ internal object MapTypeArguments : ResolutionPart() { } internal object NoTypeArguments : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { assert(kotlinCall.typeArguments.isEmpty()) { "Variable call cannot has explicit type arguments: ${kotlinCall.typeArguments}. Call: $kotlinCall" } @@ -80,7 +82,7 @@ internal object NoTypeArguments : ResolutionPart() { } internal object MapArguments : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val mapping = callComponents.argumentsToParametersMapper.mapArguments(kotlinCall, candidateDescriptor) mapping.diagnostics.forEach(this::addDiagnostic) @@ -89,7 +91,7 @@ internal object MapArguments : ResolutionPart() { } internal object ArgumentsToCandidateParameterDescriptor : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val map = hashMapOf() for ((originalValueParameter, resolvedCallArgument) in resolvedCall.argumentMappingByOriginal) { val valueParameter = candidateDescriptor.valueParameters.getOrNull(originalValueParameter.index) ?: continue @@ -102,7 +104,7 @@ internal object ArgumentsToCandidateParameterDescriptor : ResolutionPart() { } internal object NoArguments : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { assert(kotlinCall.argumentsInParenthesis.isEmpty()) { "Variable call cannot has arguments: ${kotlinCall.argumentsInParenthesis}. Call: $kotlinCall" } @@ -116,7 +118,7 @@ internal object NoArguments : ResolutionPart() { internal object CreateFreshVariablesSubstitutor : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val toFreshVariables = if (candidateDescriptor.typeParameters.isEmpty()) FreshVariableNewTypeSubstitutor.Empty @@ -272,7 +274,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() { } internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { for ((argument, parameter) in resolvedCall.argumentToCandidateParameter) { if (!callComponents.statelessCallbacks.isBuilderInferenceCall(argument, parameter)) continue val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue @@ -299,7 +301,7 @@ internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() { } internal object CompatibilityOfTypeVariableAsIntersectionTypePart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { for ((_, variableWithConstraints) in csBuilder.currentStorage().notFixedTypeVariables) { val constraints = variableWithConstraints.constraints.filter { csBuilder.isProperType(it.type) } @@ -317,7 +319,7 @@ internal object CompatibilityOfTypeVariableAsIntersectionTypePart : ResolutionPa } internal object CompatibilityOfPartiallyApplicableSamConversion : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { if (resolvedCall.argumentsWithConversion.isEmpty()) return if (resolvedCall.argumentsWithConversion.size == candidateDescriptor.valueParameters.size) return @@ -339,14 +341,14 @@ internal object CompatibilityOfPartiallyApplicableSamConversion : ResolutionPart } internal object CheckExplicitReceiverKindConsistency : ResolutionPart() { - private fun KotlinResolutionCandidate.hasError(): Nothing = + private fun ResolutionCandidate.hasError(): Nothing = error( "Inconsistent call: $kotlinCall. \n" + "Candidate: $candidateDescriptor, explicitReceiverKind: ${resolvedCall.explicitReceiverKind}.\n" + "Explicit receiver: ${kotlinCall.explicitReceiver}, dispatchReceiverForInvokeExtension: ${kotlinCall.dispatchReceiverForInvokeExtension}" ) - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { when (resolvedCall.explicitReceiverKind) { NO_EXPLICIT_RECEIVER -> if (kotlinCall.explicitReceiver is SimpleKotlinCallArgument || kotlinCall.dispatchReceiverForInvokeExtension != null) hasError() DISPATCH_RECEIVER, EXTENSION_RECEIVER -> @@ -483,7 +485,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() { freshTypeConstructor.isContainedInInvariantOrContravariantPositions = true } - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { for (variable in resolvedCall.freshVariablesSubstitutor.freshVariables) { if (resolvedCall.candidateDescriptor is ClassConstructorDescriptor) { val typeParameters = resolvedCall.candidateDescriptor.containingDeclaration.declaredTypeParameters @@ -498,7 +500,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() { } } -private fun KotlinResolutionCandidate.resolveKotlinArgument( +private fun ResolutionCandidate.resolveKotlinArgument( argument: KotlinCallArgument, candidateParameter: ParameterDescriptor?, receiverInfo: ReceiverInfo @@ -598,7 +600,7 @@ private fun KotlinResolutionCandidate.resolveKotlinArgument( } } -private fun KotlinResolutionCandidate.shouldRunConversionForConstants(expectedType: UnwrappedType): Boolean { +private fun ResolutionCandidate.shouldRunConversionForConstants(expectedType: UnwrappedType): Boolean { if (UnsignedTypes.isUnsignedType(expectedType)) return true if (csBuilder.isTypeVariable(expectedType)) { val variableWithConstraints = csBuilder.currentStorage().notFixedTypeVariables[expectedType.constructor] ?: return false @@ -617,7 +619,7 @@ internal enum class ImplicitInvokeCheckStatus { NO_INVOKE, INVOKE_ON_NOT_NULL_VARIABLE, UNSAFE_INVOKE_REPORTED } -private fun KotlinResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(argument: SimpleKotlinCallArgument): ImplicitInvokeCheckStatus { +private fun ResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(argument: SimpleKotlinCallArgument): ImplicitInvokeCheckStatus { val variableForInvoke = variableCandidateIfInvoke ?: return ImplicitInvokeCheckStatus.NO_INVOKE val receiverArgument = with(variableForInvoke.resolvedCall) { @@ -637,13 +639,13 @@ private fun KotlinResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(arg return ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE } -private fun KotlinResolutionCandidate.prepareExpectedType(expectedType: UnwrappedType): UnwrappedType { +private fun ResolutionCandidate.prepareExpectedType(expectedType: UnwrappedType): UnwrappedType { val resultType = resolvedCall.freshVariablesSubstitutor.safeSubstitute(expectedType) return resolvedCall.knownParametersSubstitutor.safeSubstitute(resultType) } internal object CheckReceivers : ResolutionPart() { - private fun KotlinResolutionCandidate.checkReceiver( + private fun ResolutionCandidate.checkReceiver( receiverArgument: SimpleKotlinCallArgument?, receiverParameter: ReceiverParameterDescriptor?, shouldCheckImplicitInvoke: Boolean, @@ -666,7 +668,7 @@ internal object CheckReceivers : ResolutionPart() { resolveKotlinArgument(receiverArgument, receiverParameter, receiverInfo) } - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { if (workIndex == 0) { checkReceiver( resolvedCall.dispatchReceiverArgument, @@ -682,20 +684,20 @@ internal object CheckReceivers : ResolutionPart() { } } - override fun KotlinResolutionCandidate.workCount() = 2 + override fun ResolutionCandidate.workCount() = 2 } internal object CheckArgumentsInParenthesis : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val argument = kotlinCall.argumentsInParenthesis[workIndex] resolveKotlinArgument(argument, resolvedCall.argumentToCandidateParameter[argument], ReceiverInfo.notReceiver) } - override fun KotlinResolutionCandidate.workCount() = kotlinCall.argumentsInParenthesis.size + override fun ResolutionCandidate.workCount() = kotlinCall.argumentsInParenthesis.size } internal object CheckExternalArgument : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val argument = kotlinCall.externalArgument ?: return resolveKotlinArgument(argument, resolvedCall.argumentToCandidateParameter[argument], ReceiverInfo.notReceiver) @@ -703,7 +705,7 @@ internal object CheckExternalArgument : ResolutionPart() { } internal object EagerResolveOfCallableReferences : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { getSubResolvedAtoms() .filterIsInstance() .forEach { @@ -713,7 +715,7 @@ internal object EagerResolveOfCallableReferences : ResolutionPart() { } internal object CheckInfixResolutionPart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor if (candidateDescriptor !is FunctionDescriptor) return if (!candidateDescriptor.isInfix && callComponents.statelessCallbacks.isInfixCall(kotlinCall)) { @@ -723,7 +725,7 @@ internal object CheckInfixResolutionPart : ResolutionPart() { } internal object CheckOperatorResolutionPart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor if (candidateDescriptor !is FunctionDescriptor) return if (!candidateDescriptor.isOperator && callComponents.statelessCallbacks.isOperatorCall(kotlinCall)) { @@ -733,7 +735,7 @@ internal object CheckOperatorResolutionPart : ResolutionPart() { } internal object CheckSuperExpressionCallPart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor if (callComponents.statelessCallbacks.isSuperExpression(resolvedCall.dispatchReceiverArgument)) { @@ -750,7 +752,7 @@ internal object CheckSuperExpressionCallPart : ResolutionPart() { } internal object ErrorDescriptorResolutionPart : ResolutionPart() { - override fun KotlinResolutionCandidate.process(workIndex: Int) { + override fun ResolutionCandidate.process(workIndex: Int) { assert(ErrorUtils.isError(candidateDescriptor)) { "Should be error descriptor: $candidateDescriptor" } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt index ce7ac60415e..ca0b7b62248 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ParameterDescriptor import org.jetbrains.kotlin.incremental.record +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.sam.SAM_LOOKUP_NAME import org.jetbrains.kotlin.resolve.sam.getFunctionTypeForPossibleSamType @@ -19,7 +20,7 @@ import org.jetbrains.kotlin.types.typeUtil.isNothing object SamTypeConversions : ParameterTypeConversion { override fun conversionDefinitelyNotNeeded( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, expectedParameterType: UnwrappedType ): Boolean { @@ -72,7 +73,7 @@ object SamTypeConversions : ParameterTypeConversion { } override fun convertParameterType( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, parameter: ParameterDescriptor, expectedParameterType: UnwrappedType @@ -118,7 +119,7 @@ object SamTypeConversions : ParameterTypeConversion { return convertedTypeByCandidate } - private fun needCompatibilityResolveForSAM(candidate: KotlinResolutionCandidate, typeToConvert: UnwrappedType): Boolean { + private fun needCompatibilityResolveForSAM(candidate: ResolutionCandidate, typeToConvert: UnwrappedType): Boolean { // fun interfaces is a new feature with a new modifier, so no compatibility resolve is needed val descriptor = typeToConvert.constructor.declarationDescriptor if (descriptor is ClassDescriptor && descriptor.isFun) return false @@ -128,7 +129,7 @@ object SamTypeConversions : ParameterTypeConversion { } fun isJavaParameterCanBeConverted( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, expectedParameterType: UnwrappedType ): Boolean { val callComponents = candidate.callComponents diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SuspendConversionUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SuspendConversionUtils.kt index c2c35b279d0..bd1f2f45558 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SuspendConversionUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SuspendConversionUtils.kt @@ -8,13 +8,13 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.builtins.* import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ParameterDescriptor -import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.types.UnwrappedType object SuspendTypeConversions : ParameterTypeConversion { override fun conversionDefinitelyNotNeeded( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, expectedParameterType: UnwrappedType ): Boolean { @@ -35,7 +35,7 @@ object SuspendTypeConversions : ParameterTypeConversion { argument is SimpleKotlinCallArgument && argument.receiver.stableType.isFunctionTypeOrSubtype override fun convertParameterType( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, parameter: ParameterDescriptor, expectedParameterType: UnwrappedType diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt index 0becae26121..ef32e1343b4 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.builtins.* import org.jetbrains.kotlin.descriptors.ParameterDescriptor +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate @@ -20,7 +21,7 @@ import org.jetbrains.kotlin.types.typeUtil.isUnit object UnitTypeConversions : ParameterTypeConversion { override fun conversionDefinitelyNotNeeded( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, expectedParameterType: UnwrappedType ): Boolean { @@ -67,7 +68,7 @@ object UnitTypeConversions : ParameterTypeConversion { } override fun convertParameterType( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, parameter: ParameterDescriptor, expectedParameterType: UnwrappedType diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/CallableReferenceResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/CallableReferenceResolutionCandidate.kt new file mode 100644 index 00000000000..22507d1e220 --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/CallableReferenceResolutionCandidate.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2021 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.candidate + +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.resolve.calls.components.CallableReceiver +import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation +import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks +import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor +import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.resolve.calls.model.* +import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind +import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower +import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.UnwrappedType + +/** + * Suppose we have class A with staticM, memberM, memberExtM. + * For A::staticM both receivers will be null + * For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null + * For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver + * + * For class B with companion object B::companionM dispatchReceiver = BoundValueReference + */ +class CallableReferenceResolutionCandidate( + val candidate: CallableDescriptor, + val dispatchReceiver: CallableReceiver?, + val extensionReceiver: CallableReceiver?, + val explicitReceiverKind: ExplicitReceiverKind, + val reflectionCandidateType: UnwrappedType, + val callableReferenceAdaptation: CallableReferenceAdaptation?, + val kotlinCall: CallableReferenceResolutionAtom, + override val callComponents: KotlinCallComponents, + override val scopeTower: ImplicitScopeTower, + override val resolutionCallbacks: KotlinResolutionCallbacks, + val expectedType: UnwrappedType?, + override val baseSystem: ConstraintStorage? +) : ResolutionCandidate() { + override val variableCandidateIfInvoke: ResolutionCandidate? = null + override val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null // callable reference's rhs doesn't have type parameters + + override val resolvedCall = ResolvedCallableReferenceCallAtom( + kotlinCall.call, candidate, explicitReceiverKind, + if (dispatchReceiver != null) ReceiverExpressionKotlinCallArgument(dispatchReceiver.receiver) else null, + if (extensionReceiver != null) ReceiverExpressionKotlinCallArgument(extensionReceiver.receiver) else null, + reflectionCandidateType, + candidate = this + ) + + override fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) {} // there aren't nested resolved primitives for callable references + override fun getSubResolvedAtoms(): List = emptyList() + + var freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor? = null + internal set + + val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0 +} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt similarity index 53% rename from compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolutionCandidate.kt rename to compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt index 535af22cce8..6e1bfda38ac 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolutionCandidate.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt @@ -3,60 +3,62 @@ * 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.model +package org.jetbrains.kotlin.resolve.calls.components.candidate +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl -import org.jetbrains.kotlin.resolve.calls.tower.Candidate -import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability -import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower +import org.jetbrains.kotlin.resolve.calls.model.* +import org.jetbrains.kotlin.resolve.calls.tower.* import org.jetbrains.kotlin.types.TypeSubstitutor +import java.util.ArrayList -/** - * baseSystem contains all information from arguments, i.e. it is union of all system of arguments - * Also by convention we suppose that baseSystem has no contradiction - */ -class KotlinResolutionCandidate( - val callComponents: KotlinCallComponents, - val resolutionCallbacks: KotlinResolutionCallbacks, - val callableReferenceResolver: CallableReferenceResolver, - val scopeTower: ImplicitScopeTower, - private val baseSystem: ConstraintStorage, - val resolvedCall: MutableResolvedCallAtom, - val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null, - private val resolutionSequence: List = resolvedCall.atom.callKind.resolutionSequence -) : Candidate, KotlinDiagnosticsHolder { - val diagnosticsFromResolutionParts = arrayListOf() // TODO: this is mutable list, take diagnostics only once! +sealed class ResolutionCandidate : Candidate, KotlinDiagnosticsHolder { + abstract val resolvedCall: MutableResolvedCallAtom + abstract val callComponents: KotlinCallComponents + abstract fun getSubResolvedAtoms(): List + abstract fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) + abstract val variableCandidateIfInvoke: ResolutionCandidate? + abstract val scopeTower: ImplicitScopeTower + abstract val knownTypeParametersResultingSubstitutor: TypeSubstitutor? + abstract val resolutionCallbacks: KotlinResolutionCallbacks + protected abstract val baseSystem: ConstraintStorage? + + override fun addDiagnostic(diagnostic: KotlinCallDiagnostic) { + mutableDiagnostics.add(diagnostic) + currentApplicability = minOf(diagnostic.candidateApplicability, currentApplicability) + } + + private val variableApplicability + get() = variableCandidateIfInvoke?.resultingApplicability ?: CandidateApplicability.RESOLVED + + val descriptor: CallableDescriptor get() = resolvedCall.candidateDescriptor + + protected val mutableDiagnostics: ArrayList = arrayListOf() + + open val resolutionSequence: List get() = resolvedCall.atom.callKind.resolutionSequence private var newSystem: NewConstraintSystemImpl? = null - private var currentApplicability = CandidateApplicability.RESOLVED - private var subResolvedAtoms: MutableList = arrayListOf() - private val stepCount = resolutionSequence.sumOf { it.run { workCount() } } - private var step = 0 + val diagnostics: List = mutableDiagnostics fun getSystem(): NewConstraintSystem { if (newSystem == null) { - newSystem = - NewConstraintSystemImpl(callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner) - newSystem!!.addOtherSystem(baseSystem) + newSystem = NewConstraintSystemImpl( + callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner + ) + if (baseSystem != null) { + newSystem!!.addOtherSystem(baseSystem!!) + } } return newSystem!! } - internal val csBuilder get() = getSystem().getBuilder() - - override fun addDiagnostic(diagnostic: KotlinCallDiagnostic) { - diagnosticsFromResolutionParts.add(diagnostic) - currentApplicability = minOf(diagnostic.candidateApplicability, currentApplicability) - } - - fun getSubResolvedAtoms(): List = subResolvedAtoms - - fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) { - subResolvedAtoms.add(resolvedAtom) - } + private val stepCount get() = resolutionSequence.sumOf { it.run { workCount() } } + private var step = 0 private fun processParts(stopOnFirstError: Boolean) { if (stopOnFirstError && step > 0) return // error already happened @@ -83,7 +85,7 @@ class KotlinResolutionCandidate( partIndex++ } if (step == stepCount) { - resolvedCall.setAnalyzedResults(subResolvedAtoms) + resolvedCall.setAnalyzedResults(getSubResolvedAtoms()) } } @@ -98,35 +100,32 @@ class KotlinResolutionCandidate( return false } - val variableCandidateIfInvoke: KotlinResolutionCandidate? - get() = callComponents.statelessCallbacks.getVariableCandidateIfInvoke(resolvedCall.atom) - - private val variableApplicability - get() = variableCandidateIfInvoke?.resultingApplicability ?: CandidateApplicability.RESOLVED + protected var currentApplicability: CandidateApplicability = CandidateApplicability.RESOLVED override val isSuccessful: Boolean get() { processParts(stopOnFirstError = true) - return currentApplicability.isSuccess && variableApplicability.isSuccess && !getSystem().hasContradiction + return resultingApplicabilities.minOrNull()!!.isSuccess && !getSystem().hasContradiction } + val resultingApplicabilities: Array + get() = arrayOf(currentApplicability, getResultApplicability(getSystem().errors), variableApplicability) + override val resultingApplicability: CandidateApplicability get() { processParts(stopOnFirstError = false) - - val systemApplicability = getResultApplicability(getSystem().errors) - return minOf(currentApplicability, systemApplicability, variableApplicability) + return resultingApplicabilities.minOrNull()!! } override fun addCompatibilityWarning(other: Candidate) { - if (this !== other && other is KotlinResolutionCandidate) { - addDiagnostic(CompatibilityWarning(other.resolvedCall.candidateDescriptor)) + if (other is ResolutionCandidate && this !== other && this::class == other::class) { + addDiagnostic(CompatibilityWarning(other.descriptor)) } } override fun toString(): String { val descriptor = DescriptorRenderer.COMPACT.render(resolvedCall.candidateDescriptor) - val okOrFail = if (currentApplicability.isSuccess) "OK" else "FAIL" + val okOrFail = if (resultingApplicabilities.minOrNull()!!.isSuccess) "OK" else "FAIL" val step = "$step/$stepCount" return "$okOrFail($step): $descriptor" } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleErrorResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleErrorResolutionCandidate.kt new file mode 100644 index 00000000000..fd70b8179ab --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleErrorResolutionCandidate.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 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.candidate + +import org.jetbrains.kotlin.resolve.calls.components.ErrorDescriptorResolutionPart +import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks +import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents +import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCallAtom +import org.jetbrains.kotlin.resolve.calls.model.ResolutionPart +import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower + +class SimpleErrorResolutionCandidate( + callComponents: KotlinCallComponents, + resolutionCallbacks: KotlinResolutionCallbacks, + scopeTower: ImplicitScopeTower, + baseSystem: ConstraintStorage, + resolvedCall: MutableResolvedCallAtom +) : SimpleResolutionCandidate(callComponents, resolutionCallbacks, scopeTower, baseSystem, resolvedCall) { + override val resolutionSequence: List = listOf(ErrorDescriptorResolutionPart) +} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleResolutionCandidate.kt new file mode 100644 index 00000000000..63d027d5263 --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/SimpleResolutionCandidate.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2021 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.candidate + +import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks +import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage +import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents +import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCallAtom +import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom +import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower +import org.jetbrains.kotlin.types.TypeSubstitutor + +/** + * baseSystem contains all information from arguments, i.e. it is union of all system of arguments + * Also by convention we suppose that baseSystem has no contradiction + */ +open class SimpleResolutionCandidate( + override val callComponents: KotlinCallComponents, + override val resolutionCallbacks: KotlinResolutionCallbacks, + override val scopeTower: ImplicitScopeTower, + override val baseSystem: ConstraintStorage, + override val resolvedCall: MutableResolvedCallAtom, + override val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null, +) : ResolutionCandidate() { + private var subResolvedAtoms: MutableList = arrayListOf() + + override val variableCandidateIfInvoke: ResolutionCandidate? + get() = callComponents.statelessCallbacks.getVariableCandidateIfInvoke(resolvedCall.atom) + + override fun getSubResolvedAtoms(): List = subResolvedAtoms + + override fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) { + subResolvedAtoms.add(resolvedAtom) + } +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt index 0927cdba063..119caeaa353 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt @@ -6,13 +6,14 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.descriptors.ParameterDescriptor +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate import org.jetbrains.kotlin.types.UnwrappedType interface ParameterTypeConversion { fun conversionDefinitelyNotNeeded( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, expectedParameterType: UnwrappedType ): Boolean @@ -21,7 +22,7 @@ interface ParameterTypeConversion { fun conversionIsNeededAfterSubtypingCheck(argument: KotlinCallArgument): Boolean fun convertParameterType( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, parameter: ParameterDescriptor, expectedParameterType: UnwrappedType @@ -30,7 +31,7 @@ interface ParameterTypeConversion { object TypeConversions { fun performCompositeConversionBeforeSubtyping( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, candidateParameter: ParameterDescriptor, candidateExpectedType: UnwrappedType, @@ -61,7 +62,7 @@ object TypeConversions { } fun performCompositeConversionAfterSubtyping( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, candidateParameter: ParameterDescriptor, candidateExpectedType: UnwrappedType, @@ -86,7 +87,7 @@ object TypeConversions { } private fun performConversionAfterSubtyping( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, candidateParameter: ParameterDescriptor, candidateExpectedType: UnwrappedType, @@ -103,7 +104,7 @@ object TypeConversions { } private fun performConversionBeforeSubtyping( - candidate: KotlinResolutionCandidate, + candidate: ResolutionCandidate, argument: KotlinCallArgument, candidateParameter: ParameterDescriptor, candidateExpectedType: UnwrappedType, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt index b4ffa9a2c96..56ccb30825a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt @@ -282,7 +282,7 @@ class KotlinConstraintSystemCompleter( fun prepareLambdaAtomForFactoryPattern( atom: ResolvedLambdaAtom, - candidate: KotlinResolutionCandidate, + candidate: SimpleResolutionCandidate, diagnosticsHolder: KotlinDiagnosticsHolder, ): ResolvedLambdaAtom { val returnVariable = TypeVariableForLambdaReturnType(candidate.callComponents.builtIns, "_R") diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferencesCandidateFactory.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt similarity index 98% rename from compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferencesCandidateFactory.kt rename to compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt index 33716380c03..fac5202f581 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferencesCandidateFactory.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/CallableReferencesCandidateFactory.kt @@ -38,7 +38,7 @@ class CallableReferencesCandidateFactory( val expectedType: UnwrappedType?, private val csBuilder: ConstraintSystemOperation, private val resolutionCallbacks: KotlinResolutionCallbacks -) : CandidateFactory { +) : CandidateFactory { fun createCallableProcessor(explicitReceiver: DetailedReceiver?) = createCallableReferenceProcessor(scopeTower, argument.rhsName, this, explicitReceiver) @@ -47,7 +47,7 @@ class CallableReferencesCandidateFactory( towerCandidate: CandidateWithBoundDispatchReceiver, explicitReceiverKind: ExplicitReceiverKind, extensionReceiver: ReceiverValueWithSmartCastInfo? - ): CallableReferenceCandidate { + ): CallableReferenceResolutionCandidate { val dispatchCallableReceiver = towerCandidate.dispatchReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER) } @@ -63,8 +63,8 @@ class CallableReferencesCandidateFactory( callComponents.builtIns ) - fun createReferenceCandidate(): CallableReferenceCandidate = - CallableReferenceCandidate( + fun createReferenceCandidate(): CallableReferenceResolutionCandidate = + CallableReferenceResolutionCandidate( candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver, explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation, diagnostics ) @@ -92,7 +92,7 @@ class CallableReferencesCandidateFactory( } if (candidateDescriptor !is CallableMemberDescriptor) { - return CallableReferenceCandidate( + return CallableReferenceResolutionCandidate( candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver, explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation, listOf(NotCallableMemberReference(argument, candidateDescriptor)) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt index 7afe3603911..e6b636af553 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt @@ -19,7 +19,8 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintWarning import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability @@ -193,16 +194,13 @@ class SuperAsExtensionReceiver(val receiver: SimpleKotlinCallArgument) : KotlinC } // candidates result -class NoneCandidatesCallDiagnostic(val kotlinCall: KotlinCall) : KotlinCallDiagnostic(INAPPLICABLE) { +class NoneCandidatesCallDiagnostic : KotlinCallDiagnostic(INAPPLICABLE) { override fun report(reporter: DiagnosticReporter) { reporter.onCall(this) } } -class ManyCandidatesCallDiagnostic( - val kotlinCall: KotlinCall, - val candidates: Collection -) : KotlinCallDiagnostic(INAPPLICABLE) { +class ManyCandidatesCallDiagnostic(val candidates: Collection) : KotlinCallDiagnostic(INAPPLICABLE) { override fun report(reporter: DiagnosticReporter) { reporter.onCall(this) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index 9a6e2926484..f7f19c18ed7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -19,24 +19,16 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.config.LanguageVersionSettings -import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.resolve.calls.components.* -import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector -import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage -import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind -import org.jetbrains.kotlin.resolve.calls.tower.* -import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation import org.jetbrains.kotlin.resolve.sam.SamConversionOracle import org.jetbrains.kotlin.resolve.sam.SamConversionResolver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo -import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker -import org.jetbrains.kotlin.types.isDynamic class KotlinCallComponents( @@ -52,6 +44,7 @@ class KotlinCallComponents( val kotlinTypeChecker: NewKotlinTypeChecker, val lookupTracker: LookupTracker, val kotlinTypeRefiner: KotlinTypeRefiner, + val callableReferenceArgumentResolver: CallableReferenceArgumentResolver ) class SimpleCandidateFactory( @@ -60,7 +53,7 @@ class SimpleCandidateFactory( val kotlinCall: KotlinCall, val resolutionCallbacks: KotlinResolutionCallbacks, val callableReferenceResolver: CallableReferenceResolver -) : CandidateFactory { +) : CandidateFactory { val inferenceSession: InferenceSession = resolutionCallbacks.inferenceSession val baseSystem: ConstraintStorage @@ -102,7 +95,7 @@ class SimpleCandidateFactory( else -> null } - fun createCandidate(givenCandidate: GivenCandidate): KotlinResolutionCandidate { + fun createCandidate(givenCandidate: GivenCandidate): SimpleResolutionCandidate { val isSafeCall = (kotlinCall.explicitReceiver as? SimpleKotlinCallArgument)?.isSafeCall ?: false val explicitReceiverKind = @@ -120,7 +113,7 @@ class SimpleCandidateFactory( towerCandidate: CandidateWithBoundDispatchReceiver, explicitReceiverKind: ExplicitReceiverKind, extensionReceiver: ReceiverValueWithSmartCastInfo? - ): KotlinResolutionCandidate { + ): SimpleResolutionCandidate { val dispatchArgumentReceiver = createReceiverArgument( kotlinCall.getExplicitDispatchReceiver(explicitReceiverKind), towerCandidate.dispatchReceiver @@ -141,14 +134,14 @@ class SimpleCandidateFactory( extensionArgumentReceiver: SimpleKotlinCallArgument?, initialDiagnostics: Collection, knownSubstitutor: TypeSubstitutor? - ): KotlinResolutionCandidate { + ): SimpleResolutionCandidate { val resolvedKtCall = MutableResolvedCallAtom( kotlinCall, descriptor, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver ) if (ErrorUtils.isError(descriptor)) { - return KotlinResolutionCandidate( + return SimpleResolutionCandidate( callComponents, resolutionCallbacks, callableReferenceResolver, @@ -160,7 +153,7 @@ class SimpleCandidateFactory( ) } - val candidate = KotlinResolutionCandidate( + val candidate = SimpleResolutionCandidate( callComponents, resolutionCallbacks, callableReferenceResolver, scopeTower, baseSystem, resolvedKtCall, knownSubstitutor ) @@ -183,7 +176,7 @@ class SimpleCandidateFactory( return candidate } - fun createErrorCandidate(): KotlinResolutionCandidate { + fun createErrorCandidate(): SimpleResolutionCandidate { val errorScope = ErrorUtils.createErrorScope("Error resolution candidate for call $kotlinCall") val errorDescriptor = if (kotlinCall.callKind == KotlinCallKind.VARIABLE) { errorScope.getContributedVariables(kotlinCall.name, scopeTower.location) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt index 71479bdc080..ce7cecf21d2 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.components.ReturnArgumentsInfo import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper import org.jetbrains.kotlin.resolve.calls.components.extractInputOutputTypesFromCallableReferenceExpectedType @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewT import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeConstructor @@ -167,13 +168,13 @@ abstract class ResolvedCallableReferenceAtom( override val atom: CallableReferenceKotlinCallArgument, override val expectedType: UnwrappedType? ) : PostponedResolvedAtom() { - var candidate: CallableReferenceCandidate? = null + var candidate: CallableReferenceResolutionCandidate? = null private set var completed: Boolean = false fun setAnalyzedResults( - candidate: CallableReferenceCandidate?, + candidate: CallableReferenceResolutionCandidate?, subResolvedAtoms: List ) { this.candidate = candidate @@ -292,7 +293,7 @@ class AllCandidatesResolutionResult( val allCandidates: Collection ) : CallResolutionResult(null, emptyList(), ConstraintStorage.Empty) -data class CandidateWithDiagnostics(val candidate: KotlinResolutionCandidate, val diagnostics: List) +data class CandidateWithDiagnostics(val candidate: ResolutionCandidate, val diagnostics: List) fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? = if (this is SingleCallResolutionResult) resultCallAtom else null diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt index 7768771a478..d53a21fb87c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt @@ -21,7 +21,8 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.calls.components.* -import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem +import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate +import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage @@ -37,13 +38,13 @@ import org.jetbrains.kotlin.utils.SmartList abstract class ResolutionPart { - abstract fun KotlinResolutionCandidate.process(workIndex: Int) + abstract fun ResolutionCandidate.process(workIndex: Int) - open fun KotlinResolutionCandidate.workCount(): Int = 1 + open fun ResolutionCandidate.workCount(): Int = 1 // helper functions - protected inline val KotlinResolutionCandidate.candidateDescriptor get() = resolvedCall.candidateDescriptor - protected inline val KotlinResolutionCandidate.kotlinCall get() = resolvedCall.atom + protected inline val ResolutionCandidate.candidateDescriptor get() = resolvedCall.candidateDescriptor + protected inline val ResolutionCandidate.kotlinCall get() = resolvedCall.atom } interface KotlinDiagnosticsHolder { @@ -139,7 +140,7 @@ class MutableResolvedCallAtom( override fun toString(): String = "$atom, candidate = $candidateDescriptor" } -fun KotlinResolutionCandidate.markCandidateForCompatibilityResolve() { +fun ResolutionCandidate.markCandidateForCompatibilityResolve() { if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return addDiagnostic(LowerPriorityToPreserveCompatibility.asDiagnostic()) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt index bd181ee63df..6dfc48d0e17 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerResolver.kt @@ -46,6 +46,8 @@ interface CandidateFactory { explicitReceiverKind: ExplicitReceiverKind, extensionReceiver: ReceiverValueWithSmartCastInfo? ): C + + fun createErrorCandidate(): C } interface CandidateFactoryProviderForInvoke {