Skip to content

Commit 6b812e1

Browse files
authored
Merge pull request #6680 from apple/revert-6679-archetype-anchor-cleanup
2 parents dfebf20 + 7381347 commit 6b812e1

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/AST/ArchetypeBuilder.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -374,22 +374,13 @@ bool ArchetypeBuilder::PotentialArchetype::isBetterArchetypeAnchor(
374374
auto ArchetypeBuilder::PotentialArchetype::getArchetypeAnchor()
375375
-> PotentialArchetype * {
376376

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()) {
381380
if (pa->isBetterArchetypeAnchor(best))
382381
best = pa;
383382
}
384383

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-
393384
return best;
394385
}
395386

@@ -1058,10 +1049,18 @@ static int compareDependentTypes(ArchetypeBuilder::PotentialArchetype * const* p
10581049
if (int compareProtocols
10591050
= ProtocolType::compareProtocols(&protoa, &protob))
10601051
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;
10641060
}
1061+
1062+
// A resolved archetype is always ordered before an unresolved one.
1063+
return -1;
10651064
}
10661065

10671066
// A resolved archetype is always ordered before an unresolved one.

test/Generics/associated_type_typo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func typoAssoc4<T : P2>(_: T) where T.Assocp2.assoc : P3 {}
3939
// CHECK-GENERIC-LABEL: .typoAssoc4@
4040
// CHECK-GENERIC-NEXT: Requirements:
4141
// CHECK-GENERIC-NEXT: T : P2 [explicit
42-
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 : P1 [protocol
4342
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 == T[.P2].AssocP2 [redundant]
44-
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc : P3 [explicit
43+
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 : P1 [protocol
4544
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc == T[.P2].AssocP2[.P1].Assoc [redundant
45+
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc : P3 [explicit
4646
// CHECK-GENERIC-NEXT: Generic signature
4747

4848
// <rdar://problem/19620340>

0 commit comments

Comments
 (0)