Skip to content

Commit 998a787

Browse files
committed
[Sema] Add cancellation flag to typechecker options
Once this flag is set, the type checker will bail out with a “expression to complex” error.
1 parent 17d3335 commit 998a787

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/swift/Basic/LangOptions.h

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

598+
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
599+
/// typechecking should be aborted at the next possible opportunity.
600+
/// This is used by SourceKit to cancel requests for which the result is no
601+
/// longer of interest.
602+
std::shared_ptr<bool> CancellationFlag = nullptr;
603+
598604
/// If non-zero, abort the switch statement exhaustiveness checker if
599605
/// the Space::minus function is called more than this many times.
600606
///

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5155,6 +5155,10 @@ class ConstraintSystem {
51555155
if (isExpressionAlreadyTooComplex)
51565156
return true;
51575157

5158+
auto CancellationFlag = getASTContext().TypeCheckerOpts.CancellationFlag;
5159+
if (CancellationFlag && *CancellationFlag)
5160+
return true;
5161+
51585162
auto used = getASTContext().getSolverMemory() + solutionMemory;
51595163
MaxMemory = std::max(used, MaxMemory);
51605164
auto threshold = getASTContext().TypeCheckerOpts.SolverMemoryThreshold;

0 commit comments

Comments
 (0)