Skip to content

Commit 0a53c62

Browse files
authored
Merge pull request swiftlang#32529 from nkcsgexi/64538537
AST: isEquivalentToExtendedContext() should consider use patterns of @_originallyDefinedIn
2 parents f8f2e56 + e45fa71 commit 0a53c62

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,12 @@ bool ExtensionDecl::isConstrainedExtension() const {
12971297

12981298
bool ExtensionDecl::isEquivalentToExtendedContext() const {
12991299
auto decl = getExtendedNominal();
1300-
return getParentModule() == decl->getParentModule()
1300+
auto extendDeclfromSameModule =
1301+
getParentModule() == decl->getParentModule() ||
1302+
// if the extended type was defined in the same module with the extension,
1303+
// we should consider them as the same module to preserve ABI stability.
1304+
decl->getAlternateModuleName() == getParentModule()->getNameStr();
1305+
return extendDeclfromSameModule
13011306
&& !isConstrainedExtension()
13021307
&& !getDeclaredInterfaceType()->isExistentialType();
13031308
}

test/TBD/move_to_extension.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: %empty-directory(%t)
3+
4+
// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/before_move.tbd -D BEFORE_MOVE -module-name Foo -enable-library-evolution
5+
// RUN: %FileCheck %s < %t/before_move.tbd
6+
7+
// RUN: %target-swift-frontend %s -emit-module -emit-module-path %t/FooCore.swiftmodule -D AFTER_MOVE_FOO_CORE -module-name FooCore -enable-library-evolution
8+
// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/after_move.tbd -D AFTER_MOVE_FOO -module-name Foo -I %t -enable-library-evolution
9+
// RUN: %FileCheck %s < %t/after_move.tbd
10+
11+
// CHECK: '_$s3Foo4DateC14getCurrentYearSiyFZ'
12+
// CHECK: '_$s3Foo9DateValueV4yearACSi_tcfC'
13+
// CHECK: '_$s3Foo9DateValueV4yearSivg'
14+
// CHECK: '_$s3Foo9DateValueV4yearSivpMV'
15+
16+
#if BEFORE_MOVE
17+
18+
public class Date {
19+
public static func getCurrentYear() -> Int { return 2020 }
20+
}
21+
22+
public struct DateValue {
23+
public init(year: Int) {}
24+
public var year: Int { return 2020 }
25+
}
26+
27+
#endif
28+
29+
#if AFTER_MOVE_FOO_CORE
30+
31+
@available(OSX 10.7, *)
32+
@_originallyDefinedIn(module: "Foo", OSX 10.9)
33+
public class Date {}
34+
35+
@available(OSX 10.7, *)
36+
@_originallyDefinedIn(module: "Foo", OSX 10.9)
37+
public struct DateValue {}
38+
39+
#endif
40+
41+
#if AFTER_MOVE_FOO
42+
43+
@_exported import FooCore
44+
45+
public extension Date {
46+
public static func getCurrentYear() -> Int { return 2020 }
47+
}
48+
49+
public extension DateValue {
50+
public init(year: Int) {}
51+
public var year: Int { return 2020 }
52+
}
53+
54+
#endif

0 commit comments

Comments
 (0)