Skip to content

Commit 9042536

Browse files
committed
[SourceKit] Move the cancellation flag from TypeCheckerOptions to ASTContext
We need to modify the pointer pointing to the cancellation flag when reusing an ASTContext for code completion. This is not possible by the previous design because `TypeCheckerOptions` was `const`. Moving the cancellation flag to `ASTContext` will also allow other stages of the compiler to honor a cancellation request.
1 parent 237338b commit 9042536

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

include/swift/AST/ASTContext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ class ASTContext final {
273273
/// Diags - The diagnostics engine.
274274
DiagnosticEngine &Diags;
275275

276+
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
277+
/// all operations working on this ASTContext should be aborted at the next
278+
/// possible opportunity.
279+
/// This is used by SourceKit to cancel requests for which the result is no
280+
/// longer of interest.
281+
/// The returned result will be discarded, so the operation that acknowledges
282+
/// the cancellation might return with any result.
283+
std::shared_ptr<std::atomic<bool>> CancellationFlag = nullptr;
284+
276285
TypeCheckCompletionCallback *CompletionCallback = nullptr;
277286

278287
/// The request-evaluator that is used to process various requests.

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,6 @@ namespace swift {
606606
/// than this many seconds.
607607
unsigned ExpressionTimeoutThreshold = 600;
608608

609-
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
610-
/// typechecking should be aborted at the next possible opportunity.
611-
/// This is used by SourceKit to cancel requests for which the result is no
612-
/// longer of interest.
613-
std::shared_ptr<std::atomic<bool>> CancellationFlag = nullptr;
614-
615609
/// If non-zero, abort the switch statement exhaustiveness checker if
616610
/// the Space::minus function is called more than this many times.
617611
///

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5176,7 +5176,7 @@ class ConstraintSystem {
51765176
if (isExpressionAlreadyTooComplex)
51775177
return true;
51785178

5179-
auto CancellationFlag = getASTContext().TypeCheckerOpts.CancellationFlag;
5179+
auto CancellationFlag = getASTContext().CancellationFlag;
51805180
if (CancellationFlag && CancellationFlag->load(std::memory_order_relaxed))
51815181
return true;
51825182

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
10791079
Invocation, convertFileContentsToInputs(Contents));
10801080

10811081
Invocation.getLangOptions().CollectParsedToken = true;
1082-
Invocation.getTypeCheckerOptions().CancellationFlag = CancellationFlag;
10831082

10841083
if (FileSystem != llvm::vfs::getRealFileSystem()) {
10851084
CompIns.getSourceMgr().setFileSystem(FileSystem);
@@ -1091,6 +1090,7 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
10911090
Error = "compilation setup failed";
10921091
return nullptr;
10931092
}
1093+
CompIns.getASTContext().CancellationFlag = CancellationFlag;
10941094
if (CompIns.loadStdlibIfNeeded()) {
10951095
LOG_WARN_FUNC("Loading the stdlib failed");
10961096
Error = "Loading the stdlib failed";

0 commit comments

Comments
 (0)