Skip to content

RequirementMachine: Reduction order on symbols should compare associated type name before protocols #39241

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
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
4 changes: 3 additions & 1 deletion lib/AST/RequirementMachine/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ int Symbol::compare(Symbol other, const ProtocolGraph &graph) const {
auto protos = getProtocols();
auto otherProtos = other.getProtocols();

if (getName() != other.getName())
return getName().compare(other.getName());

// Symbols with more protocols are 'smaller' than those with fewer.
if (protos.size() != otherProtos.size())
return protos.size() > otherProtos.size() ? -1 : 1;
Expand All @@ -516,7 +519,6 @@ int Symbol::compare(Symbol other, const ProtocolGraph &graph) const {
return result;
}

result = getName().compare(other.getName());
break;
}

Expand Down
17 changes: 17 additions & 0 deletions test/Generics/associated_type_order.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s

protocol P1 {
associatedtype B
}

protocol P2 {
associatedtype A
}

// Make sure that T.[P1:A] < T.[P2:B].

struct G<T : P1 & P2> where T.A == T.B {
// 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>) -> () {
func foo(_: T.A) {}
}