[NI] Extract PostponedArgumentsAnalyzerContext from PostponedArgumentsAnalyzer
This commit is contained in:
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.returnExpressions
|
|||||||
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirErrorFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirErrorFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirErrorPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirErrorPropertySymbol
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class CandidateFactory private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PostponedArgumentsAnalyzer.Context.addSubsystemFromExpression(statement: FirStatement) {
|
fun PostponedArgumentsAnalyzerContext.addSubsystemFromExpression(statement: FirStatement) {
|
||||||
when (statement) {
|
when (statement) {
|
||||||
is FirFunctionCall,
|
is FirFunctionCall,
|
||||||
is FirQualifiedAccessExpression,
|
is FirQualifiedAccessExpression,
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.StoreNameReference
|
|||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
import org.jetbrains.kotlin.fir.types.ConeTypeVariable
|
import org.jetbrains.kotlin.fir.types.ConeTypeVariable
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||||
@@ -48,7 +48,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun analyze(
|
fun analyze(
|
||||||
c: PostponedArgumentsAnalyzer.Context,
|
c: PostponedArgumentsAnalyzerContext,
|
||||||
argument: PostponedResolvedAtom,
|
argument: PostponedResolvedAtom,
|
||||||
candidate: Candidate
|
candidate: Candidate
|
||||||
//diagnosticsHolder: KotlinDiagnosticsHolder
|
//diagnosticsHolder: KotlinDiagnosticsHolder
|
||||||
@@ -96,7 +96,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun analyzeLambda(
|
private fun analyzeLambda(
|
||||||
c: PostponedArgumentsAnalyzer.Context,
|
c: PostponedArgumentsAnalyzerContext,
|
||||||
lambda: ResolvedLambdaAtom,
|
lambda: ResolvedLambdaAtom,
|
||||||
candidate: Candidate
|
candidate: Candidate
|
||||||
//diagnosticHolder: KotlinDiagnosticsHolder
|
//diagnosticHolder: KotlinDiagnosticsHolder
|
||||||
|
|||||||
+4
-21
@@ -11,10 +11,8 @@ import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
|||||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPositionImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
@@ -27,24 +25,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|||||||
class PostponedArgumentsAnalyzer(
|
class PostponedArgumentsAnalyzer(
|
||||||
private val callableReferenceResolver: CallableReferenceResolver
|
private val callableReferenceResolver: CallableReferenceResolver
|
||||||
) {
|
) {
|
||||||
interface Context : TypeSystemInferenceExtensionContext {
|
|
||||||
fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructorMarker, StubTypeMarker>): TypeSubstitutorMarker
|
|
||||||
fun buildNotFixedVariablesToStubTypesSubstitutor(): TypeSubstitutorMarker
|
|
||||||
fun bindingStubsForPostponedVariables(): Map<TypeVariableMarker, StubTypeMarker>
|
|
||||||
|
|
||||||
// type can be proper if it not contains not fixed type variables
|
|
||||||
fun canBeProper(type: KotlinTypeMarker): Boolean
|
|
||||||
|
|
||||||
fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean
|
|
||||||
|
|
||||||
// mutable operations
|
|
||||||
fun addOtherSystem(otherSystem: ConstraintStorage)
|
|
||||||
|
|
||||||
fun getBuilder(): ConstraintSystemBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
fun analyze(
|
fun analyze(
|
||||||
c: Context,
|
c: PostponedArgumentsAnalyzerContext,
|
||||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||||
argument: ResolvedAtom,
|
argument: ResolvedAtom,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
@@ -77,7 +60,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
val substitute: (KotlinType) -> UnwrappedType
|
val substitute: (KotlinType) -> UnwrappedType
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Context.createSubstituteFunctorForLambdaAnalysis(): SubstitutorAndStubsForLambdaAnalysis {
|
fun PostponedArgumentsAnalyzerContext.createSubstituteFunctorForLambdaAnalysis(): SubstitutorAndStubsForLambdaAnalysis {
|
||||||
val stubsForPostponedVariables = bindingStubsForPostponedVariables()
|
val stubsForPostponedVariables = bindingStubsForPostponedVariables()
|
||||||
val currentSubstitutor = buildCurrentSubstitutor(stubsForPostponedVariables.mapKeys { it.key.freshTypeConstructor(this) })
|
val currentSubstitutor = buildCurrentSubstitutor(stubsForPostponedVariables.mapKeys { it.key.freshTypeConstructor(this) })
|
||||||
return SubstitutorAndStubsForLambdaAnalysis(stubsForPostponedVariables) {
|
return SubstitutorAndStubsForLambdaAnalysis(stubsForPostponedVariables) {
|
||||||
@@ -86,7 +69,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun analyzeLambda(
|
fun analyzeLambda(
|
||||||
c: Context,
|
c: PostponedArgumentsAnalyzerContext,
|
||||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||||
lambda: ResolvedLambdaAtom,
|
lambda: ResolvedLambdaAtom,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
@@ -153,7 +136,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun applyResultsOfAnalyzedLambdaToCandidateSystem(
|
fun applyResultsOfAnalyzedLambdaToCandidateSystem(
|
||||||
c: Context,
|
c: PostponedArgumentsAnalyzerContext,
|
||||||
lambda: ResolvedLambdaAtom,
|
lambda: ResolvedLambdaAtom,
|
||||||
returnArgumentsAnalysisResult: ReturnArgumentsAnalysisResult,
|
returnArgumentsAnalysisResult: ReturnArgumentsAnalysisResult,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.calls.components
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
|
import org.jetbrains.kotlin.types.model.*
|
||||||
|
|
||||||
|
interface PostponedArgumentsAnalyzerContext : TypeSystemInferenceExtensionContext {
|
||||||
|
fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructorMarker, StubTypeMarker>): TypeSubstitutorMarker
|
||||||
|
fun buildNotFixedVariablesToStubTypesSubstitutor(): TypeSubstitutorMarker
|
||||||
|
fun bindingStubsForPostponedVariables(): Map<TypeVariableMarker, StubTypeMarker>
|
||||||
|
|
||||||
|
// type can be proper if it not contains not fixed type variables
|
||||||
|
fun canBeProper(type: KotlinTypeMarker): Boolean
|
||||||
|
|
||||||
|
fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean
|
||||||
|
|
||||||
|
// mutable operations
|
||||||
|
fun addOtherSystem(otherSystem: ConstraintStorage)
|
||||||
|
|
||||||
|
fun getBuilder(): ConstraintSystemBuilder
|
||||||
|
}
|
||||||
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.inference
|
package org.jetbrains.kotlin.resolve.calls.inference
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgument
|
import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgument
|
||||||
@@ -61,7 +61,7 @@ fun CallableDescriptor.substituteAndApproximateTypes(
|
|||||||
return substitute(TypeSubstitutor.create(wrappedSubstitution)) ?: this
|
return substitute(TypeSubstitutor.create(wrappedSubstitution)) ?: this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PostponedArgumentsAnalyzer.Context.addSubsystemFromArgument(argument: KotlinCallArgument?): Boolean {
|
fun PostponedArgumentsAnalyzerContext.addSubsystemFromArgument(argument: KotlinCallArgument?): Boolean {
|
||||||
return when (argument) {
|
return when (argument) {
|
||||||
is SubKotlinCallArgument -> {
|
is SubKotlinCallArgument -> {
|
||||||
addOtherSystem(argument.callResult.constraintSystem)
|
addOtherSystem(argument.callResult.constraintSystem)
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.inference
|
package org.jetbrains.kotlin.resolve.calls.inference
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
|
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.PostponedArgumentInputTypesResolver
|
import org.jetbrains.kotlin.resolve.calls.inference.components.PostponedArgumentInputTypesResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
@@ -32,6 +32,6 @@ interface NewConstraintSystem {
|
|||||||
fun asReadOnlyStorage(): ConstraintStorage
|
fun asReadOnlyStorage(): ConstraintStorage
|
||||||
|
|
||||||
fun asConstraintSystemCompleterContext(): ConstraintSystemCompletionContext
|
fun asConstraintSystemCompleterContext(): ConstraintSystemCompletionContext
|
||||||
fun asPostponedArgumentsAnalyzerContext(): PostponedArgumentsAnalyzer.Context
|
fun asPostponedArgumentsAnalyzerContext(): PostponedArgumentsAnalyzerContext
|
||||||
fun asPostponedArgumentInputTypesResolverContext(): PostponedArgumentInputTypesResolver.Context
|
fun asPostponedArgumentInputTypesResolverContext(): PostponedArgumentInputTypesResolver.Context
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.*
|
import org.jetbrains.kotlin.resolve.calls.inference.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom
|
||||||
@@ -29,7 +29,7 @@ class NewConstraintSystemImpl(
|
|||||||
ResultTypeResolver.Context,
|
ResultTypeResolver.Context,
|
||||||
ConstraintSystemCompletionContext,
|
ConstraintSystemCompletionContext,
|
||||||
PostponedArgumentInputTypesResolver.Context,
|
PostponedArgumentInputTypesResolver.Context,
|
||||||
PostponedArgumentsAnalyzer.Context {
|
PostponedArgumentsAnalyzerContext {
|
||||||
private val storage = MutableConstraintStorage()
|
private val storage = MutableConstraintStorage()
|
||||||
private var state = State.BUILDING
|
private var state = State.BUILDING
|
||||||
private val typeVariablesTransaction: MutableList<TypeVariableMarker> = SmartList()
|
private val typeVariablesTransaction: MutableList<TypeVariableMarker> = SmartList()
|
||||||
|
|||||||
Reference in New Issue
Block a user