@@ -43,14 +43,14 @@ using namespace inference;
4343
4444#define DEBUG_TYPE " ConstraintSystem"
4545
46- ExpressionTimer::ExpressionTimer (Expr *E , ConstraintSystem &CS)
46+ ExpressionTimer::ExpressionTimer (AnchorType Anchor , ConstraintSystem &CS)
4747 : ExpressionTimer(
48- E , CS,
48+ Anchor , CS,
4949 CS.getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold) {}
5050
51- ExpressionTimer::ExpressionTimer (Expr *E , ConstraintSystem &CS,
51+ ExpressionTimer::ExpressionTimer (AnchorType Anchor , ConstraintSystem &CS,
5252 unsigned thresholdInMillis)
53- : E(E ), Context(CS.getASTContext()),
53+ : Anchor(Anchor ), Context(CS.getASTContext()),
5454 StartTime(llvm::TimeRecord::getCurrentTime()),
5555 ThresholdInMillis(thresholdInMillis),
5656 PrintDebugTiming(CS.getASTContext().TypeCheckerOpts.DebugTimeExpressions),
@@ -64,21 +64,39 @@ ExpressionTimer::~ExpressionTimer() {
6464 // Round up to the nearest 100th of a millisecond.
6565 llvm::errs () << llvm::format (" %0.2f" , ceil (elapsed * 100000 ) / 100 )
6666 << " ms\t " ;
67- E->getLoc ().print (llvm::errs (), Context.SourceMgr );
67+ if (auto *E = Anchor.dyn_cast <Expr *>()) {
68+ E->getLoc ().print (llvm::errs (), Context.SourceMgr );
69+ } else {
70+ auto *locator = Anchor.get <ConstraintLocator *>();
71+ locator->dump (&Context.SourceMgr , llvm::errs ());
72+ }
6873 llvm::errs () << " \n " ;
6974 }
7075
7176 if (!PrintWarning)
7277 return ;
7378
79+ ASTNode anchor;
80+ if (auto *locator = Anchor.dyn_cast <ConstraintLocator *>()) {
81+ anchor = simplifyLocatorToAnchor (locator);
82+ // If locator couldn't be simplified down to a single AST
83+ // element, let's warn about its root.
84+ if (!anchor)
85+ anchor = locator->getAnchor ();
86+ } else {
87+ anchor = Anchor.get <Expr *>();
88+ }
89+
7490 const auto WarnLimit = getWarnLimit ();
75- if (WarnLimit != 0 && elapsedMS >= WarnLimit && E->getLoc ().isValid ())
76- Context.Diags .diagnose (E->getLoc (), diag::debug_long_expression,
77- elapsedMS, WarnLimit)
78- .highlight (E->getSourceRange ());
91+ if (WarnLimit != 0 && elapsedMS >= WarnLimit &&
92+ anchor.getStartLoc ().isValid ()) {
93+ Context.Diags
94+ .diagnose (anchor.getStartLoc (), diag::debug_long_expression, elapsedMS,
95+ WarnLimit)
96+ .highlight (anchor.getSourceRange ());
97+ }
7998}
8099
81-
82100ConstraintSystem::ConstraintSystem (DeclContext *dc,
83101 ConstraintSystemOptions options)
84102 : Context(dc->getASTContext ()), DC(dc), Options(options),
0 commit comments