@@ -280,11 +280,13 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
280
280
Type FailureDiagnostic::restoreGenericParameters (
281
281
Type type,
282
282
llvm::function_ref<void (GenericTypeParamType *, Type)> substitution) {
283
+ llvm::SmallPtrSet<GenericTypeParamType *, 4 > processed;
283
284
return type.transform ([&](Type type) -> Type {
284
285
if (auto *typeVar = type->getAs <TypeVariableType>()) {
285
286
type = resolveType (typeVar);
286
287
if (auto *GP = typeVar->getImpl ().getGenericParameter ()) {
287
- substitution (GP, type);
288
+ if (processed.insert (GP).second )
289
+ substitution (GP, type);
288
290
return GP;
289
291
}
290
292
}
@@ -3524,22 +3526,30 @@ bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
3524
3526
return false ;
3525
3527
3526
3528
using Substitution = std::pair<GenericTypeParamType *, Type>;
3527
- llvm::DenseMap<GenericParamKey, Substitution > substitutions;
3529
+ llvm::SmallVector<Substitution, 8 > substitutions;
3528
3530
3529
3531
auto paramTy = restoreGenericParameters (
3530
3532
ParamType, [&](GenericTypeParamType *GP, Type resolvedType) {
3531
- substitutions[{GP}] = std::make_pair (GP, resolvedType);
3533
+ substitutions. push_back ( std::make_pair (GP, resolvedType) );
3532
3534
});
3533
3535
3534
3536
DeclBaseName name = choice->getBaseName ();
3535
3537
3536
3538
std::string subsStr;
3537
3539
if (!substitutions.empty ()) {
3540
+ llvm::array_pod_sort (
3541
+ substitutions.begin (), substitutions.end (),
3542
+ [](const std::pair<GenericTypeParamType *, Type> *lhs,
3543
+ const std::pair<GenericTypeParamType *, Type> *rhs) -> int {
3544
+ GenericParamKey key1 (lhs->first );
3545
+ GenericParamKey key2 (rhs->first );
3546
+ return key1 < key2 ? -1 : (key1 == key2) ? 0 : 1 ;
3547
+ });
3548
+
3538
3549
subsStr += " [with " ;
3539
3550
interleave (
3540
3551
substitutions,
3541
- [&subsStr](const std::pair<GenericParamKey, Substitution> &e) {
3542
- const auto &substitution = e.second ;
3552
+ [&subsStr](const Substitution &substitution) {
3543
3553
subsStr += substitution.first ->getString ();
3544
3554
subsStr += " = " ;
3545
3555
subsStr += substitution.second ->getString ();
0 commit comments