mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
This commit is contained in:
@@ -6888,14 +6888,6 @@ namespace {
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
static int compareSameTypeComponents(const SameTypeComponentRef *lhsPtr,
|
||||
const SameTypeComponentRef *rhsPtr){
|
||||
Type lhsType = lhsPtr->first->derivedSameTypeComponents[lhsPtr->second].type;
|
||||
Type rhsType = rhsPtr->first->derivedSameTypeComponents[rhsPtr->second].type;
|
||||
|
||||
return compareDependentTypes(lhsType, rhsType);
|
||||
}
|
||||
|
||||
void GenericSignatureBuilder::enumerateRequirements(
|
||||
TypeArrayView<GenericTypeParamType> genericParams,
|
||||
llvm::function_ref<
|
||||
@@ -6914,10 +6906,6 @@ void GenericSignatureBuilder::enumerateRequirements(
|
||||
subjects.push_back({&equivClass, i});
|
||||
}
|
||||
|
||||
// Sort the subject types in canonical order.
|
||||
llvm::array_pod_sort(subjects.begin(), subjects.end(),
|
||||
compareSameTypeComponents);
|
||||
|
||||
for (const auto &subject : subjects) {
|
||||
// Dig out the subject type and its corresponding component.
|
||||
auto equivClass = subject.first;
|
||||
@@ -7151,6 +7139,15 @@ static void collectRequirements(GenericSignatureBuilder &builder,
|
||||
|
||||
requirements.push_back(Requirement(kind, depTy, repTy));
|
||||
});
|
||||
|
||||
// Sort the subject types in canonical order. This needs to be a stable sort
|
||||
// so that the relative order of requirements that have the same subject type
|
||||
// is preserved.
|
||||
std::stable_sort(requirements.begin(), requirements.end(),
|
||||
[](const Requirement &lhs, const Requirement &rhs) {
|
||||
return compareDependentTypes(lhs.getFirstType(),
|
||||
rhs.getFirstType()) < 0;
|
||||
});
|
||||
}
|
||||
|
||||
GenericSignature GenericSignatureBuilder::computeGenericSignature(
|
||||
|
||||
Reference in New Issue
Block a user