@@ -374,22 +374,13 @@ bool ArchetypeBuilder::PotentialArchetype::isBetterArchetypeAnchor(
374
374
auto ArchetypeBuilder::PotentialArchetype::getArchetypeAnchor ()
375
375
-> PotentialArchetype * {
376
376
377
- // Find the best archetype within this equivalence class.
378
- PotentialArchetype *rep = getRepresentative ();
379
- auto best = rep;
380
- for (auto pa : rep->getEquivalenceClass ()) {
377
+ // Default to the representative, unless we find something better.
378
+ PotentialArchetype *best = getRepresentative ();
379
+ for (auto pa : best->getEquivalenceClass ()) {
381
380
if (pa->isBetterArchetypeAnchor (best))
382
381
best = pa;
383
382
}
384
383
385
- #ifndef NDEBUG
386
- // Make sure that we did, in fact, get one that is better than all others.
387
- for (auto pa : rep->getEquivalenceClass ()) {
388
- assert (!pa->isBetterArchetypeAnchor (best) &&
389
- " archetype anchor isn't a total order" );
390
- }
391
- #endif
392
-
393
384
return best;
394
385
}
395
386
@@ -1058,10 +1049,18 @@ static int compareDependentTypes(ArchetypeBuilder::PotentialArchetype * const* p
1058
1049
if (int compareProtocols
1059
1050
= ProtocolType::compareProtocols (&protoa, &protob))
1060
1051
return compareProtocols;
1061
- } else {
1062
- // A resolved archetype is always ordered before an unresolved one.
1063
- return -1 ;
1052
+
1053
+ // - if one is the representative, put it first.
1054
+ if ((a->getRepresentative () == a) !=
1055
+ (b->getRepresentative () == b))
1056
+ return a->getRepresentative () ? -1 : 1 ;
1057
+
1058
+ // FIXME: Would be nice if this was a total order.
1059
+ return 0 ;
1064
1060
}
1061
+
1062
+ // A resolved archetype is always ordered before an unresolved one.
1063
+ return -1 ;
1065
1064
}
1066
1065
1067
1066
// A resolved archetype is always ordered before an unresolved one.
0 commit comments