Skip to content

Commit 5092b5e

Browse files
authored
Merge pull request #39241 from slavapestov/reduction-order-assoc-type-fix
RequirementMachine: Reduction order on symbols should compare associated type name before protocols
2 parents ff92d93 + 0309cfa commit 5092b5e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/AST/RequirementMachine/Symbol.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ int Symbol::compare(Symbol other, const ProtocolGraph &graph) const {
506506
auto protos = getProtocols();
507507
auto otherProtos = other.getProtocols();
508508

509+
if (getName() != other.getName())
510+
return getName().compare(other.getName());
511+
509512
// Symbols with more protocols are 'smaller' than those with fewer.
510513
if (protos.size() != otherProtos.size())
511514
return protos.size() > otherProtos.size() ? -1 : 1;
@@ -516,7 +519,6 @@ int Symbol::compare(Symbol other, const ProtocolGraph &graph) const {
516519
return result;
517520
}
518521

519-
result = getName().compare(other.getName());
520522
break;
521523
}
522524

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s
2+
3+
protocol P1 {
4+
associatedtype B
5+
}
6+
7+
protocol P2 {
8+
associatedtype A
9+
}
10+
11+
// Make sure that T.[P1:A] < T.[P2:B].
12+
13+
struct G<T : P1 & P2> where T.A == T.B {
14+
// CHECK-LABEL: sil hidden [ossa] @$s21associated_type_order1GV3fooyy1AAA2P2PQzF : $@convention(method) <T where T : P1, T : P2, T.A == T.B> (@in_guaranteed T.A, G<T>) -> () {
15+
func foo(_: T.A) {}
16+
}
17+

0 commit comments

Comments
 (0)