Skip to content

Commit 017be57

Browse files
committed
Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e broke -warn-long-expression-type-checking because now the ExpressionTimer is not instantiated by default and that entire code path is skipped. Change it so that if -warn-long-expression-type-checking is passed in, we still start the timer, we just don't ever consider it to have 'expired'. Fixes rdar://problem/152998878.
1 parent e744e35 commit 017be57

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ class ExpressionTimer {
249249
bool PrintWarning;
250250

251251
public:
252+
const static unsigned NoLimit = (unsigned) -1;
253+
252254
ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
253255
unsigned thresholdInSecs);
254256

@@ -274,6 +276,9 @@ class ExpressionTimer {
274276
/// Return the remaining process time in seconds until the
275277
/// threshold specified during construction is reached.
276278
unsigned getRemainingProcessTimeInSeconds() const {
279+
if (ThresholdInSecs == NoLimit)
280+
return NoLimit;
281+
277282
auto elapsed = unsigned(getElapsedProcessTimeInFractionalSeconds());
278283
return elapsed >= ThresholdInSecs ? 0 : ThresholdInSecs - elapsed;
279284
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,18 @@ ConstraintSystem::~ConstraintSystem() {
141141
void ConstraintSystem::startExpressionTimer(ExpressionTimer::AnchorType anchor) {
142142
ASSERT(!Timer);
143143

144-
unsigned timeout = getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold;
145-
if (timeout == 0)
146-
return;
144+
const auto &opts = getASTContext().TypeCheckerOpts;
145+
unsigned timeout = opts.ExpressionTimeoutThreshold;
146+
147+
// If either the timeout is set, or we're asked to emit warnings,
148+
// start the timer. Otherwise, don't start the timer, it's needless
149+
// overhead.
150+
if (timeout == 0) {
151+
if (opts.WarnLongExpressionTypeChecking == 0)
152+
return;
153+
154+
timeout = ExpressionTimer::NoLimit;
155+
}
147156

148157
Timer.emplace(anchor, *this, timeout);
149158
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -warn-long-expression-type-checking=1 -warn-long-function-bodies=1
2-
// REQUIRES: rdar44305428
1+
// RUN: %target-typecheck-verify-swift -warn-long-expression-type-checking=1 -solver-disable-shrink -warn-long-function-bodies=1
32
@_silgen_name("generic_foo")
43
func foo<T>(_ x: T) -> T
54

@@ -8,6 +7,6 @@ func foo(_ x: Int) -> Int
87

98
func test(m: Double) -> Int {
109
// expected-warning@-1 {{global function 'test(m:)' took}}
11-
return Int(foo(Float(m) / 20) * 20 - 2) + 10
10+
return ~(~(~(~(~(~(~(~(~(~(~(~(0))))))))))))
1211
// expected-warning@-1 {{expression took}}
1312
}

0 commit comments

Comments
 (0)