Skip to content

Commit 665eb51

Browse files
authored
Merge pull request #32667 from nkcsgexi/comments-on-64538537-5.3
AST: address code review comments on isEquivalentToExtendedContext()
2 parents 3e8166e + 50142f8 commit 665eb51

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,16 @@ bool ExtensionDecl::isConstrainedExtension() const {
12971297

12981298
bool ExtensionDecl::isEquivalentToExtendedContext() const {
12991299
auto decl = getExtendedNominal();
1300-
auto extendDeclfromSameModule =
1301-
getParentModule() == decl->getParentModule() ||
1300+
bool extendDeclFromSameModule = false;
1301+
if (!decl->getAlternateModuleName().empty()) {
13021302
// if the extended type was defined in the same module with the extension,
13031303
// we should consider them as the same module to preserve ABI stability.
1304-
decl->getAlternateModuleName() == getParentModule()->getNameStr();
1305-
return extendDeclfromSameModule
1304+
extendDeclFromSameModule = decl->getAlternateModuleName() ==
1305+
getParentModule()->getNameStr();
1306+
} else {
1307+
extendDeclFromSameModule = decl->getParentModule() == getParentModule();
1308+
}
1309+
return extendDeclFromSameModule
13061310
&& !isConstrainedExtension()
13071311
&& !getDeclaredInterfaceType()->isExistentialType();
13081312
}

test/TBD/move_to_extension.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
// REQUIRES: OS=macosx
22
// RUN: %empty-directory(%t)
33

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
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
55
// RUN: %FileCheck %s < %t/before_move.tbd
6+
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/before_move.sil
67

78
// 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: %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
910
// RUN: %FileCheck %s < %t/after_move.tbd
11+
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/after_move.sil
1012

1113
// CHECK: '_$s3Foo4DateC14getCurrentYearSiyFZ'
1214
// CHECK: '_$s3Foo9DateValueV4yearACSi_tcfC'
1315
// CHECK: '_$s3Foo9DateValueV4yearSivg'
14-
// CHECK: '_$s3Foo9DateValueV4yearSivpMV'
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
1520

1621
#if BEFORE_MOVE
1722

23+
@available(OSX 10.7, *)
1824
public class Date {
1925
public static func getCurrentYear() -> Int { return 2020 }
2026
}
2127

28+
@available(OSX 10.7, *)
2229
public struct DateValue {
2330
public init(year: Int) {}
2431
public var year: Int { return 2020 }
@@ -47,7 +54,7 @@ public extension Date {
4754
}
4855

4956
public extension DateValue {
50-
public init(year: Int) {}
57+
public init(year: Int) { self.init(year: 2020) }
5158
public var year: Int { return 2020 }
5259
}
5360

0 commit comments

Comments
 (0)