Skip to content

Commit 2dc2cd0

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 099c415 commit 2dc2cd0

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
@@ -5370,6 +5370,13 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
53705370
// of the ABI, and so we must take care to get the correct module
53715371
// name for the comparison.
53725372
auto getModuleNameForOrder = [&](const TypeDecl *decl) -> StringRef {
5373+
// Respect @_originallyDefinedIn on the type itself, so that
5374+
// moving a protocol across modules does not change its
5375+
// position in the order.
5376+
auto alternateName = decl->getAlternateModuleName();
5377+
if (!alternateName.empty())
5378+
return alternateName;
5379+
53735380
// This used to just call getName(), which caused accidental ABI breaks
53745381
// when a module is imported under different aliases.
53755382
//
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)