[NI] Introduce inference for coroutines and builder-like constructions
This commit is contained in:
+8
-7
@@ -9,16 +9,14 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
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.ErrorCallInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PartialCallInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.DelegatedPropertyConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ExpectedTypeConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallAtom
|
||||
@@ -26,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.ManyCandidatesResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.PSICallResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.PSIPartialCallInfo
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
@@ -83,6 +82,8 @@ class DelegatedPropertyInferenceSession(
|
||||
|
||||
addConstraintForThis(candidateDescriptor, commonSystem)
|
||||
}
|
||||
|
||||
override fun inferPostponedVariables(initialStorage: ConstraintStorage): Map<TypeConstructor, UnwrappedType> = emptyMap()
|
||||
}
|
||||
|
||||
object InferenceSessionForExistingCandidates : InferenceSession {
|
||||
@@ -91,9 +92,9 @@ object InferenceSessionForExistingCandidates : InferenceSession {
|
||||
}
|
||||
|
||||
override fun addPartialCallInfo(callInfo: PartialCallInfo) {}
|
||||
override fun addCompletedCallInfo(callInfo: CompletedCallInfo) {}
|
||||
override fun addErrorCallInfo(callInfo: ErrorCallInfo) {}
|
||||
|
||||
override fun currentConstraintSystem(): ConstraintStorage {
|
||||
return ConstraintStorage.Empty
|
||||
}
|
||||
override fun currentConstraintSystem(): ConstraintStorage = ConstraintStorage.Empty
|
||||
override fun inferPostponedVariables(initialStorage: ConstraintStorage): Map<TypeConstructor, UnwrappedType> = emptyMap()
|
||||
}
|
||||
|
||||
+8
@@ -145,6 +145,14 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
||||
inferenceSession);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceInferenceSession(@NotNull InferenceSession newInferenceSession) {
|
||||
if (newInferenceSession == inferenceSession) return self();
|
||||
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
|
||||
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings, dataFlowValueFactory,
|
||||
newInferenceSession);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceExpectedType(@Nullable KotlinType newExpectedType) {
|
||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.inference
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CompletedCallInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.types.NonFixedType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
class CoroutineInferenceSession(
|
||||
psiCallResolver: PSICallResolver,
|
||||
postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||
kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||
callComponents: KotlinCallComponents,
|
||||
builtIns: KotlinBuiltIns,
|
||||
private val stubsForPostponedVariables: Map<NewTypeVariable, NonFixedType>,
|
||||
private val trace: BindingTrace,
|
||||
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer
|
||||
) : ManyCandidatesResolver<CallableDescriptor>(
|
||||
psiCallResolver, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter, callComponents, builtIns
|
||||
) {
|
||||
private val suspendCompletedCalls = arrayListOf<PSICompletedCallInfo>()
|
||||
private val normalCompletedCalls = arrayListOf<PSICompletedCallInfo>()
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean = true
|
||||
|
||||
override fun addCompletedCallInfo(callInfo: CompletedCallInfo) {
|
||||
require(callInfo is PSICompletedCallInfo) { "Wrong instance of callInfo: $callInfo" }
|
||||
|
||||
val candidateDescriptor = callInfo.callResolutionResult.resultCallAtom.candidateDescriptor
|
||||
if (candidateDescriptor is FunctionDescriptor && candidateDescriptor.isSuspend)
|
||||
suspendCompletedCalls.add(callInfo)
|
||||
else
|
||||
normalCompletedCalls.add(callInfo)
|
||||
}
|
||||
|
||||
override fun currentConstraintSystem(): ConstraintStorage {
|
||||
return ConstraintStorage.Empty
|
||||
}
|
||||
|
||||
override fun inferPostponedVariables(initialStorage: ConstraintStorage): Map<TypeConstructor, UnwrappedType> {
|
||||
val commonSystem = buildCommonSystem(initialStorage)
|
||||
|
||||
val context = commonSystem.asConstraintSystemCompleterContext()
|
||||
kotlinConstraintSystemCompleter.completeConstraintSystem(context, builtIns.unitType)
|
||||
|
||||
updateCalls(initialStorage, commonSystem)
|
||||
|
||||
return commonSystem.fixedTypeVariables
|
||||
}
|
||||
|
||||
private fun createNonFixedTypeToVariableSubstitutor(): NewTypeSubstitutorByConstructorMap {
|
||||
val bindings = hashMapOf<TypeConstructor, UnwrappedType>()
|
||||
for ((variable, nonFixedType) in stubsForPostponedVariables) {
|
||||
bindings[nonFixedType.constructor] = variable.defaultType
|
||||
}
|
||||
|
||||
return NewTypeSubstitutorByConstructorMap(bindings)
|
||||
}
|
||||
|
||||
private fun integrateConstraints(
|
||||
commonSystem: NewConstraintSystemImpl,
|
||||
storage: ConstraintStorage,
|
||||
nonFixedToVariablesSubstitutor: NewTypeSubstitutor
|
||||
) {
|
||||
storage.notFixedTypeVariables.values.forEach { commonSystem.registerVariable(it.typeVariable) }
|
||||
|
||||
/*
|
||||
* storage can contain the following substitutions:
|
||||
* TypeVariable(A) -> ProperType
|
||||
* TypeVariable(B) -> Special-Non-Fixed-Type
|
||||
*
|
||||
* while substitutor from parameter map non-fixed types to the original type variable
|
||||
* */
|
||||
val callSubstitutor = storage.buildResultingSubstitutor()
|
||||
|
||||
for (initialConstraint in storage.initialConstraints) {
|
||||
val lower = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.a))
|
||||
val upper = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.b))
|
||||
|
||||
if (commonSystem.isProperType(lower) && commonSystem.isProperType(upper)) continue
|
||||
|
||||
when (initialConstraint.constraintKind) {
|
||||
ConstraintKind.LOWER -> error("LOWER constraint shouldn't be used, please use UPPER")
|
||||
|
||||
ConstraintKind.UPPER -> commonSystem.addSubtypeConstraint(lower, upper, initialConstraint.position)
|
||||
|
||||
ConstraintKind.EQUALITY ->
|
||||
with(commonSystem) {
|
||||
addSubtypeConstraint(lower, upper, initialConstraint.position)
|
||||
addSubtypeConstraint(upper, lower, initialConstraint.position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildCommonSystem(initialStorage: ConstraintStorage): NewConstraintSystemImpl {
|
||||
val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns)
|
||||
|
||||
val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor()
|
||||
|
||||
integrateConstraints(commonSystem, initialStorage, nonFixedToVariablesSubstitutor)
|
||||
|
||||
for (suspendCall in suspendCompletedCalls) {
|
||||
integrateConstraints(commonSystem, suspendCall.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor)
|
||||
}
|
||||
|
||||
return commonSystem
|
||||
}
|
||||
|
||||
private fun updateCalls(initialStorage: ConstraintStorage, commonSystem: NewConstraintSystemImpl) {
|
||||
val nonFixedToResult = mutableMapOf<TypeConstructor, UnwrappedType>()
|
||||
for (variable in initialStorage.postponedTypeVariables) {
|
||||
nonFixedToResult[variable.freshTypeConstructor] = commonSystem.fixedTypeVariables[variable.freshTypeConstructor] ?: continue
|
||||
}
|
||||
|
||||
val commonSystemSubstitutor = NewTypeSubstitutorByConstructorMap(nonFixedToResult)
|
||||
|
||||
for (completedCall in suspendCompletedCalls + normalCompletedCalls) {
|
||||
val resultCallAtom = completedCall.callResolutionResult.resultCallAtom
|
||||
val call = resultCallAtom.atom.getResolvedPsiKotlinCall<CallableDescriptor>(trace) ?: continue
|
||||
|
||||
val resultingCallSubstitutor = completedCall
|
||||
.callResolutionResult
|
||||
.constraintSystem
|
||||
.fixedTypeVariables
|
||||
.entries
|
||||
.associate { it.key to commonSystemSubstitutor.safeSubstitute(it.value) }
|
||||
|
||||
call.setResultingSubstitutor(NewTypeSubstitutorByConstructorMap(resultingCallSubstitutor))
|
||||
|
||||
val resultingDescriptor = call.resultingDescriptor
|
||||
kotlinToResolvedCallTransformer.reportCallDiagnostic(
|
||||
completedCall.context, trace, resultCallAtom, resultingDescriptor, commonSystem.diagnostics
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-9
@@ -23,7 +23,11 @@ import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CoroutineInferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
@@ -33,10 +37,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||
import org.jetbrains.kotlin.types.TypeApproximator
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
@@ -60,7 +61,11 @@ class KotlinResolutionCallbacksImpl(
|
||||
val dataFlowValueFactory: DataFlowValueFactory,
|
||||
override val inferenceSession: InferenceSession,
|
||||
val constantExpressionEvaluator: ConstantExpressionEvaluator,
|
||||
val typeResolver: TypeResolver
|
||||
val typeResolver: TypeResolver,
|
||||
val psiCallResolver: PSICallResolver,
|
||||
val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||
val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||
val callComponents: KotlinCallComponents
|
||||
) : KotlinResolutionCallbacks {
|
||||
class LambdaInfo(val expectedType: UnwrappedType, val contextDependency: ContextDependency) {
|
||||
val returnStatements = ArrayList<Pair<KtReturnExpression, LambdaContextInfo?>>()
|
||||
@@ -76,8 +81,9 @@ class KotlinResolutionCallbacksImpl(
|
||||
isSuspend: Boolean,
|
||||
receiverType: UnwrappedType?,
|
||||
parameters: List<UnwrappedType>,
|
||||
expectedReturnType: UnwrappedType?
|
||||
): List<KotlinCallArgument> {
|
||||
expectedReturnType: UnwrappedType?,
|
||||
stubsForPostponedVariables: Map<NewTypeVariable, NonFixedType>
|
||||
): Pair<List<KotlinCallArgument>, InferenceSession?> {
|
||||
val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument
|
||||
val outerCallContext = psiCallArgument.outerCallContext
|
||||
|
||||
@@ -122,11 +128,22 @@ class KotlinResolutionCallbacksImpl(
|
||||
val approximatesExpectedType =
|
||||
typeApproximator.approximateToSubType(expectedType, TypeApproximatorConfiguration.LocalDeclaration) ?: expectedType
|
||||
|
||||
val coroutineSession =
|
||||
if (stubsForPostponedVariables.isNotEmpty())
|
||||
CoroutineInferenceSession(
|
||||
psiCallResolver, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter,
|
||||
callComponents, builtIns, stubsForPostponedVariables, trace, kotlinToResolvedCallTransformer
|
||||
)
|
||||
else
|
||||
null
|
||||
|
||||
val actualContext = outerCallContext
|
||||
.replaceBindingTrace(trace)
|
||||
.replaceContextDependency(lambdaInfo.contextDependency)
|
||||
.replaceExpectedType(approximatesExpectedType)
|
||||
.replaceDataFlowInfo(psiCallArgument.lambdaInitialDataFlowInfo)
|
||||
.replaceDataFlowInfo(psiCallArgument.lambdaInitialDataFlowInfo).let {
|
||||
if (coroutineSession != null) it.replaceInferenceSession(coroutineSession) else it
|
||||
}
|
||||
|
||||
val functionTypeInfo = expressionTypingServices.getTypeInfo(psiCallArgument.expression, actualContext)
|
||||
trace.record(BindingContext.NEW_INFERENCE_LAMBDA_INFO, psiCallArgument.ktFunction, LambdaInfo.STUB_EMPTY)
|
||||
@@ -159,7 +176,7 @@ class KotlinResolutionCallbacksImpl(
|
||||
|
||||
returnArguments.addIfNotNull(lastExpressionArgument)
|
||||
|
||||
return returnArguments
|
||||
return Pair(returnArguments, coroutineSession)
|
||||
}
|
||||
|
||||
private fun getLastDeparentesizedExpression(psiCallArgument: PSIKotlinCallArgument): KtExpression? {
|
||||
|
||||
+6
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression
|
||||
import org.jetbrains.kotlin.resolve.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -25,8 +26,10 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isSuperOrDelegatingConstructorCall
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionStatelessCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.isCoroutineCallWithAdditionalInference
|
||||
import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@@ -57,4 +60,7 @@ class KotlinResolutionStatelessCallbacksImpl(
|
||||
|
||||
override fun getVariableCandidateIfInvoke(functionCall: KotlinCall) =
|
||||
functionCall.safeAs<PSIKotlinCallForInvoke>()?.variableCall
|
||||
|
||||
override fun isCoroutineCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean =
|
||||
isCoroutineCallWithAdditionalInference(parameter, argument.psiCallArgument.valueArgument)
|
||||
}
|
||||
|
||||
+6
-3
@@ -96,6 +96,10 @@ class KotlinToResolvedCallTransformer(
|
||||
is CompletedCallResolutionResult, is ErrorCallResolutionResult -> {
|
||||
val candidate = (baseResolvedCall as SingleCallResolutionResult).resultCallAtom
|
||||
|
||||
context.inferenceSession.addCompletedCallInfo(
|
||||
PSICompletedCallInfo(baseResolvedCall as CompletedCallResolutionResult, context, tracingStrategy)
|
||||
)
|
||||
|
||||
val resultSubstitutor = baseResolvedCall.constraintSystem.buildResultingSubstitutor()
|
||||
val ktPrimitiveCompleter = ResolvedAtomCompleter(
|
||||
resultSubstitutor, context.trace, context, this, expressionTypingServices, argumentTypeResolver,
|
||||
@@ -153,8 +157,7 @@ class KotlinToResolvedCallTransformer(
|
||||
diagnostics: Collection<KotlinCallDiagnostic>
|
||||
): NewResolvedCallImpl<D> {
|
||||
if (trace != null) {
|
||||
val storedResolvedCall =
|
||||
completedSimpleAtom.atom.psiKotlinCall.psiCall.getResolvedCall(trace.bindingContext)?.safeAs<NewResolvedCallImpl<D>>()
|
||||
val storedResolvedCall = completedSimpleAtom.atom.psiKotlinCall.getResolvedPsiKotlinCall<D>(trace)
|
||||
if (storedResolvedCall != null) {
|
||||
storedResolvedCall.setResultingSubstitutor(resultSubstitutor)
|
||||
storedResolvedCall.updateDiagnostics(diagnostics)
|
||||
@@ -339,7 +342,7 @@ class KotlinToResolvedCallTransformer(
|
||||
reportCallDiagnostic(context, trace, functionCall.resolvedCallAtom, functionCall.resultingDescriptor, emptyList())
|
||||
}
|
||||
|
||||
private fun reportCallDiagnostic(
|
||||
fun reportCallDiagnostic(
|
||||
context: BasicCallResolutionContext,
|
||||
trace: BindingTrace,
|
||||
completedCallAtom: ResolvedCallAtom,
|
||||
|
||||
+17
-4
@@ -7,28 +7,31 @@ package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
|
||||
abstract class ManyCandidatesResolver<D : CallableDescriptor>(
|
||||
private val psiCallResolver: PSICallResolver,
|
||||
private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||
private val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||
private val callComponents: KotlinCallComponents,
|
||||
protected val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||
protected val callComponents: KotlinCallComponents,
|
||||
val builtIns: KotlinBuiltIns
|
||||
) : InferenceSession {
|
||||
private val partiallyResolvedCallsInfo = arrayListOf<PSIPartialCallInfo>()
|
||||
private val errorCallsInfo = arrayListOf<PSIErrorCallInfo<D>>()
|
||||
|
||||
abstract fun prepareForCompletion(commonSystem: NewConstraintSystem, resolvedCallsInfo: List<PSIPartialCallInfo>)
|
||||
open fun prepareForCompletion(commonSystem: NewConstraintSystem, resolvedCallsInfo: List<PSIPartialCallInfo>) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
return false
|
||||
@@ -41,6 +44,10 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
|
||||
partiallyResolvedCallsInfo.add(callInfo)
|
||||
}
|
||||
|
||||
override fun addCompletedCallInfo(callInfo: CompletedCallInfo) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun addErrorCallInfo(callInfo: ErrorCallInfo) {
|
||||
if (callInfo !is PSIErrorCallInfo<*>) {
|
||||
throw AssertionError("Error call info for $callInfo should be instance of PSIErrorCallInfo")
|
||||
@@ -108,6 +115,12 @@ class PSIPartialCallInfo(
|
||||
val tracingStrategy: TracingStrategy
|
||||
) : PartialCallInfo
|
||||
|
||||
class PSICompletedCallInfo(
|
||||
override val callResolutionResult: CompletedCallResolutionResult,
|
||||
val context: BasicCallResolutionContext,
|
||||
val tracingStrategy: TracingStrategy
|
||||
) : CompletedCallInfo
|
||||
|
||||
class PSIErrorCallInfo<D : CallableDescriptor>(
|
||||
override val callResolutionResult: CallResolutionResult,
|
||||
val result: OverloadResolutionResults<D>
|
||||
|
||||
@@ -24,9 +24,11 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
@@ -61,7 +63,9 @@ class PSICallResolver(
|
||||
private val argumentTypeResolver: ArgumentTypeResolver,
|
||||
private val effectSystem: EffectSystem,
|
||||
private val constantExpressionEvaluator: ConstantExpressionEvaluator,
|
||||
private val dataFlowValueFactory: DataFlowValueFactory
|
||||
private val dataFlowValueFactory: DataFlowValueFactory,
|
||||
private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||
private val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter
|
||||
) {
|
||||
private val givenCandidatesName = Name.special("<given candidates>")
|
||||
|
||||
@@ -160,7 +164,8 @@ class PSICallResolver(
|
||||
KotlinResolutionCallbacksImpl(
|
||||
trace, expressionTypingServices, typeApproximator,
|
||||
argumentTypeResolver, languageVersionSettings, kotlinToResolvedCallTransformer,
|
||||
dataFlowValueFactory, inferenceSession, constantExpressionEvaluator, typeResolver
|
||||
dataFlowValueFactory, inferenceSession, constantExpressionEvaluator, typeResolver,
|
||||
this, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter, callComponents
|
||||
)
|
||||
|
||||
private fun calculateExpectedType(context: BasicCallResolutionContext): UnwrappedType? {
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
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.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
@@ -26,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategyForInvoke
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val KotlinCall.psiKotlinCall: PSIKotlinCall
|
||||
get() {
|
||||
@@ -35,6 +39,9 @@ val KotlinCall.psiKotlinCall: PSIKotlinCall
|
||||
return this as PSIKotlinCall
|
||||
}
|
||||
|
||||
fun <D : CallableDescriptor> KotlinCall.getResolvedPsiKotlinCall(trace: BindingTrace): NewResolvedCallImpl<D>? =
|
||||
psiKotlinCall.psiCall.getResolvedCall(trace.bindingContext) as? NewResolvedCallImpl<D>
|
||||
|
||||
abstract class PSIKotlinCall : KotlinCall {
|
||||
abstract val psiCall: Call
|
||||
abstract val startingDataFlowInfo: DataFlowInfo
|
||||
|
||||
Reference in New Issue
Block a user