@@ -73,35 +73,6 @@ ExpressionTimer::~ExpressionTimer() {
73
73
.highlight (E->getSourceRange ());
74
74
}
75
75
76
- // / Extend the given depth map by adding depths for all of the subexpressions
77
- // / of the given expression.
78
- static void extendDepthMap (
79
- Expr *expr,
80
- llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &depthMap) {
81
- class RecordingTraversal : public ASTWalker {
82
- public:
83
- llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &DepthMap;
84
- unsigned Depth = 0 ;
85
-
86
- explicit RecordingTraversal (
87
- llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &depthMap)
88
- : DepthMap(depthMap) {}
89
-
90
- std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
91
- DepthMap[E] = {Depth, Parent.getAsExpr ()};
92
- Depth++;
93
- return { true , E };
94
- }
95
-
96
- Expr *walkToExprPost (Expr *E) override {
97
- Depth--;
98
- return E;
99
- }
100
- };
101
-
102
- RecordingTraversal traversal (depthMap);
103
- expr->walk (traversal);
104
- }
105
76
106
77
ConstraintSystem::ConstraintSystem (DeclContext *dc,
107
78
ConstraintSystemOptions options,
@@ -111,7 +82,7 @@ ConstraintSystem::ConstraintSystem(DeclContext *dc,
111
82
CG(*new ConstraintGraph(*this ))
112
83
{
113
84
if (expr) {
114
- extendDepthMap (expr, ExprWeights );
85
+ InputExprs. insert (expr);
115
86
}
116
87
117
88
assert (DC && " context required" );
@@ -530,6 +501,54 @@ ConstraintSystem::getCalleeLocator(ConstraintLocator *locator,
530
501
return getConstraintLocator (anchor);
531
502
}
532
503
504
+ // / Extend the given depth map by adding depths for all of the subexpressions
505
+ // / of the given expression.
506
+ static void extendDepthMap (
507
+ Expr *expr,
508
+ llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &depthMap) {
509
+ class RecordingTraversal : public ASTWalker {
510
+ public:
511
+ llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &DepthMap;
512
+ unsigned Depth = 0 ;
513
+
514
+ explicit RecordingTraversal (
515
+ llvm::DenseMap<Expr *, std::pair<unsigned , Expr *>> &depthMap)
516
+ : DepthMap(depthMap) {}
517
+
518
+ std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
519
+ DepthMap[E] = {Depth, Parent.getAsExpr ()};
520
+ Depth++;
521
+ return { true , E };
522
+ }
523
+
524
+ Expr *walkToExprPost (Expr *E) override {
525
+ Depth--;
526
+ return E;
527
+ }
528
+ };
529
+
530
+ RecordingTraversal traversal (depthMap);
531
+ expr->walk (traversal);
532
+ }
533
+
534
+ Optional<std::pair<unsigned , Expr *>> ConstraintSystem::getExprDepthAndParent (
535
+ Expr *expr) {
536
+ // Bring the set of expression weights up to date.
537
+ while (NumInputExprsInWeights < InputExprs.size ()) {
538
+ extendDepthMap (InputExprs[NumInputExprsInWeights], ExprWeights);
539
+ ++NumInputExprsInWeights;
540
+ }
541
+
542
+ auto e = ExprWeights.find (expr);
543
+ if (e != ExprWeights.end ())
544
+ return e->second ;
545
+
546
+ if (baseCS && baseCS != this )
547
+ return baseCS->getExprDepthAndParent (expr);
548
+
549
+ return None;
550
+ }
551
+
533
552
Type ConstraintSystem::openUnboundGenericType (UnboundGenericType *unbound,
534
553
ConstraintLocatorBuilder locator,
535
554
OpenedTypeMap &replacements) {
0 commit comments