FIR: Attempt to cache constraint storage in delegate inference

This commit is contained in:
Mikhail Glukhikh
2021-11-17 17:43:37 +03:00
committed by teamcity
parent 9aced1c33d
commit 8ae37a3dd2
@@ -25,25 +25,38 @@ class FirDelegatedPropertyInferenceSession(
private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer, private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer,
) : AbstractManyCandidatesInferenceSession(resolutionContext) { ) : AbstractManyCandidatesInferenceSession(resolutionContext) {
private var refreshConstraintStorage = true
private val system = components.session.inferenceComponents.createConstraintSystem()
private var stubToTypeVariableSubstitutor: ConeSubstitutor = ConeSubstitutor.Empty
private fun computeConstraintStorage(): ConstraintStorage {
stubToTypeVariableSubstitutor = createToSyntheticTypeVariableSubstitutor()
syntheticTypeVariableByTypeVariable.values.forEach {
system.registerVariable(it)
}
partiallyResolvedCalls.forEach { (_, candidate) ->
integrateConstraints(
system,
candidate.system.asReadOnlyStorage(),
stubToTypeVariableSubstitutor,
shouldIntegrateAllConstraints = false
)
}
return system.currentStorage()
}
private lateinit var cachedConstraintStorage: ConstraintStorage
override val currentConstraintSystem: ConstraintStorage override val currentConstraintSystem: ConstraintStorage
get() { get() {
// return ConstraintStorage.Empty if (refreshConstraintStorage) {
val system = components.session.inferenceComponents.createConstraintSystem() refreshConstraintStorage = false
cachedConstraintStorage = computeConstraintStorage()
val stubToTypeVariableSubstitutor = createToSyntheticTypeVariableSubstitutor()
syntheticTypeVariableByTypeVariable.values.forEach {
system.registerVariable(it)
} }
partiallyResolvedCalls.forEach { (_, candidate) -> return cachedConstraintStorage
integrateConstraints(
system,
candidate.system.asReadOnlyStorage(),
stubToTypeVariableSubstitutor,
false
)
}
return system.currentStorage()
} }
private val commonSystem = components.session.inferenceComponents.createConstraintSystem() private val commonSystem = components.session.inferenceComponents.createConstraintSystem()
@@ -58,6 +71,12 @@ class FirDelegatedPropertyInferenceSession(
override fun <T> addCompletedCall(call: T, candidate: Candidate) where T : FirResolvable, T : FirStatement { override fun <T> addCompletedCall(call: T, candidate: Candidate) where T : FirResolvable, T : FirStatement {
partiallyResolvedCalls += call to candidate partiallyResolvedCalls += call to candidate
integrateConstraints(
system,
candidate.system.asReadOnlyStorage(),
stubToTypeVariableSubstitutor,
shouldIntegrateAllConstraints = false
)
} }
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement { override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement {
@@ -232,6 +251,7 @@ class FirDelegatedPropertyInferenceSession(
variable as ConeTypeVariable variable as ConeTypeVariable
val syntheticVariable = syntheticTypeVariableByTypeVariable.getOrPut(variable) { val syntheticVariable = syntheticTypeVariableByTypeVariable.getOrPut(variable) {
refreshConstraintStorage = true
ConeTypeVariable("_" + variable.typeConstructor.name) ConeTypeVariable("_" + variable.typeConstructor.name)
} }