Skip to content

Commit 3cc52dc

Browse files
authored
Merge pull request swiftlang#84042 from hamishknight/too-complex-log
[CS] Add debug message when hitting too complex limit
2 parents ade5c6a + 0142d0b commit 3cc52dc

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5671,13 +5671,22 @@ class ConstraintSystem {
56715671
if (CancellationFlag && CancellationFlag->load(std::memory_order_relaxed))
56725672
return true;
56735673

5674+
auto markTooComplex = [&](SourceRange range, StringRef reason) {
5675+
if (isDebugMode()) {
5676+
if (solverState)
5677+
llvm::errs().indent(solverState->getCurrentIndent());
5678+
llvm::errs() << "(too complex: " << reason << ")\n";
5679+
}
5680+
isAlreadyTooComplex = {true, range};
5681+
return true;
5682+
};
5683+
56745684
auto used = getASTContext().getSolverMemory() + solutionMemory;
56755685
MaxMemory = std::max(used, MaxMemory);
56765686
auto threshold = getASTContext().TypeCheckerOpts.SolverMemoryThreshold;
56775687
if (MaxMemory > threshold) {
56785688
// No particular location for OoM problems.
5679-
isAlreadyTooComplex.first = true;
5680-
return true;
5689+
return markTooComplex(SourceRange(), "exceeded memory limit");
56815690
}
56825691

56835692
if (Timer && Timer->isExpired()) {
@@ -5686,23 +5695,18 @@ class ConstraintSystem {
56865695
// emitting an error.
56875696
Timer->disableWarning();
56885697

5689-
isAlreadyTooComplex = {true, Timer->getAffectedRange()};
5690-
return true;
5698+
return markTooComplex(Timer->getAffectedRange(), "exceeded time limit");
56915699
}
56925700

56935701
auto &opts = getASTContext().TypeCheckerOpts;
56945702

56955703
// Bail out once we've looked at a really large number of choices.
5696-
if (opts.SolverScopeThreshold && NumSolverScopes > opts.SolverScopeThreshold) {
5697-
isAlreadyTooComplex.first = true;
5698-
return true;
5699-
}
5704+
if (opts.SolverScopeThreshold && NumSolverScopes > opts.SolverScopeThreshold)
5705+
return markTooComplex(SourceRange(), "exceeded scope limit");
57005706

57015707
// Bail out once we've taken a really large number of steps.
5702-
if (opts.SolverTrailThreshold && NumTrailSteps > opts.SolverTrailThreshold) {
5703-
isAlreadyTooComplex.first = true;
5704-
return true;
5705-
}
5708+
if (opts.SolverTrailThreshold && NumTrailSteps > opts.SolverTrailThreshold)
5709+
return markTooComplex(SourceRange(), "exceeded trail limit");
57065710

57075711
return false;
57085712
}

0 commit comments

Comments
 (0)