Skip to content

[6.2] Sema: Fix -warn-long-expression-type-checking when expression timer is disabled #82508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ class ExpressionTimer {
bool PrintWarning;

public:
const static unsigned NoLimit = (unsigned) -1;

ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
unsigned thresholdInSecs);

Expand All @@ -274,6 +276,9 @@ class ExpressionTimer {
/// Return the remaining process time in seconds until the
/// threshold specified during construction is reached.
unsigned getRemainingProcessTimeInSeconds() const {
if (ThresholdInSecs == NoLimit)
return NoLimit;

auto elapsed = unsigned(getElapsedProcessTimeInFractionalSeconds());
return elapsed >= ThresholdInSecs ? 0 : ThresholdInSecs - elapsed;
}
Expand Down
15 changes: 12 additions & 3 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,18 @@ ConstraintSystem::~ConstraintSystem() {
void ConstraintSystem::startExpressionTimer(ExpressionTimer::AnchorType anchor) {
ASSERT(!Timer);

unsigned timeout = getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold;
if (timeout == 0)
return;
const auto &opts = getASTContext().TypeCheckerOpts;
unsigned timeout = opts.ExpressionTimeoutThreshold;

// If either the timeout is set, or we're asked to emit warnings,
// start the timer. Otherwise, don't start the timer, it's needless
// overhead.
if (timeout == 0) {
if (opts.WarnLongExpressionTypeChecking == 0)
return;

timeout = ExpressionTimer::NoLimit;
}

Timer.emplace(anchor, *this, timeout);
}
Expand Down
5 changes: 2 additions & 3 deletions test/Constraints/warn_long_compile.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %target-typecheck-verify-swift -warn-long-expression-type-checking=1 -warn-long-function-bodies=1
// REQUIRES: rdar44305428
// RUN: %target-typecheck-verify-swift -warn-long-expression-type-checking=1 -solver-disable-shrink -warn-long-function-bodies=1
@_silgen_name("generic_foo")
func foo<T>(_ x: T) -> T

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

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