[NI] Refactoring: KotlinCallContext to stateless component (2)
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.tower
|
package org.jetbrains.kotlin.resolve.calls.tower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
@@ -39,11 +38,8 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
@@ -70,13 +66,7 @@ class PSICallResolver(
|
|||||||
private val languageVersionSettings: LanguageVersionSettings,
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
private val dynamicCallableDescriptors: DynamicCallableDescriptors,
|
private val dynamicCallableDescriptors: DynamicCallableDescriptors,
|
||||||
private val syntheticScopes: SyntheticScopes,
|
private val syntheticScopes: SyntheticScopes,
|
||||||
private val argumentsToParametersMapper: ArgumentsToParametersMapper,
|
private val callComponents: KotlinCallComponents,
|
||||||
private val statelessCallbacks: KotlinResolutionStatelessCallbacks,
|
|
||||||
private val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
|
|
||||||
private val resultTypeResolver: ResultTypeResolver,
|
|
||||||
private val callableReferenceResolver: CallableReferenceResolver,
|
|
||||||
private val constraintInjector: ConstraintInjector,
|
|
||||||
private val reflectionTypes: ReflectionTypes,
|
|
||||||
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
|
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
|
||||||
private val kotlinCallResolver: KotlinCallResolver,
|
private val kotlinCallResolver: KotlinCallResolver,
|
||||||
private val typeApproximator: TypeApproximator,
|
private val typeApproximator: TypeApproximator,
|
||||||
@@ -95,17 +85,16 @@ class PSICallResolver(
|
|||||||
|
|
||||||
val kotlinCall = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, refinedName, tracingStrategy)
|
val kotlinCall = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, refinedName, tracingStrategy)
|
||||||
val scopeTower = ASTScopeTower(context)
|
val scopeTower = ASTScopeTower(context)
|
||||||
val lambdaAnalyzer = createLambdaAnalyzer(context)
|
val resolutionCallbacks = createResolutionCallbacks(context)
|
||||||
|
|
||||||
val callContext = createCallContext(scopeTower, lambdaAnalyzer)
|
val factoryProviderForInvoke = FactoryProviderForInvoke(context, scopeTower, kotlinCall)
|
||||||
val factoryProviderForInvoke = FactoryProviderForInvoke(context, callContext, scopeTower, kotlinCall)
|
|
||||||
|
|
||||||
val expectedType = calculateExpectedType(context)
|
val expectedType = calculateExpectedType(context)
|
||||||
var result = kotlinCallResolver.resolveCall(callContext, kotlinCall, expectedType, factoryProviderForInvoke)
|
var result = kotlinCallResolver.resolveCall(scopeTower, resolutionCallbacks, kotlinCall, expectedType, factoryProviderForInvoke)
|
||||||
|
|
||||||
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
||||||
if (isBinaryRemOperator && shouldUseOperatorRem && (result.isEmpty() || result.areAllCompletedAndInapplicable())) {
|
if (isBinaryRemOperator && shouldUseOperatorRem && (result.isEmpty() || result.areAllCompletedAndInapplicable())) {
|
||||||
result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, callContext, scopeTower, expectedType)
|
result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, scopeTower, resolutionCallbacks, expectedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind.kotlinCallKind, kotlinCall)) {
|
if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind.kotlinCallKind, kotlinCall)) {
|
||||||
@@ -125,8 +114,7 @@ class PSICallResolver(
|
|||||||
|
|
||||||
val kotlinCall = toKotlinCall(context, KotlinCallKind.FUNCTION, context.call, GIVEN_CANDIDATES_NAME, tracingStrategy, dispatchReceiver)
|
val kotlinCall = toKotlinCall(context, KotlinCallKind.FUNCTION, context.call, GIVEN_CANDIDATES_NAME, tracingStrategy, dispatchReceiver)
|
||||||
val scopeTower = ASTScopeTower(context)
|
val scopeTower = ASTScopeTower(context)
|
||||||
val lambdaAnalyzer = createLambdaAnalyzer(context)
|
val resolutionCallbacks = createResolutionCallbacks(context)
|
||||||
val callContext = createCallContext(scopeTower, lambdaAnalyzer)
|
|
||||||
|
|
||||||
val givenCandidates = resolutionCandidates.map {
|
val givenCandidates = resolutionCandidates.map {
|
||||||
GivenCandidate(scopeTower, it.descriptor as FunctionDescriptor,
|
GivenCandidate(scopeTower, it.descriptor as FunctionDescriptor,
|
||||||
@@ -134,7 +122,7 @@ class PSICallResolver(
|
|||||||
it.knownTypeParametersResultingSubstitutor)
|
it.knownTypeParametersResultingSubstitutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = kotlinCallResolver.resolveGivenCandidates(callContext, kotlinCall, calculateExpectedType(context), givenCandidates)
|
val result = kotlinCallResolver.resolveGivenCandidates(resolutionCallbacks, kotlinCall, calculateExpectedType(context), givenCandidates)
|
||||||
return convertToOverloadResolutionResults(context, result, tracingStrategy)
|
return convertToOverloadResolutionResults(context, result, tracingStrategy)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -144,14 +132,14 @@ class PSICallResolver(
|
|||||||
context: BasicCallResolutionContext,
|
context: BasicCallResolutionContext,
|
||||||
resolutionKind: NewResolutionOldInference.ResolutionKind<D>,
|
resolutionKind: NewResolutionOldInference.ResolutionKind<D>,
|
||||||
tracingStrategy: TracingStrategy,
|
tracingStrategy: TracingStrategy,
|
||||||
callContext: KotlinCallContext,
|
|
||||||
scopeTower: ImplicitScopeTower,
|
scopeTower: ImplicitScopeTower,
|
||||||
|
resolutionCallbacks: KotlinResolutionCallbacksImpl,
|
||||||
expectedType: UnwrappedType?
|
expectedType: UnwrappedType?
|
||||||
): Collection<ResolvedKotlinCall> {
|
): Collection<ResolvedKotlinCall> {
|
||||||
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!!
|
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!!
|
||||||
val callWithDeprecatedName = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, deprecatedName, tracingStrategy)
|
val callWithDeprecatedName = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, deprecatedName, tracingStrategy)
|
||||||
val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, callContext, scopeTower, callWithDeprecatedName)
|
val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, scopeTower, callWithDeprecatedName)
|
||||||
return kotlinCallResolver.resolveCall(callContext, callWithDeprecatedName, expectedType, refinedProviderForInvokeFactory)
|
return kotlinCallResolver.resolveCall(scopeTower, resolutionCallbacks, callWithDeprecatedName, expectedType, refinedProviderForInvokeFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refineNameForRemOperator(isBinaryRemOperator: Boolean, name: Name): Name {
|
private fun refineNameForRemOperator(isBinaryRemOperator: Boolean, name: Name): Name {
|
||||||
@@ -159,7 +147,7 @@ class PSICallResolver(
|
|||||||
return if (isBinaryRemOperator && !shouldUseOperatorRem) OperatorConventions.REM_TO_MOD_OPERATION_NAMES[name]!! else name
|
return if (isBinaryRemOperator && !shouldUseOperatorRem) OperatorConventions.REM_TO_MOD_OPERATION_NAMES[name]!! else name
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createLambdaAnalyzer(context: BasicCallResolutionContext) =
|
private fun createResolutionCallbacks(context: BasicCallResolutionContext) =
|
||||||
KotlinResolutionCallbacksImpl(context, expressionTypingServices, typeApproximator, kotlinToResolvedCallTransformer,
|
KotlinResolutionCallbacksImpl(context, expressionTypingServices, typeApproximator, kotlinToResolvedCallTransformer,
|
||||||
argumentTypeResolver, doubleColonExpressionResolver, languageVersionSettings)
|
argumentTypeResolver, doubleColonExpressionResolver, languageVersionSettings)
|
||||||
|
|
||||||
@@ -177,11 +165,6 @@ class PSICallResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCallContext(scopeTower: ASTScopeTower, resolutionCallbacks: KotlinResolutionCallbacks) =
|
|
||||||
KotlinCallContext(scopeTower, resolutionCallbacks, statelessCallbacks, argumentsToParametersMapper,
|
|
||||||
typeArgumentsToParametersMapper, resultTypeResolver,
|
|
||||||
callableReferenceResolver, constraintInjector, reflectionTypes)
|
|
||||||
|
|
||||||
private fun <D : CallableDescriptor> convertToOverloadResolutionResults(
|
private fun <D : CallableDescriptor> convertToOverloadResolutionResults(
|
||||||
context: BasicCallResolutionContext,
|
context: BasicCallResolutionContext,
|
||||||
result: Collection<ResolvedKotlinCall>,
|
result: Collection<ResolvedKotlinCall>,
|
||||||
@@ -291,7 +274,6 @@ class PSICallResolver(
|
|||||||
|
|
||||||
private inner class FactoryProviderForInvoke(
|
private inner class FactoryProviderForInvoke(
|
||||||
val context: BasicCallResolutionContext,
|
val context: BasicCallResolutionContext,
|
||||||
val callContext: KotlinCallContext,
|
|
||||||
val scopeTower: ImplicitScopeTower,
|
val scopeTower: ImplicitScopeTower,
|
||||||
val kotlinCall: PSIKotlinCallImpl
|
val kotlinCall: PSIKotlinCallImpl
|
||||||
) : CandidateFactoryProviderForInvoke<KotlinResolutionCandidate> {
|
) : CandidateFactoryProviderForInvoke<KotlinResolutionCandidate> {
|
||||||
@@ -317,7 +299,7 @@ class PSICallResolver(
|
|||||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<SimpleKotlinResolutionCandidate> {
|
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<SimpleKotlinResolutionCandidate> {
|
||||||
val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver
|
val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver
|
||||||
val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name)
|
val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name)
|
||||||
return SimpleCandidateFactory(callContext, scopeTower, variableCall)
|
return SimpleCandidateFactory(callComponents, scopeTower, variableCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean):
|
override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean):
|
||||||
@@ -341,7 +323,7 @@ class PSICallResolver(
|
|||||||
PSIKotlinCallForInvoke(kotlinCall, variableCallArgument, null)
|
PSIKotlinCallForInvoke(kotlinCall, variableCallArgument, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
return variableCallArgument.receiver to SimpleCandidateFactory(callContext, scopeTower, callForInvoke)
|
return variableCallArgument.receiver to SimpleCandidateFactory(callComponents, scopeTower, callForInvoke)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: create special check that there is no invoke on variable
|
// todo: create special check that there is no invoke on variable
|
||||||
|
|||||||
@@ -30,20 +30,20 @@ import java.lang.UnsupportedOperationException
|
|||||||
class KotlinCallResolver(
|
class KotlinCallResolver(
|
||||||
private val towerResolver: TowerResolver,
|
private val towerResolver: TowerResolver,
|
||||||
private val kotlinCallCompleter: KotlinCallCompleter,
|
private val kotlinCallCompleter: KotlinCallCompleter,
|
||||||
private val overloadingConflictResolver: NewOverloadingConflictResolver
|
private val overloadingConflictResolver: NewOverloadingConflictResolver,
|
||||||
|
private val callComponents: KotlinCallComponents
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun resolveCall(
|
fun resolveCall(
|
||||||
callContext: KotlinCallContext,
|
scopeTower: ImplicitScopeTower,
|
||||||
|
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||||
kotlinCall: KotlinCall,
|
kotlinCall: KotlinCall,
|
||||||
expectedType: UnwrappedType?,
|
expectedType: UnwrappedType?,
|
||||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<KotlinResolutionCandidate>
|
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<KotlinResolutionCandidate>
|
||||||
): Collection<ResolvedKotlinCall> {
|
): Collection<ResolvedKotlinCall> {
|
||||||
val scopeTower = callContext.scopeTower
|
|
||||||
|
|
||||||
kotlinCall.checkCallInvariants()
|
kotlinCall.checkCallInvariants()
|
||||||
|
|
||||||
val candidateFactory = SimpleCandidateFactory(callContext, scopeTower, kotlinCall)
|
val candidateFactory = SimpleCandidateFactory(callComponents, scopeTower, kotlinCall)
|
||||||
val processor = when(kotlinCall.callKind) {
|
val processor = when(kotlinCall.callKind) {
|
||||||
KotlinCallKind.VARIABLE -> {
|
KotlinCallKind.VARIABLE -> {
|
||||||
createVariableAndObjectProcessor(scopeTower, kotlinCall.name, candidateFactory, kotlinCall.explicitReceiver?.receiver)
|
createVariableAndObjectProcessor(scopeTower, kotlinCall.name, candidateFactory, kotlinCall.explicitReceiver?.receiver)
|
||||||
@@ -56,11 +56,11 @@ class KotlinCallResolver(
|
|||||||
|
|
||||||
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = kotlinCall.callKind != KotlinCallKind.UNSUPPORTED)
|
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = kotlinCall.callKind != KotlinCallKind.UNSUPPORTED)
|
||||||
|
|
||||||
return choseMostSpecific(callContext.resolutionCallbacks, expectedType, candidates)
|
return choseMostSpecific(resolutionCallbacks, expectedType, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveGivenCandidates(
|
fun resolveGivenCandidates(
|
||||||
callContext: KotlinCallContext,
|
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||||
kotlinCall: KotlinCall,
|
kotlinCall: KotlinCall,
|
||||||
expectedType: UnwrappedType?,
|
expectedType: UnwrappedType?,
|
||||||
givenCandidates: Collection<GivenCandidate>
|
givenCandidates: Collection<GivenCandidate>
|
||||||
@@ -70,7 +70,7 @@ class KotlinCallResolver(
|
|||||||
val isSafeCall = (kotlinCall.explicitReceiver as? SimpleKotlinCallArgument)?.isSafeCall ?: false
|
val isSafeCall = (kotlinCall.explicitReceiver as? SimpleKotlinCallArgument)?.isSafeCall ?: false
|
||||||
|
|
||||||
val resolutionCandidates = givenCandidates.map {
|
val resolutionCandidates = givenCandidates.map {
|
||||||
SimpleKotlinResolutionCandidate(callContext,
|
SimpleKotlinResolutionCandidate(callComponents,
|
||||||
it.scopeTower,
|
it.scopeTower,
|
||||||
kotlinCall,
|
kotlinCall,
|
||||||
if (it.dispatchReceiver == null) ExplicitReceiverKind.NO_EXPLICIT_RECEIVER else ExplicitReceiverKind.DISPATCH_RECEIVER,
|
if (it.dispatchReceiver == null) ExplicitReceiverKind.NO_EXPLICIT_RECEIVER else ExplicitReceiverKind.DISPATCH_RECEIVER,
|
||||||
@@ -84,7 +84,7 @@ class KotlinCallResolver(
|
|||||||
val candidates = towerResolver.runWithEmptyTowerData(KnownResultProcessor(resolutionCandidates),
|
val candidates = towerResolver.runWithEmptyTowerData(KnownResultProcessor(resolutionCandidates),
|
||||||
TowerResolver.SuccessfulResultCollector { it.status },
|
TowerResolver.SuccessfulResultCollector { it.status },
|
||||||
useOrder = true)
|
useOrder = true)
|
||||||
return choseMostSpecific(callContext.resolutionCallbacks, expectedType, candidates)
|
return choseMostSpecific(resolutionCallbacks, expectedType, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun choseMostSpecific(
|
private fun choseMostSpecific(
|
||||||
|
|||||||
+5
-5
@@ -152,7 +152,7 @@ private fun ConstraintSystemOperation.addReceiverConstraint(
|
|||||||
|
|
||||||
class CallableReferencesCandidateFactory(
|
class CallableReferencesCandidateFactory(
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
val argument: CallableReferenceKotlinCallArgument,
|
||||||
val outerCallContext: KotlinCallContext,
|
val callComponents: KotlinCallComponents,
|
||||||
val scopeTower: ImplicitScopeTower,
|
val scopeTower: ImplicitScopeTower,
|
||||||
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
|
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
|
||||||
val expectedType: UnwrappedType?
|
val expectedType: UnwrappedType?
|
||||||
@@ -224,7 +224,7 @@ class CallableReferencesCandidateFactory(
|
|||||||
if (expectedArgumentCount < 0) return null
|
if (expectedArgumentCount < 0) return null
|
||||||
|
|
||||||
val fakeArguments = (0..(expectedArgumentCount - 1)).map { FakeKotlinCallArgumentForCallableReference(it) }
|
val fakeArguments = (0..(expectedArgumentCount - 1)).map { FakeKotlinCallArgumentForCallableReference(it) }
|
||||||
val argumentMapping = outerCallContext.argumentsToParametersMapper.mapArguments(fakeArguments, externalArgument = null, descriptor = descriptor)
|
val argumentMapping = callComponents.argumentsToParametersMapper.mapArguments(fakeArguments, externalArgument = null, descriptor = descriptor)
|
||||||
if (argumentMapping.diagnostics.any { !it.candidateApplicability.isSuccess }) return null
|
if (argumentMapping.diagnostics.any { !it.candidateApplicability.isSuccess }) return null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -277,7 +277,7 @@ class CallableReferencesCandidateFactory(
|
|||||||
scopeTower.lexicalScope.ownerDescriptor)
|
scopeTower.lexicalScope.ownerDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
return outerCallContext.reflectionTypes.getKPropertyType(Annotations.EMPTY, argumentsAndReceivers, descriptorReturnType, mutable) to 0
|
return callComponents.reflectionTypes.getKPropertyType(Annotations.EMPTY, argumentsAndReceivers, descriptorReturnType, mutable) to 0
|
||||||
}
|
}
|
||||||
is FunctionDescriptor -> {
|
is FunctionDescriptor -> {
|
||||||
val returnType: KotlinType
|
val returnType: KotlinType
|
||||||
@@ -298,8 +298,8 @@ class CallableReferencesCandidateFactory(
|
|||||||
returnType = if (coercion == CoercionStrategy.COERCION_TO_UNIT) descriptor.builtIns.unitType else descriptorReturnType
|
returnType = if (coercion == CoercionStrategy.COERCION_TO_UNIT) descriptor.builtIns.unitType else descriptorReturnType
|
||||||
}
|
}
|
||||||
|
|
||||||
return outerCallContext.reflectionTypes.getKFunctionType(Annotations.EMPTY, null, argumentsAndReceivers, null,
|
return callComponents.reflectionTypes.getKFunctionType(Annotations.EMPTY, null, argumentsAndReceivers, null,
|
||||||
returnType, descriptor.builtIns) to defaults
|
returnType, descriptor.builtIns) to defaults
|
||||||
}
|
}
|
||||||
else -> error("Unsupported descriptor type: $descriptor")
|
else -> error("Unsupported descriptor type: $descriptor")
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-38
@@ -53,53 +53,53 @@ class CallableReferenceOverloadConflictResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processCallableReferenceArgument(
|
|
||||||
callContext: KotlinCallContext,
|
|
||||||
scopeTower: ImplicitScopeTower,
|
|
||||||
csBuilder: ConstraintSystemBuilder,
|
|
||||||
postponedArgument: PostponedCallableReferenceArgument
|
|
||||||
): KotlinCallDiagnostic? {
|
|
||||||
val argument = postponedArgument.argument
|
|
||||||
val expectedType = postponedArgument.expectedType
|
|
||||||
|
|
||||||
val subLHSCall = ((argument.lhsResult as? LHSResult.Expression)?.lshCallArgument as? SubKotlinCallArgument)
|
|
||||||
if (subLHSCall != null) {
|
|
||||||
csBuilder.addInnerCall(subLHSCall.resolvedCall)
|
|
||||||
}
|
|
||||||
val candidates = callContext.callableReferenceResolver.runRLSResolution(callContext, scopeTower, argument, expectedType) { checkCallableReference ->
|
|
||||||
csBuilder.runTransaction { checkCallableReference(this); false }
|
|
||||||
}
|
|
||||||
val chosenCandidate = when (candidates.size) {
|
|
||||||
0 -> return NoneCallableReferenceCandidates(argument)
|
|
||||||
1 -> candidates.single()
|
|
||||||
else -> return CallableReferenceCandidatesAmbiguity(argument, candidates)
|
|
||||||
}
|
|
||||||
val (toFreshSubstitutor, diagnostic) = with(chosenCandidate) {
|
|
||||||
csBuilder.checkCallableReference(argument, dispatchReceiver, extensionReceiver, candidate,
|
|
||||||
reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
postponedArgument.analyzedAndThereIsResult = true
|
|
||||||
postponedArgument.myTypeVariables = toFreshSubstitutor.freshVariables
|
|
||||||
postponedArgument.callableResolutionCandidate = chosenCandidate
|
|
||||||
|
|
||||||
return diagnostic
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CallableReferenceResolver(
|
class CallableReferenceResolver(
|
||||||
val towerResolver: TowerResolver,
|
private val towerResolver: TowerResolver,
|
||||||
val callableReferenceOverloadConflictResolver: CallableReferenceOverloadConflictResolver
|
private val callableReferenceOverloadConflictResolver: CallableReferenceOverloadConflictResolver,
|
||||||
|
private val callComponents: KotlinCallComponents
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun runRLSResolution(
|
fun processCallableReferenceArgument(
|
||||||
outerCallContext: KotlinCallContext,
|
scopeTower: ImplicitScopeTower,
|
||||||
|
csBuilder: ConstraintSystemBuilder,
|
||||||
|
postponedArgument: PostponedCallableReferenceArgument
|
||||||
|
): KotlinCallDiagnostic? {
|
||||||
|
val argument = postponedArgument.argument
|
||||||
|
val expectedType = postponedArgument.expectedType
|
||||||
|
|
||||||
|
val subLHSCall = ((argument.lhsResult as? LHSResult.Expression)?.lshCallArgument as? SubKotlinCallArgument)
|
||||||
|
if (subLHSCall != null) {
|
||||||
|
csBuilder.addInnerCall(subLHSCall.resolvedCall)
|
||||||
|
}
|
||||||
|
val candidates = runRLSResolution(scopeTower, argument, expectedType) { checkCallableReference ->
|
||||||
|
csBuilder.runTransaction { checkCallableReference(this); false }
|
||||||
|
}
|
||||||
|
val chosenCandidate = when (candidates.size) {
|
||||||
|
0 -> return NoneCallableReferenceCandidates(argument)
|
||||||
|
1 -> candidates.single()
|
||||||
|
else -> return CallableReferenceCandidatesAmbiguity(argument, candidates)
|
||||||
|
}
|
||||||
|
val (toFreshSubstitutor, diagnostic) = with(chosenCandidate) {
|
||||||
|
csBuilder.checkCallableReference(argument, dispatchReceiver, extensionReceiver, candidate,
|
||||||
|
reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
postponedArgument.analyzedAndThereIsResult = true
|
||||||
|
postponedArgument.myTypeVariables = toFreshSubstitutor.freshVariables
|
||||||
|
postponedArgument.callableResolutionCandidate = chosenCandidate
|
||||||
|
|
||||||
|
return diagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun runRLSResolution(
|
||||||
scopeTower: ImplicitScopeTower,
|
scopeTower: ImplicitScopeTower,
|
||||||
callableReference: CallableReferenceKotlinCallArgument,
|
callableReference: CallableReferenceKotlinCallArgument,
|
||||||
expectedType: UnwrappedType?, // this type can have not fixed type variable inside
|
expectedType: UnwrappedType?, // this type can have not fixed type variable inside
|
||||||
compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be roll backed
|
compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be roll backed
|
||||||
): Set<CallableReferenceCandidate> {
|
): Set<CallableReferenceCandidate> {
|
||||||
val factory = CallableReferencesCandidateFactory(callableReference, outerCallContext, scopeTower, compatibilityChecker, expectedType)
|
val factory = CallableReferencesCandidateFactory(callableReference, callComponents, scopeTower, compatibilityChecker, expectedType)
|
||||||
val processor = createCallableReferenceProcessor(factory)
|
val processor = createCallableReferenceProcessor(factory)
|
||||||
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true)
|
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true)
|
||||||
return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(candidates, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(candidates, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||||
|
|||||||
+3
-2
@@ -39,7 +39,8 @@ import org.jetbrains.kotlin.types.typeUtil.contains
|
|||||||
class KotlinCallCompleter(
|
class KotlinCallCompleter(
|
||||||
private val fixationOrderCalculator: FixationOrderCalculator,
|
private val fixationOrderCalculator: FixationOrderCalculator,
|
||||||
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter,
|
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter,
|
||||||
private val inferenceStepResolver: InferenceStepResolver
|
private val inferenceStepResolver: InferenceStepResolver,
|
||||||
|
private val callableReferenceResolver: CallableReferenceResolver
|
||||||
) {
|
) {
|
||||||
interface Context {
|
interface Context {
|
||||||
val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall>
|
val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall>
|
||||||
@@ -93,7 +94,7 @@ class KotlinCallCompleter(
|
|||||||
private fun resolveCallableReferenceArguments(c: Context, topLevelCall: SimpleKotlinResolutionCandidate) {
|
private fun resolveCallableReferenceArguments(c: Context, topLevelCall: SimpleKotlinResolutionCandidate) {
|
||||||
for (callableReferenceArgument in c.postponedArguments) {
|
for (callableReferenceArgument in c.postponedArguments) {
|
||||||
if (callableReferenceArgument !is PostponedCallableReferenceArgument) continue
|
if (callableReferenceArgument !is PostponedCallableReferenceArgument) continue
|
||||||
processCallableReferenceArgument(topLevelCall.callContext, topLevelCall.scopeTower, c.getBuilder(), callableReferenceArgument)
|
callableReferenceResolver.processCallableReferenceArgument(topLevelCall.scopeTower, c.getBuilder(), callableReferenceArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
|
|
||||||
internal object CheckInstantiationOfAbstractClass : ResolutionPart {
|
internal object CheckInstantiationOfAbstractClass : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
if (candidateDescriptor is ConstructorDescriptor && !callContext.statelessCallbacks.isSuperOrDelegatingConstructorCall(kotlinCall)) {
|
if (candidateDescriptor is ConstructorDescriptor && !callComponents.statelessCallbacks.isSuperOrDelegatingConstructorCall(kotlinCall)) {
|
||||||
if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) {
|
if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) {
|
||||||
return listOf(InstantiationOfAbstractClass)
|
return listOf(InstantiationOfAbstractClass)
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ internal object CheckVisibility : ResolutionPart {
|
|||||||
|
|
||||||
internal object MapTypeArguments : ResolutionPart {
|
internal object MapTypeArguments : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
typeArgumentMappingByOriginal = callContext.typeArgumentsToParametersMapper.mapTypeArguments(kotlinCall, candidateDescriptor.original)
|
typeArgumentMappingByOriginal = callComponents.typeArgumentsToParametersMapper.mapTypeArguments(kotlinCall, candidateDescriptor.original)
|
||||||
return typeArgumentMappingByOriginal.diagnostics
|
return typeArgumentMappingByOriginal.diagnostics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ internal object NoTypeArguments : ResolutionPart {
|
|||||||
|
|
||||||
internal object MapArguments : ResolutionPart {
|
internal object MapArguments : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
val mapping = callContext.argumentsToParametersMapper.mapArguments(kotlinCall, candidateDescriptor)
|
val mapping = callComponents.argumentsToParametersMapper.mapArguments(kotlinCall, candidateDescriptor)
|
||||||
argumentMappingByOriginal = mapping.parameterToCallArgumentMap
|
argumentMappingByOriginal = mapping.parameterToCallArgumentMap
|
||||||
return mapping.diagnostics
|
return mapping.diagnostics
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
|
|
||||||
internal object CheckInfixResolutionPart : ResolutionPart {
|
internal object CheckInfixResolutionPart : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
if (callContext.statelessCallbacks.isInfixCall(kotlinCall) &&
|
if (callComponents.statelessCallbacks.isInfixCall(kotlinCall) &&
|
||||||
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
|
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
|
||||||
return listOf(InfixCallNoInfixModifier)
|
return listOf(InfixCallNoInfixModifier)
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ internal object CheckInfixResolutionPart : ResolutionPart {
|
|||||||
|
|
||||||
internal object CheckOperatorResolutionPart : ResolutionPart {
|
internal object CheckOperatorResolutionPart : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
if (callContext.statelessCallbacks.isOperatorCall(kotlinCall) &&
|
if (callComponents.statelessCallbacks.isOperatorCall(kotlinCall) &&
|
||||||
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
|
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
|
||||||
return listOf(InvokeConventionCallNoOperatorModifier)
|
return listOf(InvokeConventionCallNoOperatorModifier)
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ internal object CheckOperatorResolutionPart : ResolutionPart {
|
|||||||
|
|
||||||
internal object CheckAbstractSuperCallPart : ResolutionPart {
|
internal object CheckAbstractSuperCallPart : ResolutionPart {
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
if (callContext.externalPredicates.isSuperExpression(dispatchReceiverArgument)) {
|
if (callComponents.statelessCallbacks.isSuperExpression(dispatchReceiverArgument)) {
|
||||||
if (candidateDescriptor is MemberDescriptor && candidateDescriptor.modality == Modality.ABSTRACT) {
|
if (candidateDescriptor is MemberDescriptor && candidateDescriptor.modality == Modality.ABSTRACT) {
|
||||||
return listOf(AbstractSuperCall)
|
return listOf(AbstractSuperCall)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-8
@@ -30,20 +30,17 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
|||||||
import org.jetbrains.kotlin.types.isDynamic
|
import org.jetbrains.kotlin.types.isDynamic
|
||||||
|
|
||||||
|
|
||||||
class KotlinCallContext(
|
class KotlinCallComponents(
|
||||||
val scopeTower: ImplicitScopeTower,
|
|
||||||
val resolutionCallbacks: KotlinResolutionCallbacks,
|
|
||||||
val statelessCallbacks: KotlinResolutionStatelessCallbacks,
|
val statelessCallbacks: KotlinResolutionStatelessCallbacks,
|
||||||
val argumentsToParametersMapper: ArgumentsToParametersMapper,
|
val argumentsToParametersMapper: ArgumentsToParametersMapper,
|
||||||
val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
|
val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
|
||||||
val resultTypeResolver: ResultTypeResolver,
|
val resultTypeResolver: ResultTypeResolver,
|
||||||
val callableReferenceResolver: CallableReferenceResolver,
|
|
||||||
val constraintInjector: ConstraintInjector,
|
val constraintInjector: ConstraintInjector,
|
||||||
val reflectionTypes: ReflectionTypes
|
val reflectionTypes: ReflectionTypes
|
||||||
)
|
)
|
||||||
|
|
||||||
class SimpleCandidateFactory(
|
class SimpleCandidateFactory(
|
||||||
val callContext: KotlinCallContext,
|
val callComponents: KotlinCallComponents,
|
||||||
val scopeTower: ImplicitScopeTower,
|
val scopeTower: ImplicitScopeTower,
|
||||||
val kotlinCall: KotlinCall
|
val kotlinCall: KotlinCall
|
||||||
): CandidateFactory<SimpleKotlinResolutionCandidate> {
|
): CandidateFactory<SimpleKotlinResolutionCandidate> {
|
||||||
@@ -77,11 +74,11 @@ class SimpleCandidateFactory(
|
|||||||
val extensionArgumentReceiver = createReceiverArgument(kotlinCall.getExplicitExtensionReceiver(explicitReceiverKind), extensionReceiver)
|
val extensionArgumentReceiver = createReceiverArgument(kotlinCall.getExplicitExtensionReceiver(explicitReceiverKind), extensionReceiver)
|
||||||
|
|
||||||
if (ErrorUtils.isError(towerCandidate.descriptor)) {
|
if (ErrorUtils.isError(towerCandidate.descriptor)) {
|
||||||
return ErrorKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor)
|
return ErrorKotlinResolutionCandidate(callComponents, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
val candidateDiagnostics = towerCandidate.diagnostics.toMutableList()
|
val candidateDiagnostics = towerCandidate.diagnostics.toMutableList()
|
||||||
if (callContext.statelessCallbacks.isHiddenInResolution(towerCandidate.descriptor, kotlinCall)) {
|
if (callComponents.statelessCallbacks.isHiddenInResolution(towerCandidate.descriptor, kotlinCall)) {
|
||||||
candidateDiagnostics.add(HiddenDescriptor)
|
candidateDiagnostics.add(HiddenDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +92,7 @@ class SimpleCandidateFactory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SimpleKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver,
|
return SimpleKotlinResolutionCandidate(callComponents, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver,
|
||||||
towerCandidate.descriptor, null, candidateDiagnostics)
|
towerCandidate.descriptor, null, candidateDiagnostics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -105,7 +105,7 @@ sealed class AbstractSimpleKotlinResolutionCandidate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open class SimpleKotlinResolutionCandidate(
|
open class SimpleKotlinResolutionCandidate(
|
||||||
val callContext: KotlinCallContext,
|
val callComponents: KotlinCallComponents,
|
||||||
val scopeTower: ImplicitScopeTower,
|
val scopeTower: ImplicitScopeTower,
|
||||||
override val kotlinCall: KotlinCall,
|
override val kotlinCall: KotlinCall,
|
||||||
val explicitReceiverKind: ExplicitReceiverKind,
|
val explicitReceiverKind: ExplicitReceiverKind,
|
||||||
@@ -114,7 +114,7 @@ open class SimpleKotlinResolutionCandidate(
|
|||||||
val candidateDescriptor: CallableDescriptor,
|
val candidateDescriptor: CallableDescriptor,
|
||||||
val knownTypeParametersResultingSubstitutor: TypeSubstitutor?,
|
val knownTypeParametersResultingSubstitutor: TypeSubstitutor?,
|
||||||
initialDiagnostics: Collection<KotlinCallDiagnostic>
|
initialDiagnostics: Collection<KotlinCallDiagnostic>
|
||||||
) : AbstractSimpleKotlinResolutionCandidate(NewConstraintSystemImpl(callContext.constraintInjector, callContext.resultTypeResolver), initialDiagnostics) {
|
) : AbstractSimpleKotlinResolutionCandidate(NewConstraintSystemImpl(callComponents.constraintInjector, callComponents.resultTypeResolver), initialDiagnostics) {
|
||||||
val csBuilder: ConstraintSystemBuilder get() = constraintSystem.getBuilder()
|
val csBuilder: ConstraintSystemBuilder get() = constraintSystem.getBuilder()
|
||||||
|
|
||||||
lateinit var typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping
|
lateinit var typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping
|
||||||
@@ -134,14 +134,14 @@ open class SimpleKotlinResolutionCandidate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ErrorKotlinResolutionCandidate(
|
class ErrorKotlinResolutionCandidate(
|
||||||
callContext: KotlinCallContext,
|
callComponents: KotlinCallComponents,
|
||||||
scopeTower: ImplicitScopeTower,
|
scopeTower: ImplicitScopeTower,
|
||||||
kotlinCall: KotlinCall,
|
kotlinCall: KotlinCall,
|
||||||
explicitReceiverKind: ExplicitReceiverKind,
|
explicitReceiverKind: ExplicitReceiverKind,
|
||||||
dispatchReceiverArgument: SimpleKotlinCallArgument?,
|
dispatchReceiverArgument: SimpleKotlinCallArgument?,
|
||||||
extensionReceiver: SimpleKotlinCallArgument?,
|
extensionReceiver: SimpleKotlinCallArgument?,
|
||||||
candidateDescriptor: CallableDescriptor
|
candidateDescriptor: CallableDescriptor
|
||||||
) : SimpleKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchReceiverArgument,
|
) : SimpleKotlinResolutionCandidate(callComponents, scopeTower, kotlinCall, explicitReceiverKind, dispatchReceiverArgument,
|
||||||
extensionReceiver, candidateDescriptor, null, listOf()) {
|
extensionReceiver, candidateDescriptor, null, listOf()) {
|
||||||
override val resolutionSequence: List<ResolutionPart> get() = emptyList()
|
override val resolutionSequence: List<ResolutionPart> get() = emptyList()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user