mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #41282 from xedin/too-complex-with-multistmt-cljs
[ConstraintSystem] Adjust expression complexity computation to account for multi-statement closures
This commit is contained in:
@@ -43,13 +43,18 @@ using namespace inference;
|
||||
|
||||
#define DEBUG_TYPE "ConstraintSystem"
|
||||
|
||||
ExpressionTimer::ExpressionTimer(Expr *E, ConstraintSystem &CS)
|
||||
: E(E),
|
||||
Context(CS.getASTContext()),
|
||||
ExpressionTimer::ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS)
|
||||
: ExpressionTimer(
|
||||
Anchor, CS,
|
||||
CS.getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold) {}
|
||||
|
||||
ExpressionTimer::ExpressionTimer(AnchorType Anchor, ConstraintSystem &CS,
|
||||
unsigned thresholdInMillis)
|
||||
: Anchor(Anchor), Context(CS.getASTContext()),
|
||||
StartTime(llvm::TimeRecord::getCurrentTime()),
|
||||
ThresholdInMillis(thresholdInMillis),
|
||||
PrintDebugTiming(CS.getASTContext().TypeCheckerOpts.DebugTimeExpressions),
|
||||
PrintWarning(true) {
|
||||
}
|
||||
PrintWarning(true) {}
|
||||
|
||||
ExpressionTimer::~ExpressionTimer() {
|
||||
auto elapsed = getElapsedProcessTimeInFractionalSeconds();
|
||||
@@ -59,20 +64,38 @@ ExpressionTimer::~ExpressionTimer() {
|
||||
// Round up to the nearest 100th of a millisecond.
|
||||
llvm::errs() << llvm::format("%0.2f", ceil(elapsed * 100000) / 100)
|
||||
<< "ms\t";
|
||||
E->getLoc().print(llvm::errs(), Context.SourceMgr);
|
||||
if (auto *E = Anchor.dyn_cast<Expr *>()) {
|
||||
E->getLoc().print(llvm::errs(), Context.SourceMgr);
|
||||
} else {
|
||||
auto *locator = Anchor.get<ConstraintLocator *>();
|
||||
locator->dump(&Context.SourceMgr, llvm::errs());
|
||||
}
|
||||
llvm::errs() << "\n";
|
||||
}
|
||||
|
||||
if (!PrintWarning)
|
||||
return;
|
||||
|
||||
const auto WarnLimit = getWarnLimit();
|
||||
if (WarnLimit != 0 && elapsedMS >= WarnLimit && E->getLoc().isValid())
|
||||
Context.Diags.diagnose(E->getLoc(), diag::debug_long_expression,
|
||||
elapsedMS, WarnLimit)
|
||||
.highlight(E->getSourceRange());
|
||||
}
|
||||
ASTNode anchor;
|
||||
if (auto *locator = Anchor.dyn_cast<ConstraintLocator *>()) {
|
||||
anchor = simplifyLocatorToAnchor(locator);
|
||||
// If locator couldn't be simplified down to a single AST
|
||||
// element, let's warn about its root.
|
||||
if (!anchor)
|
||||
anchor = locator->getAnchor();
|
||||
} else {
|
||||
anchor = Anchor.get<Expr *>();
|
||||
}
|
||||
|
||||
const auto WarnLimit = getWarnLimit();
|
||||
if (WarnLimit != 0 && elapsedMS >= WarnLimit &&
|
||||
anchor.getStartLoc().isValid()) {
|
||||
Context.Diags
|
||||
.diagnose(anchor.getStartLoc(), diag::debug_long_expression, elapsedMS,
|
||||
WarnLimit)
|
||||
.highlight(anchor.getSourceRange());
|
||||
}
|
||||
}
|
||||
|
||||
ConstraintSystem::ConstraintSystem(DeclContext *dc,
|
||||
ConstraintSystemOptions options)
|
||||
|
||||
Reference in New Issue
Block a user