add support for cancel compilation from IDE

#KT-8158 Fixed
This commit is contained in:
Michael Nedzelsky
2015-06-25 21:30:51 +03:00
parent 4eeff03525
commit c462d23a0e
12 changed files with 132 additions and 32 deletions
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.context
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressIndicatorProvider
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -27,17 +29,18 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
import org.jetbrains.kotlin.storage.ExceptionTracker
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import kotlin.platform.platformStatic
public trait GlobalContext {
public interface GlobalContext {
public val storageManager: StorageManager
public val exceptionTracker: ExceptionTracker
}
public trait ProjectContext : GlobalContext {
public interface ProjectContext : GlobalContext {
public val project: Project
}
public trait ModuleContext : ProjectContext {
public interface ModuleContext : ProjectContext {
public val module: ModuleDescriptor
public val platformToKotlinClassMap: PlatformToKotlinClassMap
@@ -47,7 +50,7 @@ public trait ModuleContext : ProjectContext {
get() = module.builtIns
}
public trait MutableModuleContext: ModuleContext {
public interface MutableModuleContext: ModuleContext {
override val module: ModuleDescriptorImpl
public fun setDependencies(vararg dependencies: ModuleDescriptorImpl) {
@@ -112,6 +115,29 @@ public fun ContextForNewModule(
return MutableModuleContextImpl(module, projectContext)
}
public class CompilationCanceledException : ProcessCanceledException()
public interface CompilationCanceledStatus {
fun checkCanceled(): Unit
}
public class ProgressIndicatorAndCompilationCanceledStatus {
companion object {
private var canceledStatus: CompilationCanceledStatus? = null
platformStatic
synchronized public fun setCompilationCanceledStatus(newCanceledStatus: CompilationCanceledStatus?): Unit {
canceledStatus = newCanceledStatus
}
platformStatic
public fun checkCanceled(): Unit {
ProgressIndicatorProvider.checkCanceled()
canceledStatus?.checkCanceled()
}
}
}
deprecated("Used temporarily while we are in transition from to lazy resolve")
public open class TypeLazinessToken {
deprecated("Used temporarily while we are in transition from to lazy resolve")
@@ -17,11 +17,11 @@
package org.jetbrains.kotlin.resolve.calls;
import com.google.common.collect.Lists;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.context.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.name.Name;
@@ -74,8 +74,8 @@ public class CallResolver {
private TaskPrioritizer taskPrioritizer;
private AdditionalCheckerProvider additionalCheckerProvider;
private static PerformanceCounter callResolvePerfCounter = new PerformanceCounter("Call resolve", true);
private static PerformanceCounter candidatePerfCounter = new PerformanceCounter("Call resolve candidate analysis", true);
private static final PerformanceCounter callResolvePerfCounter = new PerformanceCounter("Call resolve", true);
private static final PerformanceCounter candidatePerfCounter = new PerformanceCounter("Call resolve candidate analysis", true);
@Inject
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
@@ -255,7 +255,7 @@ public class CallResolver {
@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicCallResolutionContext context) {
ProgressIndicatorProvider.checkCanceled();
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
JetExpression calleeExpression = context.call.getCalleeExpression();
if (calleeExpression instanceof JetSimpleNameExpression) {
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.resolve.calls;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.context.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
@@ -76,7 +76,7 @@ public class CandidateResolver {
@NotNull CallCandidateResolutionContext<D> context,
@NotNull ResolutionTask<D, F> task) {
ProgressIndicatorProvider.checkCanceled();
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
MutableResolvedCall<D> candidateCall = context.candidateCall;
D candidate = candidateCall.getCandidateDescriptor();
@@ -18,28 +18,32 @@ package org.jetbrains.kotlin.resolve.calls.tasks
import com.google.common.collect.Lists
import com.google.common.collect.Sets
import com.intellij.openapi.progress.ProgressIndicatorProvider
import org.jetbrains.kotlin.context.ProgressIndicatorAndCompilationCanceledStatus
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.CallResolverUtil.isOrOverridesSynthesized
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastUtils
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.BOTH_RECEIVERS
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RECEIVER
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.EXTENSION_RECEIVER
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.NO_EXPLICIT_RECEIVER
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCollector
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCollectors
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.filtered
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
import org.jetbrains.kotlin.resolve.calls.CallResolverUtil.isOrOverridesSynthesized
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.util.*
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.*
import org.jetbrains.kotlin.types.isDynamic
public class TaskPrioritizer(private val storageManager: StorageManager) {
@@ -106,7 +110,7 @@ public class TaskPrioritizer(private val storageManager: StorageManager) {
}
private fun <D : CallableDescriptor, F : D> doComputeTasks(receiver: ReceiverValue, c: TaskPrioritizerContext<D, F>) {
ProgressIndicatorProvider.checkCanceled()
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
val resolveInvoke = c.context.call.getDispatchReceiver().exists()
if (resolveInvoke) {