Skip to content

Commit 5c97d9c

Browse files
committed
AST: Also respect @_originallyDefinedIn in TypeDecl::compare()
If a protocol was moved from one module to another, we need to continue using the old module name when comparing it against other protocols.
1 parent d0ee8ad commit 5c97d9c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/AST/Decl.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -5353,6 +5353,13 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
53535353
// of the ABI, and so we must take care to get the correct module
53545354
// name for the comparison.
53555355
auto getModuleNameForOrder = [&](const TypeDecl *decl) -> StringRef {
5356+
// Respect @_originallyDefinedIn on the type itself, so that
5357+
// moving a protocol across modules does not change its
5358+
// position in the order.
5359+
auto alternateName = decl->getAlternateModuleName();
5360+
if (!alternateName.empty())
5361+
return alternateName;
5362+
53565363
// This used to just call getName(), which caused accidental ABI breaks
53575364
// when a module is imported under different aliases.
53585365
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-emit-silgen %s -module-name main | %FileCheck %s
2+
3+
// REQUIRES: OS=macosx
4+
5+
@_originallyDefinedIn(module: "AnimalKit", macOS 10.10)
6+
@available(macOS 10.9, *)
7+
public protocol Ungulate {}
8+
9+
@_originallyDefinedIn(module: "HorseKit", macOS 10.10)
10+
@available(macOS 10.9, *)
11+
public protocol Horse {}
12+
13+
// CHECK-LABEL: sil [ossa] @$s4main39requirementOrderWithOriginallyDefinedInyyx9AnimalKit8UngulateRz05HorseI00K0RzlF : $@convention(thin) <T where T : Ungulate, T : Horse> (@in_guaranteed T) -> () {
14+
public func requirementOrderWithOriginallyDefinedIn<T: Ungulate & Horse>(_: T) {}

0 commit comments

Comments
 (0)