Skip to content

Commit 7dd559c

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 ce6b06d commit 7dd559c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/swift/Sema/ConstraintSystem.h

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

249249
public:
250+
const static unsigned NoLimit = (unsigned) -1;
251+
250252
ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
251253
unsigned thresholdInSecs);
252254

@@ -272,6 +274,9 @@ class ExpressionTimer {
272274
/// Return the remaining process time in seconds until the
273275
/// threshold specified during construction is reached.
274276
unsigned getRemainingProcessTimeInSeconds() const {
277+
if (ThresholdInSecs == NoLimit)
278+
return NoLimit;
279+
275280
auto elapsed = unsigned(getElapsedProcessTimeInFractionalSeconds());
276281
return elapsed >= ThresholdInSecs ? 0 : ThresholdInSecs - elapsed;
277282
}

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
}

test/Constraints/warn_long_compile.swift

Lines changed: 1 addition & 2 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 -disable-constraint-solver-performance-hacks -warn-long-function-bodies=1 -solver-expression-time-threshold=60
2-
// FIXME: -solver-expression-time-threshold=60 should not be needed
1+
// RUN: %target-typecheck-verify-swift -warn-long-expression-type-checking=1 -disable-constraint-solver-performance-hacks -warn-long-function-bodies=1
32
@_silgen_name("generic_foo")
43
func foo<T>(_ x: T) -> T
54

0 commit comments

Comments
 (0)