Skip to content

Commit bcf5e97

Browse files
committed
RequirementMachine: Take concrete substitutions into account when checking completion depth limit
We didn't look at the length of terms appearing in concrete substitutions, so runaway recursion there was only caught by the completion step limit which takes much longer.
1 parent 889d65d commit bcf5e97

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ bool Rule::isProtocolRefinementRule() const {
7272
LHS[0] != LHS[1]);
7373
}
7474

75+
/// Returns the length of the left hand side.
76+
unsigned Rule::getDepth() const {
77+
auto result = LHS.size();
78+
79+
if (LHS.back().isSuperclassOrConcreteType()) {
80+
for (auto substitution : LHS.back().getSubstitutions()) {
81+
result = std::max(result, substitution.size());
82+
}
83+
}
84+
85+
return result;
86+
}
87+
7588
/// Linear order on rules; compares LHS followed by RHS.
7689
int Rule::compare(const Rule &other, RewriteContext &ctx) const {
7790
int compare = LHS.compare(other.LHS, ctx);

lib/AST/RequirementMachine/RewriteSystem.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ class Rule final {
116116
Redundant = true;
117117
}
118118

119-
/// Returns the length of the left hand side.
120-
unsigned getDepth() const {
121-
return LHS.size();
122-
}
119+
unsigned getDepth() const;
123120

124121
int compare(const Rule &other, RewriteContext &ctx) const;
125122

0 commit comments

Comments
 (0)