Skip to content

Commit 01e3b7b

Browse files
authored
Merge pull request #21498 from DougGregor/revert-reasonable-gsb-change-5.0
[5.0] Revert "[GSB] When adding same-type requirements pick representative based on canonical order
2 parents c86283e + 05aeed6 commit 01e3b7b

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,8 +4801,12 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
48014801
auto T1 = OrigT1->getRepresentative();
48024802
auto T2 = OrigT2->getRepresentative();
48034803

4804-
// Pick representative based on the canonical ordering of the type parameters.
4805-
if (compareDependentTypes(depType2, depType1) < 0) {
4804+
// Decide which potential archetype is to be considered the representative.
4805+
// We prefer potential archetypes with lower nesting depths, because it
4806+
// prevents us from unnecessarily building deeply nested potential archetypes.
4807+
unsigned nestingDepth1 = T1->getNestingDepth();
4808+
unsigned nestingDepth2 = T2->getNestingDepth();
4809+
if (nestingDepth2 < nestingDepth1) {
48064810
std::swap(T1, T2);
48074811
std::swap(OrigT1, OrigT2);
48084812
std::swap(equivClass, equivClass2);

test/Generics/rdar45957015.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/Generics/same_type_constraints.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ func intercomponentSameComponents<T: P10>(_: T)
353353
func intercomponentMoreThanSpanningTree<T: P10>(_: T)
354354
where T.A == T.B,
355355
T.B == T.C,
356-
T.D == T.E, // expected-note {{previous same-type constraint 'T.D' == 'T.E' written here}}
356+
T.D == T.E, // expected-note{{previous same-type constraint 'T.D' == 'T.E' written here}}
357357
T.D == T.B,
358-
T.E == T.B // expected-warning {{redundant same-type constraint 'T.E' == 'T.B'}}
358+
T.E == T.B // expected-warning{{redundant same-type constraint 'T.E' == 'T.B'}}
359359
{ }
360360

361361
func trivialRedundancy<T: P10>(_: T) where T.A == T.A { } // expected-warning{{redundant same-type constraint 'T.A' == 'T.A'}}

test/decl/protocol/req/associated_type_ambiguity.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol P1 {
1515
}
1616

1717
protocol P2 {
18-
associatedtype T // expected-note 2 {{found this candidate}}
18+
associatedtype T // expected-note {{found this candidate}}
1919
}
2020

2121
// FIXME: This extension's generic signature is still minimized differently from
@@ -36,7 +36,7 @@ extension P1 where Self : P2 {
3636
// Same as above, but now we have two visible associated types with the same
3737
// name.
3838
protocol P3 {
39-
associatedtype T // expected-note {{found this candidate}}
39+
associatedtype T
4040
}
4141

4242
// FIXME: This extension's generic signature is still minimized differently from
@@ -48,7 +48,7 @@ extension P2 where Self : P3, T == Int {
4848
}
4949

5050
extension P2 where Self : P3 {
51-
func takeT1(_: T) {} // expected-error {{'T' is ambiguous for type lookup in this context}}
51+
func takeT1(_: T) {}
5252
func takeT2(_: Self.T) {}
5353
}
5454

0 commit comments

Comments
 (0)