[FIR] Remove delegate specific methods from abstract inference session
This commit is contained in:
+1
-50
@@ -10,24 +10,15 @@ import org.jetbrains.kotlin.fir.expressions.FirStatement
|
|||||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.candidate
|
import org.jetbrains.kotlin.fir.resolve.calls.candidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
|
||||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
|
|
||||||
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.ConstraintStorage
|
||||||
|
|
||||||
abstract class AbstractManyCandidatesInferenceSession(
|
abstract class AbstractManyCandidatesInferenceSession(
|
||||||
protected val components: BodyResolveComponents,
|
protected val components: BodyResolveComponents
|
||||||
private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
|
||||||
) : FirInferenceSession() {
|
) : FirInferenceSession() {
|
||||||
private val errorCalls: MutableList<FirResolvable> = mutableListOf()
|
private val errorCalls: MutableList<FirResolvable> = mutableListOf()
|
||||||
protected val partiallyResolvedCalls: MutableList<Pair<FirResolvable, Candidate>> = mutableListOf()
|
protected val partiallyResolvedCalls: MutableList<Pair<FirResolvable, Candidate>> = mutableListOf()
|
||||||
private val completedCalls: MutableSet<FirResolvable> = mutableSetOf()
|
private val completedCalls: MutableSet<FirResolvable> = mutableSetOf()
|
||||||
|
|
||||||
private val unitType: ConeKotlinType = components.session.builtinTypes.unitType.coneTypeUnsafe()
|
|
||||||
|
|
||||||
override val currentConstraintSystem: ConstraintStorage
|
override val currentConstraintSystem: ConstraintStorage
|
||||||
get() = partiallyResolvedCalls.lastOrNull()
|
get() = partiallyResolvedCalls.lastOrNull()
|
||||||
?.second
|
?.second
|
||||||
@@ -35,8 +26,6 @@ abstract class AbstractManyCandidatesInferenceSession(
|
|||||||
?.currentStorage()
|
?.currentStorage()
|
||||||
?: ConstraintStorage.Empty
|
?: ConstraintStorage.Empty
|
||||||
|
|
||||||
private lateinit var resultingConstraintSystem: NewConstraintSystem
|
|
||||||
|
|
||||||
override fun <T> addCompetedCall(call: T, candidate: Candidate) where T : FirResolvable, T : FirStatement {
|
override fun <T> addCompetedCall(call: T, candidate: Candidate) where T : FirResolvable, T : FirStatement {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
@@ -53,44 +42,6 @@ abstract class AbstractManyCandidatesInferenceSession(
|
|||||||
return !completedCalls.add(call)
|
return !completedCalls.add(call)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun prepareForCompletion(
|
|
||||||
commonSystem: NewConstraintSystem,
|
|
||||||
partiallyResolvedCalls: List<FirResolvable>
|
|
||||||
) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
fun completeCandidates(): List<FirResolvable> {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val resolvedCalls = partiallyResolvedCalls.map { it.first }
|
|
||||||
val commonSystem = components.inferenceComponents.createConstraintSystem().apply {
|
|
||||||
addOtherSystem(currentConstraintSystem)
|
|
||||||
}
|
|
||||||
prepareForCompletion(commonSystem, resolvedCalls)
|
|
||||||
components.inferenceComponents.withInferenceSession(DEFAULT) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
components.callCompleter.completer.complete(
|
|
||||||
commonSystem.asConstraintSystemCompleterContext(),
|
|
||||||
KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL,
|
|
||||||
resolvedCalls as List<FirStatement>,
|
|
||||||
unitType
|
|
||||||
) {
|
|
||||||
postponedArgumentsAnalyzer.analyze(
|
|
||||||
commonSystem.asPostponedArgumentsAnalyzerContext(),
|
|
||||||
it,
|
|
||||||
resolvedCalls.first().candidate
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultingConstraintSystem = commonSystem
|
|
||||||
return resolvedCalls
|
|
||||||
}
|
|
||||||
|
|
||||||
protected val FirResolvable.candidate: Candidate
|
protected val FirResolvable.candidate: Candidate
|
||||||
get() = candidate()!!
|
get() = candidate()!!
|
||||||
|
|
||||||
fun createFinalSubstitutor(): ConeSubstitutor {
|
|
||||||
return resultingConstraintSystem.asReadOnlyStorage()
|
|
||||||
.buildAbstractResultingSubstitutor(components.inferenceComponents.ctx) as ConeSubstitutor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-2
@@ -26,9 +26,8 @@ import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
|||||||
|
|
||||||
class FirBuilderInferenceSession(
|
class FirBuilderInferenceSession(
|
||||||
components: BodyResolveComponents,
|
components: BodyResolveComponents,
|
||||||
postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
|
||||||
private val stubsForPostponedVariables: Map<ConeTypeVariable, ConeStubType>,
|
private val stubsForPostponedVariables: Map<ConeTypeVariable, ConeStubType>,
|
||||||
) : AbstractManyCandidatesInferenceSession(components, postponedArgumentsAnalyzer) {
|
) : AbstractManyCandidatesInferenceSession(components) {
|
||||||
private val commonCalls: MutableList<Pair<FirStatement, Candidate>> = mutableListOf()
|
private val commonCalls: MutableList<Pair<FirStatement, Candidate>> = mutableListOf()
|
||||||
|
|
||||||
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement {
|
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement {
|
||||||
|
|||||||
+2
-10
@@ -124,18 +124,10 @@ class FirCallCompleter(
|
|||||||
return PostponedArgumentsAnalyzer(
|
return PostponedArgumentsAnalyzer(
|
||||||
lambdaAnalyzer, inferenceComponents,
|
lambdaAnalyzer, inferenceComponents,
|
||||||
transformer.components.callResolver
|
transformer.components.callResolver
|
||||||
).also {
|
)
|
||||||
lambdaAnalyzer.initAnalyzer(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class LambdaAnalyzerImpl : LambdaAnalyzer {
|
private inner class LambdaAnalyzerImpl : LambdaAnalyzer {
|
||||||
private lateinit var postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer
|
|
||||||
|
|
||||||
fun initAnalyzer(postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer) {
|
|
||||||
this.postponedArgumentsAnalyzer = postponedArgumentsAnalyzer
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun analyzeAndGetLambdaReturnArguments(
|
override fun analyzeAndGetLambdaReturnArguments(
|
||||||
lambdaAtom: ResolvedLambdaAtom,
|
lambdaAtom: ResolvedLambdaAtom,
|
||||||
receiverType: ConeKotlinType?,
|
receiverType: ConeKotlinType?,
|
||||||
@@ -185,7 +177,7 @@ class FirCallCompleter(
|
|||||||
|
|
||||||
val builderInferenceSession = runIf(stubsForPostponedVariables.isNotEmpty()) {
|
val builderInferenceSession = runIf(stubsForPostponedVariables.isNotEmpty()) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
FirBuilderInferenceSession(components, postponedArgumentsAnalyzer, stubsForPostponedVariables as Map<ConeTypeVariable, ConeStubType>)
|
FirBuilderInferenceSession(components, stubsForPostponedVariables as Map<ConeTypeVariable, ConeStubType>)
|
||||||
}
|
}
|
||||||
|
|
||||||
val localContext = towerDataContextForAnonymousFunctions.getValue(lambdaArgument.symbol)
|
val localContext = towerDataContextForAnonymousFunctions.getValue(lambdaArgument.symbol)
|
||||||
|
|||||||
+39
-3
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
|||||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
import org.jetbrains.kotlin.fir.types.ConeTypeVariableTypeConstructor
|
import org.jetbrains.kotlin.fir.types.ConeTypeVariableTypeConstructor
|
||||||
@@ -24,6 +25,8 @@ import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
|||||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
|
||||||
|
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.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
@@ -33,8 +36,8 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
val property: FirProperty,
|
val property: FirProperty,
|
||||||
initialCall: FirExpression,
|
initialCall: FirExpression,
|
||||||
components: BodyResolveComponents,
|
components: BodyResolveComponents,
|
||||||
postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
|
||||||
) : AbstractManyCandidatesInferenceSession(components, postponedArgumentsAnalyzer) {
|
) : AbstractManyCandidatesInferenceSession(components) {
|
||||||
init {
|
init {
|
||||||
val initialCandidate = (initialCall as? FirResolvable)
|
val initialCandidate = (initialCall as? FirResolvable)
|
||||||
?.calleeReference
|
?.calleeReference
|
||||||
@@ -46,6 +49,8 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val expectedType: ConeKotlinType? by lazy { property.returnTypeRef.coneTypeSafe() }
|
val expectedType: ConeKotlinType? by lazy { property.returnTypeRef.coneTypeSafe() }
|
||||||
|
private val unitType: ConeKotlinType = components.session.builtinTypes.unitType.coneTypeUnsafe()
|
||||||
|
private lateinit var resultingConstraintSystem: NewConstraintSystem
|
||||||
|
|
||||||
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement = false
|
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement = false
|
||||||
|
|
||||||
@@ -56,7 +61,33 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
|
|
||||||
override fun <T> shouldCompleteResolvedSubAtomsOf(call: T): Boolean where T : FirResolvable, T : FirStatement = true
|
override fun <T> shouldCompleteResolvedSubAtomsOf(call: T): Boolean where T : FirResolvable, T : FirStatement = true
|
||||||
|
|
||||||
override fun prepareForCompletion(commonSystem: NewConstraintSystem, partiallyResolvedCalls: List<FirResolvable>) {
|
fun completeCandidates(): List<FirResolvable> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val resolvedCalls = partiallyResolvedCalls.map { it.first }
|
||||||
|
val commonSystem = components.inferenceComponents.createConstraintSystem().apply {
|
||||||
|
addOtherSystem(currentConstraintSystem)
|
||||||
|
}
|
||||||
|
prepareForCompletion(commonSystem, resolvedCalls)
|
||||||
|
components.inferenceComponents.withInferenceSession(DEFAULT) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
components.callCompleter.completer.complete(
|
||||||
|
commonSystem.asConstraintSystemCompleterContext(),
|
||||||
|
KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL,
|
||||||
|
resolvedCalls as List<FirStatement>,
|
||||||
|
unitType
|
||||||
|
) {
|
||||||
|
postponedArgumentsAnalyzer.analyze(
|
||||||
|
commonSystem.asPostponedArgumentsAnalyzerContext(),
|
||||||
|
it,
|
||||||
|
resolvedCalls.first().candidate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultingConstraintSystem = commonSystem
|
||||||
|
return resolvedCalls
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareForCompletion(commonSystem: NewConstraintSystem, partiallyResolvedCalls: List<FirResolvable>) {
|
||||||
val csBuilder = commonSystem.getBuilder()
|
val csBuilder = commonSystem.getBuilder()
|
||||||
for (call in partiallyResolvedCalls) {
|
for (call in partiallyResolvedCalls) {
|
||||||
val candidate = call.candidate
|
val candidate = call.candidate
|
||||||
@@ -67,6 +98,11 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createFinalSubstitutor(): ConeSubstitutor {
|
||||||
|
return resultingConstraintSystem.asReadOnlyStorage()
|
||||||
|
.buildAbstractResultingSubstitutor(components.inferenceComponents.ctx) as ConeSubstitutor
|
||||||
|
}
|
||||||
|
|
||||||
private fun Candidate.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
private fun Candidate.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||||
if (expectedType != null) {
|
if (expectedType != null) {
|
||||||
val accessor = symbol.fir as? FirSimpleFunction ?: return
|
val accessor = symbol.fir as? FirSimpleFunction ?: return
|
||||||
|
|||||||
Reference in New Issue
Block a user