@@ -43,14 +43,14 @@ using namespace inference;
43
43
44
44
#define DEBUG_TYPE " ConstraintSystem"
45
45
46
- ExpressionTimer::ExpressionTimer (Expr *E , ConstraintSystem &CS)
46
+ ExpressionTimer::ExpressionTimer (AnchorType Anchor , ConstraintSystem &CS)
47
47
: ExpressionTimer(
48
- E , CS,
48
+ Anchor , CS,
49
49
CS.getASTContext().TypeCheckerOpts.ExpressionTimeoutThreshold) {}
50
50
51
- ExpressionTimer::ExpressionTimer (Expr *E , ConstraintSystem &CS,
51
+ ExpressionTimer::ExpressionTimer (AnchorType Anchor , ConstraintSystem &CS,
52
52
unsigned thresholdInMillis)
53
- : E(E ), Context(CS.getASTContext()),
53
+ : Anchor(Anchor ), Context(CS.getASTContext()),
54
54
StartTime(llvm::TimeRecord::getCurrentTime()),
55
55
ThresholdInMillis(thresholdInMillis),
56
56
PrintDebugTiming(CS.getASTContext().TypeCheckerOpts.DebugTimeExpressions),
@@ -64,21 +64,39 @@ ExpressionTimer::~ExpressionTimer() {
64
64
// Round up to the nearest 100th of a millisecond.
65
65
llvm::errs () << llvm::format (" %0.2f" , ceil (elapsed * 100000 ) / 100 )
66
66
<< " 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
+ }
68
73
llvm::errs () << " \n " ;
69
74
}
70
75
71
76
if (!PrintWarning)
72
77
return ;
73
78
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
+
74
90
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
+ }
79
98
}
80
99
81
-
82
100
ConstraintSystem::ConstraintSystem (DeclContext *dc,
83
101
ConstraintSystemOptions options)
84
102
: Context(dc->getASTContext ()), DC(dc), Options(options),
0 commit comments