[NI] Improve performance of resolution part for postoned variables
This commit is contained in:
+8
-14
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -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>
|
||||
}
|
||||
|
||||
+5
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user