Skip to content

Commit a7d2b24

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 38c478f commit a7d2b24

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
@@ -5439,6 +5439,13 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
54395439
// of the ABI, and so we must take care to get the correct module
54405440
// name for the comparison.
54415441
auto getModuleNameForOrder = [&](const TypeDecl *decl) -> StringRef {
5442+
// Respect @_originallyDefinedIn on the type itself, so that
5443+
// moving a protocol across modules does not change its
5444+
// position in the order.
5445+
auto alternateName = decl->getAlternateModuleName();
5446+
if (!alternateName.empty())
5447+
return alternateName;
5448+
54425449
// This used to just call getName(), which caused accidental ABI breaks
54435450
// when a module is imported under different aliases.
54445451
//
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)