Introduce hierarchy of inference sessions
This commit is contained in:
+6
-2
@@ -32,7 +32,8 @@ class DelegatedPropertyInferenceSession(
|
||||
postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||
kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||
callComponents: KotlinCallComponents,
|
||||
builtIns: KotlinBuiltIns
|
||||
builtIns: KotlinBuiltIns,
|
||||
override val parentSession: InferenceSession?
|
||||
) : ManyCandidatesResolver<FunctionDescriptor>(
|
||||
psiCallResolver, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter, callComponents, builtIns
|
||||
) {
|
||||
@@ -92,7 +93,10 @@ class DelegatedPropertyInferenceSession(
|
||||
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
|
||||
}
|
||||
|
||||
class InferenceSessionForExistingCandidates(private val resolveReceiverIndependently: Boolean) : InferenceSession {
|
||||
class InferenceSessionForExistingCandidates(
|
||||
private val resolveReceiverIndependently: Boolean,
|
||||
override val parentSession: InferenceSession?
|
||||
) : InferenceSession {
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
return !ErrorUtils.isError(candidate.resolvedCall.candidateDescriptor)
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ class DelegatedPropertyResolver(
|
||||
|
||||
val contextForProvideDelegate = createContextForProvideDelegateMethod(
|
||||
scopeForDelegate, delegateDataFlow, traceForProvideDelegate,
|
||||
InferenceSessionForExistingCandidates(substitutionMap != null)
|
||||
InferenceSessionForExistingCandidates(substitutionMap != null, inferenceSession)
|
||||
)
|
||||
|
||||
val provideDelegateResults = getProvideDelegateMethod(
|
||||
@@ -652,7 +652,7 @@ class DelegatedPropertyResolver(
|
||||
val newInferenceSession = DelegatedPropertyInferenceSession(
|
||||
variableDescriptor, expectedType, psiCallResolver,
|
||||
postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter,
|
||||
callComponents, builtIns
|
||||
callComponents, builtIns, inferenceSession
|
||||
)
|
||||
|
||||
val receiver = createReceiverForGetSetValueMethods(delegateExpression, delegateType, trace)
|
||||
|
||||
+16
-6
@@ -15,10 +15,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CompletedCallInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.stableType
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
@@ -71,6 +68,8 @@ class BuilderInferenceSession(
|
||||
|
||||
private var hasInapplicableCall = false
|
||||
|
||||
override val parentSession = topLevelCallContext.inferenceSession
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
val system = candidate.getSystem() as NewConstraintSystemImpl
|
||||
|
||||
@@ -147,7 +146,18 @@ class BuilderInferenceSession(
|
||||
descriptor.extensionReceiverParameter?.type?.contains { it is StubType } == true
|
||||
}
|
||||
|
||||
private fun isTopLevelBuilderInferenceCall() = topLevelCallContext.inferenceSession !is BuilderInferenceSession
|
||||
private fun isTopLevelBuilderInferenceCall() = findParentBuildInferenceSession() == null
|
||||
|
||||
private fun findParentBuildInferenceSession(): BuilderInferenceSession? {
|
||||
var currentSession: InferenceSession? = parentSession
|
||||
|
||||
while (currentSession != null) {
|
||||
if (currentSession is BuilderInferenceSession) return currentSession
|
||||
currentSession = currentSession.parentSession
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun hasInapplicableCall(): Boolean = hasInapplicableCall
|
||||
|
||||
@@ -234,7 +244,7 @@ class BuilderInferenceSession(
|
||||
bindings[nonFixedType.constructor] = variable.defaultType
|
||||
}
|
||||
|
||||
val parentBuilderInferenceCallSession = topLevelCallContext.inferenceSession as? BuilderInferenceSession
|
||||
val parentBuilderInferenceCallSession = findParentBuildInferenceSession()
|
||||
|
||||
if (parentBuilderInferenceCallSession != null) {
|
||||
bindings.putAll(parentBuilderInferenceCallSession.createNonFixedTypeToVariableMap())
|
||||
|
||||
+4
@@ -12,8 +12,12 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
interface InferenceSession {
|
||||
val parentSession: InferenceSession?
|
||||
|
||||
companion object {
|
||||
val default = object : InferenceSession {
|
||||
override val parentSession: InferenceSession? = null
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean = true
|
||||
override fun addPartialCallInfo(callInfo: PartialCallInfo) {}
|
||||
override fun addErrorCallInfo(callInfo: ErrorCallInfo) {}
|
||||
|
||||
Reference in New Issue
Block a user