Skip to content

Commit 0f10333

Browse files
committed
Sema: Allow turning off expression timer with -solver-expression-time-threshold=0
1 parent 85bd8ed commit 0f10333

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ class ExpressionTimer {
250250
bool PrintWarning;
251251

252252
public:
253-
/// This constructor sets a default threshold defined for all expressions
254-
/// via compiler flag `solver-expression-time-threshold`.
255-
ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS);
256253
ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
257254
unsigned thresholdInSecs);
258255

@@ -5494,7 +5491,9 @@ class ConstraintSystem {
54945491
/// increase the likelihood that a favored constraint will be successfully
54955492
/// resolved before any others.
54965493
void optimizeConstraints(Expr *e);
5497-
5494+
5495+
void startExpressionTimer(ExpressionTimer::AnchorType anchor);
5496+
54985497
/// Determine if we've already explored too many paths in an
54995498
/// attempt to solve this expression.
55005499
std::pair<bool, SourceRange> isAlreadyTooComplex = {false, SourceRange()};

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ bool ConstraintSystem::Candidate::solve(
822822
ConstraintSystem cs(DC, std::nullopt);
823823

824824
// Set up expression type checker timer for the candidate.
825-
cs.Timer.emplace(E, cs);
825+
cs.startExpressionTimer(E);
826826

827827
// Generate constraints for the new system.
828828
if (auto generatedExpr = cs.generateConstraints(E, DC)) {
@@ -1521,7 +1521,7 @@ ConstraintSystem::solveImpl(SyntacticElementTarget &target,
15211521

15221522
// Set up the expression type checker timer.
15231523
if (Expr *expr = target.getAsExpr())
1524-
Timer.emplace(expr, *this);
1524+
startExpressionTimer(expr);
15251525

15261526
if (generateConstraints(target, allowFreeTypeVariables))
15271527
return SolutionResult::forError();
@@ -1707,7 +1707,7 @@ bool ConstraintSystem::solveForCodeCompletion(
17071707
setContextualInfo(expr, target.getExprContextualTypeInfo());
17081708

17091709
// Set up the expression type checker timer.
1710-
Timer.emplace(expr, *this);
1710+
startExpressionTimer(expr);
17111711

17121712
shrink(expr);
17131713
}

lib/Sema/CSStep.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ bool ConjunctionStep::attempt(const ConjunctionElement &element) {
901901
// is important for closures with large number of statements
902902
// in them.
903903
if (CS.Timer) {
904-
CS.Timer.emplace(element.getLocator(), CS);
904+
CS.Timer.reset();
905+
CS.startExpressionTimer(element.getLocator());
905906
}
906907

907908
auto success = element.attempt(CS);

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ using namespace inference;
5252

5353
#define DEBUG_TYPE "ConstraintSystem"
5454

55-
ExpressionTimer::ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS)
56-
: ExpressionTimer(
57-
Anchor, CS,
58-
CS.getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold) {}
59-
6055
ExpressionTimer::ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
6156
unsigned thresholdInSecs)
6257
: Anchor(Anchor), Context(CS.getASTContext()),
@@ -139,6 +134,16 @@ ConstraintSystem::~ConstraintSystem() {
139134
delete &CG;
140135
}
141136

137+
void ConstraintSystem::startExpressionTimer(ExpressionTimer::AnchorType anchor) {
138+
ASSERT(!Timer);
139+
140+
unsigned timeout = getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold;
141+
if (timeout == 0)
142+
return;
143+
144+
Timer.emplace(anchor, *this, timeout);
145+
}
146+
142147
void ConstraintSystem::incrementScopeCounter() {
143148
++NumSolverScopes;
144149
if (auto *Stats = getASTContext().Stats)

0 commit comments

Comments
 (0)