Skip to content

Commit fd809ca

Browse files
committed
GSB: Instead of sorting connected components, sort the final requirements
There are fewer of them, since it is possible for the vast majority of connected components to generate no requirements.
1 parent 65620d7 commit fd809ca

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6888,14 +6888,6 @@ namespace {
68886888

68896889
} // end anonymous namespace
68906890

6891-
static int compareSameTypeComponents(const SameTypeComponentRef *lhsPtr,
6892-
const SameTypeComponentRef *rhsPtr){
6893-
Type lhsType = lhsPtr->first->derivedSameTypeComponents[lhsPtr->second].type;
6894-
Type rhsType = rhsPtr->first->derivedSameTypeComponents[rhsPtr->second].type;
6895-
6896-
return compareDependentTypes(lhsType, rhsType);
6897-
}
6898-
68996891
void GenericSignatureBuilder::enumerateRequirements(
69006892
TypeArrayView<GenericTypeParamType> genericParams,
69016893
llvm::function_ref<
@@ -6914,10 +6906,6 @@ void GenericSignatureBuilder::enumerateRequirements(
69146906
subjects.push_back({&equivClass, i});
69156907
}
69166908

6917-
// Sort the subject types in canonical order.
6918-
llvm::array_pod_sort(subjects.begin(), subjects.end(),
6919-
compareSameTypeComponents);
6920-
69216909
for (const auto &subject : subjects) {
69226910
// Dig out the subject type and its corresponding component.
69236911
auto equivClass = subject.first;
@@ -7151,6 +7139,15 @@ static void collectRequirements(GenericSignatureBuilder &builder,
71517139

71527140
requirements.push_back(Requirement(kind, depTy, repTy));
71537141
});
7142+
7143+
// Sort the subject types in canonical order. This needs to be a stable sort
7144+
// so that the relative order of requirements that have the same subject type
7145+
// is preserved.
7146+
std::stable_sort(requirements.begin(), requirements.end(),
7147+
[](const Requirement &lhs, const Requirement &rhs) {
7148+
return compareDependentTypes(lhs.getFirstType(),
7149+
rhs.getFirstType()) < 0;
7150+
});
71547151
}
71557152

71567153
GenericSignature GenericSignatureBuilder::computeGenericSignature(

0 commit comments

Comments
 (0)