Skip to content

Commit 71595d1

Browse files
authored
Merge pull request swiftlang#32665 from nkcsgexi/64538537-5.3
[5.3] AST: isEquivalentToExtendedContext() should consider use patterns of @_originallyDefinedIn
2 parents 1da6bec + 1d473da commit 71595d1

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,16 @@ bool ExtensionDecl::isConstrainedExtension() const {
13251325

13261326
bool ExtensionDecl::isEquivalentToExtendedContext() const {
13271327
auto decl = getExtendedNominal();
1328-
return getParentModule() == decl->getParentModule()
1328+
bool extendDeclFromSameModule = false;
1329+
if (!decl->getAlternateModuleName().empty()) {
1330+
// if the extended type was defined in the same module with the extension,
1331+
// we should consider them as the same module to preserve ABI stability.
1332+
extendDeclFromSameModule = decl->getAlternateModuleName() ==
1333+
getParentModule()->getNameStr();
1334+
} else {
1335+
extendDeclFromSameModule = decl->getParentModule() == getParentModule();
1336+
}
1337+
return extendDeclFromSameModule
13291338
&& !isConstrainedExtension()
13301339
&& !getDeclaredInterfaceType()->isExistentialType();
13311340
}

test/TBD/move_to_extension.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 -emit-sil -o %t/before_move.sil
5+
// RUN: %FileCheck %s < %t/before_move.tbd
6+
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/before_move.sil
7+
8+
// RUN: %target-swift-frontend %s -emit-module -emit-module-path %t/FooCore.swiftmodule -D AFTER_MOVE_FOO_CORE -module-name FooCore -enable-library-evolution
9+
// 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 -emit-sil -o %t/after_move.sil
10+
// RUN: %FileCheck %s < %t/after_move.tbd
11+
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/after_move.sil
12+
13+
// CHECK: '_$s3Foo4DateC14getCurrentYearSiyFZ'
14+
// CHECK: '_$s3Foo9DateValueV4yearACSi_tcfC'
15+
// CHECK: '_$s3Foo9DateValueV4yearSivg'
16+
17+
// CHECK-SIL: sil [available 10.7] @$s3Foo4DateC14getCurrentYearSiyFZ : $@convention(method) (@thick Date.Type) -> Int
18+
// CHECK-SIL: sil [available 10.7] @$s3Foo9DateValueV4yearACSi_tcfC : $@convention(method) (Int, @thin DateValue.Type) -> @out DateValue
19+
// CHECK-SIL: sil [available 10.7] @$s3Foo9DateValueV4yearSivg : $@convention(method) (@in_guaranteed DateValue) -> Int
20+
21+
#if BEFORE_MOVE
22+
23+
@available(OSX 10.7, *)
24+
public class Date {
25+
public static func getCurrentYear() -> Int { return 2020 }
26+
}
27+
28+
@available(OSX 10.7, *)
29+
public struct DateValue {
30+
public init(year: Int) {}
31+
public var year: Int { return 2020 }
32+
}
33+
34+
#endif
35+
36+
#if AFTER_MOVE_FOO_CORE
37+
38+
@available(OSX 10.7, *)
39+
@_originallyDefinedIn(module: "Foo", OSX 10.9)
40+
public class Date {}
41+
42+
@available(OSX 10.7, *)
43+
@_originallyDefinedIn(module: "Foo", OSX 10.9)
44+
public struct DateValue {}
45+
46+
#endif
47+
48+
#if AFTER_MOVE_FOO
49+
50+
@_exported import FooCore
51+
52+
public extension Date {
53+
public static func getCurrentYear() -> Int { return 2020 }
54+
}
55+
56+
public extension DateValue {
57+
public init(year: Int) { self.init(year: 2020) }
58+
public var year: Int { return 2020 }
59+
}
60+
61+
#endif

0 commit comments

Comments
 (0)