[NI] Improve performance of resolution part for postoned variables

This commit is contained in:
Mikhail Zarechenskiy
2018-05-04 13:07:36 +03:00
parent a30a1f2a96
commit 5187f6b060
3 changed files with 14 additions and 14 deletions
@@ -195,22 +195,16 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) {
// smartset!
val typesForCoroutineCall = resolvedCall.argumentToCandidateParameter
.filter { (argument, parameter) -> callComponents.statelessCallbacks.isCoroutineCall(argument, parameter) }
.mapNotNull { it.value.type.getReceiverTypeFromFunctionType() }
for ((argument, parameter) in resolvedCall.argumentToCandidateParameter) {
if (!callComponents.statelessCallbacks.isCoroutineCall(argument, parameter)) continue
val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue
if (typesForCoroutineCall.isEmpty()) return
for (freshVariable in resolvedCall.substitutor.freshVariables) {
val isPostponedVariable = typesForCoroutineCall.any { typeForCoroutineCall ->
typeForCoroutineCall.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }
for (freshVariable in resolvedCall.substitutor.freshVariables) {
if (csBuilder.isPostponedTypeVariable(freshVariable)) continue
if (receiverType.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }) {
csBuilder.markPostponedVariable(freshVariable)
}
}
if (isPostponedVariable) {
csBuilder.markPostponedVariable(freshVariable)
}
}
}
}
@@ -38,6 +38,7 @@ interface ConstraintSystemOperation {
fun isProperType(type: UnwrappedType): Boolean
fun isTypeVariable(type: UnwrappedType): Boolean
fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean
fun getProperSuperTypeConstructors(type: UnwrappedType): List<TypeConstructor>
}
@@ -188,6 +188,11 @@ class NewConstraintSystemImpl(
return notFixedTypeVariables.containsKey(type.constructor)
}
override fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean {
checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION)
return typeVariable in postponedTypeVariables
}
// ConstraintInjector.Context
override val allTypeVariables: Map<TypeConstructor, NewTypeVariable>
get() {