Skip to content

Commit 0b6f8c8

Browse files
hborlasimanerush
authored andcommitted
[Requirement Machine] Fix the order of requirements that involve pack elements.
1 parent 2ea4586 commit 0b6f8c8

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,6 @@ int swift::compareDependentTypes(Type type1, Type type2) {
782782
// Fast-path check for equality.
783783
if (type1->isEqual(type2)) return 0;
784784

785-
// Packs are always ordered after scalar type parameters.
786-
if (type1->isParameterPack() != type2->isParameterPack())
787-
return type2->isParameterPack() ? -1 : +1;
788-
789785
// Ordering is as follows:
790786
// - Generic params
791787
auto gp1 = type1->getAs<GenericTypeParamType>();
@@ -940,7 +936,12 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
940936
llvm::errs() << "\n";
941937
dumpAndAbort();
942938
}
943-
if (compareDependentTypes(firstType, secondType) >= 0) {
939+
// FIXME: Same-element rewrite rules are of the form [element].T => U,
940+
// which turns into a same-type requirement repeat U == each T. The
941+
// pack element must always be on the left side of the rule, so type
942+
// parameters can appear out of order in the final same-type requirement.
943+
if (firstType->isParameterPack() == secondType->isParameterPack() &&
944+
compareDependentTypes(firstType, secondType) >= 0) {
944945
llvm::errs() << "Out-of-order type parameters: ";
945946
reqt.dump(llvm::errs());
946947
llvm::errs() << "\n";

lib/AST/RequirementMachine/Term.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,17 @@ 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;
140139
for (auto *iter = lhsBegin; iter != lhsEnd; ++iter) {
141140
if (iter->getKind() == Symbol::Kind::Name)
142141
++lhsNameCount;
143-
144-
if (iter->getKind() == Symbol::Kind::PackElement)
145-
++lhsPackElementCount;
146142
}
147143

148144
unsigned rhsNameCount = 0;
149-
unsigned rhsPackElementCount = 0;
150145
for (auto *iter = rhsBegin; iter != rhsEnd; ++iter) {
151146
if (iter->getKind() == Symbol::Kind::Name)
152147
++rhsNameCount;
153-
154-
if (iter->getKind() == Symbol::Kind::PackElement)
155-
++rhsPackElementCount;
156148
}
157149

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-
163150
// A term with more name symbols orders after a term with fewer name symbols.
164151
if (lhsNameCount != rhsNameCount)
165152
return lhsNameCount > rhsNameCount ? 1 : -1;

0 commit comments

Comments
 (0)