Fix UI freezes caused by calls with a huge number overloads

While we have an overload resolution algorithm working for O(n^2),
call resolution for the single particular call may work more then just
a second.
Thus, we need to call ProgressManager.checkCanceled() with more granularity

^KT-35135 Fixed
This commit is contained in:
Denis Zharkov
2020-02-14 15:42:07 +03:00
parent 842e2dc02f
commit aac72871e7
9 changed files with 52 additions and 5 deletions
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.types.checker.NewKotlinTypeCheckerImpl
import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalClassifierAnalyzer
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
import org.jetbrains.kotlin.util.ProgressManagerBasedCancellationChecker
fun StorageComponentContainer.configureModule(
moduleContext: ModuleContext,
@@ -97,6 +98,7 @@ private fun StorageComponentContainer.configurePlatformIndependentComponents() {
useImpl<CompilerDeserializationConfiguration>()
useImpl<ClassicTypeSystemContextForCS>()
useInstance(ProgressManagerBasedCancellationChecker)
}
/**
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCallImpl
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature.Companion.argumentValueType
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.CancellationChecker
import java.util.*
@@ -55,12 +56,14 @@ fun createOverloadingConflictResolver(
builtIns: KotlinBuiltIns,
module: ModuleDescriptor,
specificityComparator: TypeSpecificityComparator,
platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator
platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator,
cancellationChecker: CancellationChecker,
) = OverloadingConflictResolver(
builtIns,
module,
specificityComparator,
platformOverloadsSpecificityComparator,
cancellationChecker,
MutableResolvedCall<*>::getResultingDescriptor,
ConstraintSystemBuilderImpl.Companion::forSpecificity,
MutableResolvedCall<*>::createFlatSignature,
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.calls.tower.TowerUtilsKt;
import org.jetbrains.kotlin.util.CancellationChecker;
import java.util.*;
@@ -42,10 +43,11 @@ public class ResolutionResultsHandler {
@NotNull KotlinBuiltIns builtIns,
@NotNull ModuleDescriptor module,
@NotNull TypeSpecificityComparator specificityComparator,
@NotNull PlatformOverloadsSpecificityComparator platformOverloadsSpecificityComparator
@NotNull PlatformOverloadsSpecificityComparator platformOverloadsSpecificityComparator,
@NotNull CancellationChecker cancellationChecker
) {
overloadingConflictResolver = FlatSignatureForResolvedCallKt.createOverloadingConflictResolver(
builtIns, module, specificityComparator, platformOverloadsSpecificityComparator
builtIns, module, specificityComparator, platformOverloadsSpecificityComparator, cancellationChecker
);
}
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.util
import com.intellij.openapi.progress.ProgressManager
object ProgressManagerBasedCancellationChecker : CancellationChecker {
override fun check() {
ProgressManager.checkCanceled()
}
}