Skip to content

Revert "[Archetype builder] Never use the representative as the archetype anchor" #6680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/AST/ArchetypeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,13 @@ bool ArchetypeBuilder::PotentialArchetype::isBetterArchetypeAnchor(
auto ArchetypeBuilder::PotentialArchetype::getArchetypeAnchor()
-> PotentialArchetype * {

// Find the best archetype within this equivalence class.
PotentialArchetype *rep = getRepresentative();
auto best = rep;
for (auto pa : rep->getEquivalenceClass()) {
// Default to the representative, unless we find something better.
PotentialArchetype *best = getRepresentative();
for (auto pa : best->getEquivalenceClass()) {
if (pa->isBetterArchetypeAnchor(best))
best = pa;
}

#ifndef NDEBUG
// Make sure that we did, in fact, get one that is better than all others.
for (auto pa : rep->getEquivalenceClass()) {
assert(!pa->isBetterArchetypeAnchor(best) &&
"archetype anchor isn't a total order");
}
#endif

return best;
}

Expand Down Expand Up @@ -1058,10 +1049,18 @@ static int compareDependentTypes(ArchetypeBuilder::PotentialArchetype * const* p
if (int compareProtocols
= ProtocolType::compareProtocols(&protoa, &protob))
return compareProtocols;
} else {
// A resolved archetype is always ordered before an unresolved one.
return -1;

// - if one is the representative, put it first.
if ((a->getRepresentative() == a) !=
(b->getRepresentative() == b))
return a->getRepresentative() ? -1 : 1;

// FIXME: Would be nice if this was a total order.
return 0;
}

// A resolved archetype is always ordered before an unresolved one.
return -1;
}

// A resolved archetype is always ordered before an unresolved one.
Expand Down
4 changes: 2 additions & 2 deletions test/Generics/associated_type_typo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func typoAssoc4<T : P2>(_: T) where T.Assocp2.assoc : P3 {}
// CHECK-GENERIC-LABEL: .typoAssoc4@
// CHECK-GENERIC-NEXT: Requirements:
// CHECK-GENERIC-NEXT: T : P2 [explicit
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 : P1 [protocol
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 == T[.P2].AssocP2 [redundant]
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc : P3 [explicit
// CHECK-GENERIC-NEXT: T[.P2].AssocP2 : P1 [protocol
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc == T[.P2].AssocP2[.P1].Assoc [redundant
// CHECK-GENERIC-NEXT: T[.P2].AssocP2[.P1].Assoc : P3 [explicit
// CHECK-GENERIC-NEXT: Generic signature

// <rdar://problem/19620340>
Expand Down