[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() { internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) { override fun KotlinResolutionCandidate.process(workIndex: Int) {
// smartset! for ((argument, parameter) in resolvedCall.argumentToCandidateParameter) {
val typesForCoroutineCall = resolvedCall.argumentToCandidateParameter if (!callComponents.statelessCallbacks.isCoroutineCall(argument, parameter)) continue
.filter { (argument, parameter) -> callComponents.statelessCallbacks.isCoroutineCall(argument, parameter) } val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue
.mapNotNull { it.value.type.getReceiverTypeFromFunctionType() }
if (typesForCoroutineCall.isEmpty()) return for (freshVariable in resolvedCall.substitutor.freshVariables) {
if (csBuilder.isPostponedTypeVariable(freshVariable)) continue
for (freshVariable in resolvedCall.substitutor.freshVariables) { if (receiverType.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }) {
val isPostponedVariable = typesForCoroutineCall.any { typeForCoroutineCall -> csBuilder.markPostponedVariable(freshVariable)
typeForCoroutineCall.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor } }
} }
if (isPostponedVariable) {
csBuilder.markPostponedVariable(freshVariable)
}
} }
} }
} }
@@ -38,6 +38,7 @@ interface ConstraintSystemOperation {
fun isProperType(type: UnwrappedType): Boolean fun isProperType(type: UnwrappedType): Boolean
fun isTypeVariable(type: UnwrappedType): Boolean fun isTypeVariable(type: UnwrappedType): Boolean
fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean
fun getProperSuperTypeConstructors(type: UnwrappedType): List<TypeConstructor> fun getProperSuperTypeConstructors(type: UnwrappedType): List<TypeConstructor>
} }
@@ -188,6 +188,11 @@ class NewConstraintSystemImpl(
return notFixedTypeVariables.containsKey(type.constructor) return notFixedTypeVariables.containsKey(type.constructor)
} }
override fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean {
checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION)
return typeVariable in postponedTypeVariables
}
// ConstraintInjector.Context // ConstraintInjector.Context
override val allTypeVariables: Map<TypeConstructor, NewTypeVariable> override val allTypeVariables: Map<TypeConstructor, NewTypeVariable>
get() { get() {