[SourceKit] Allow explicit cancellation of requests with a cancellation token

The key changes here are
- To keep track of cancellation tokens for all `ScheduledConsumer`s in `SwiftASTManager`
- Generate unique request handles for all incoming requests (`create_request_handle `), use these request handles as cancellation tokens and return them from the `sourcekitd_send_request` methods
- Implement cancellation with `sourcekitd_cancel_request` as the entry point and `SwiftASTManager::cancelASTConsumer` as the termination point

Everything else is just plumbing the cancellation token through the various abstraction layers.

rdar://83391505
This commit is contained in:
Alex Hoppen
2021-09-23 19:14:47 +02:00
parent 4521c99d56
commit 7d5ee83a61
18 changed files with 546 additions and 292 deletions

View File

@@ -736,10 +736,10 @@ public:
}
};
void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
StringRef SourceName,
ArrayRef<const char *> Args,
std::shared_ptr<EditorConsumer> Consumer) {
void SwiftLangSupport::editorOpenSwiftSourceInterface(
StringRef Name, StringRef SourceName, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
std::shared_ptr<EditorConsumer> Consumer) {
std::string Error;
auto Invocation = ASTMgr->getInvocation(Args, SourceName, Error);
if (!Invocation) {
@@ -750,6 +750,7 @@ void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
SourceName, IFaceGenContexts, Consumer, Invocation);
static const char OncePerASTToken = 0;
getASTManager()->processASTAsync(Invocation, AstConsumer, &OncePerASTToken,
CancellationToken,
llvm::vfs::getRealFileSystem());
}