@@ -374,13 +374,22 @@ bool ArchetypeBuilder::PotentialArchetype::isBetterArchetypeAnchor(
374
374
auto ArchetypeBuilder::PotentialArchetype::getArchetypeAnchor ()
375
375
-> PotentialArchetype * {
376
376
377
- // Default to the representative, unless we find something better.
378
- PotentialArchetype *best = getRepresentative ();
379
- for (auto pa : best->getEquivalenceClass ()) {
377
+ // Find the best archetype within this equivalence class.
378
+ PotentialArchetype *rep = getRepresentative ();
379
+ auto best = rep;
380
+ for (auto pa : rep->getEquivalenceClass ()) {
380
381
if (pa->isBetterArchetypeAnchor (best))
381
382
best = pa;
382
383
}
383
384
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
+
384
393
return best;
385
394
}
386
395
@@ -1049,18 +1058,10 @@ static int compareDependentTypes(ArchetypeBuilder::PotentialArchetype * const* p
1049
1058
if (int compareProtocols
1050
1059
= ProtocolType::compareProtocols (&protoa, &protob))
1051
1060
return compareProtocols;
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 ;
1061
+ } else {
1062
+ // A resolved archetype is always ordered before an unresolved one.
1063
+ return -1 ;
1060
1064
}
1061
-
1062
- // A resolved archetype is always ordered before an unresolved one.
1063
- return -1 ;
1064
1065
}
1065
1066
1066
1067
// A resolved archetype is always ordered before an unresolved one.
0 commit comments