Skip to content

Commit 0dc6719

Browse files
committed
[Requirement Machine] Fix the order of terms with pack element symbols to always appear on the left-hand side of the same-element rewrite rule.
1 parent 1ba38c5 commit 0dc6719

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/AST/RequirementMachine/Term.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,30 @@ static std::optional<int> shortlexCompare(const Symbol *lhsBegin,
136136
RewriteContext &ctx) {
137137
// First, compare the number of name and pack element symbols.
138138
unsigned lhsNameCount = 0;
139+
unsigned lhsPackElementCount = 0;
139140
for (auto *iter = lhsBegin; iter != lhsEnd; ++iter) {
140141
if (iter->getKind() == Symbol::Kind::Name)
141142
++lhsNameCount;
143+
144+
if (iter->getKind() == Symbol::Kind::PackElement)
145+
++lhsPackElementCount;
142146
}
143147

144148
unsigned rhsNameCount = 0;
149+
unsigned rhsPackElementCount = 0;
145150
for (auto *iter = rhsBegin; iter != rhsEnd; ++iter) {
146151
if (iter->getKind() == Symbol::Kind::Name)
147152
++rhsNameCount;
153+
154+
if (iter->getKind() == Symbol::Kind::PackElement)
155+
++rhsPackElementCount;
148156
}
149157

158+
// A term with more pack element symbols orders after a term with
159+
// fewer pack element symbols.
160+
if (lhsPackElementCount != rhsPackElementCount)
161+
return lhsPackElementCount > rhsPackElementCount ? 1 : -1;
162+
150163
// A term with more name symbols orders after a term with fewer name symbols.
151164
if (lhsNameCount != rhsNameCount)
152165
return lhsNameCount > rhsNameCount ? 1 : -1;

0 commit comments

Comments
 (0)