Skip to content

Commit f3dda28

Browse files
authored
Merge pull request swiftlang#20404 from slavapestov/class-method-visibility-hack-resilience
SIL: Private methods of open resilient classes don't need to be public
2 parents cb37fea + de1ba80 commit f3dda28

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/SIL/SILDeclRef.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,8 @@ SubclassScope SILDeclRef::getSubclassScope() const {
912912
case AccessLevel::Public:
913913
return SubclassScope::Internal;
914914
case AccessLevel::Open:
915+
if (classType->isResilient())
916+
return SubclassScope::Internal;
915917
return SubclassScope::External;
916918
}
917919

test/IRGen/method_linkage.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-resilience | %FileCheck %s --check-prefix=RESILIENT
23

34
// Test if all methods which go into a vtable have at least the visibility of its class.
45
// Reason: Derived classes from "outside" still have to put the less visible base members
@@ -17,29 +18,34 @@
1718

1819
class Base {
1920
// CHECK: define hidden swiftcc void @"$s14method_linkage4Base{{.*}}3foo0
21+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage4Base{{.*}}3foo0
2022
@inline(never)
2123
fileprivate func foo() {
2224
}
2325

2426
// CHECK: define internal swiftcc void @"$s14method_linkage4Base{{.*}}3bar0
27+
// RESILIENT: define internal swiftcc void @"$s14method_linkage4Base{{.*}}3bar0
2528
@inline(never)
2629
fileprivate final func bar() {
2730
}
2831

2932
// CHECK: define hidden swiftcc void @"$s14method_linkage4Base{{.*}}5other0
33+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage4Base{{.*}}5other0
3034
@inline(never)
3135
fileprivate func other() {
3236
}
3337
}
3438
class Derived : Base {
3539
// CHECK: define internal swiftcc void @"$s14method_linkage7Derived{{.*}}3foo0
40+
// RESILIENT: define internal swiftcc void @"$s14method_linkage7Derived{{.*}}3foo0
3641
@inline(never)
3742
fileprivate final override func foo() {
3843
}
3944
}
4045

4146
extension Base {
4247
// CHECK: define internal swiftcc void @"$s14method_linkage4Base{{.*}}7extfunc0
48+
// RESILIENT: define internal swiftcc void @"$s14method_linkage4Base{{.*}}7extfunc0
4349
@inline(never)
4450
fileprivate func extfunc() {
4551
}
@@ -49,11 +55,13 @@ public class PublicClass {
4955
internal init() {}
5056

5157
// CHECK: define hidden swiftcc void @"$s14method_linkage11PublicClass{{.*}}4pfoo0
58+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage11PublicClass{{.*}}4pfoo0
5259
@inline(never)
5360
fileprivate func pfoo() {
5461
}
5562

5663
// CHECK: define hidden swiftcc void @"$s14method_linkage11PublicClassC4pbaryyF
64+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage11PublicClassC4pbaryyF
5765
@inline(never)
5866
internal func pbar() {
5967
}
@@ -63,11 +71,13 @@ open class OpenClass {
6371
internal init() {}
6472

6573
// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s14method_linkage9OpenClassC4pfoo0
74+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage9OpenClassC4pfoo0
6675
@inline(never)
6776
fileprivate func pfoo() {
6877
}
6978

7079
// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s14method_linkage9OpenClassC4pbaryyF
80+
// RESILIENT: define hidden swiftcc void @"$s14method_linkage9OpenClassC4pbaryyF
7181
@inline(never)
7282
internal func pbar() {
7383
}

test/IRGen/vtable_symbol_linkage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// RUN: %empty-directory(%t)
2+
23
// RUN: %target-build-swift %S/Inputs/vtable_symbol_linkage_base.swift -emit-module -emit-module-path=%t/BaseModule.swiftmodule -emit-library -module-name BaseModule -o %t/BaseModule.%target-dylib-extension
34
// RUN: %target-build-swift -I %t %s %t/BaseModule.%target-dylib-extension -o %t/a.out
45

6+
// RUN: %target-build-swift %S/Inputs/vtable_symbol_linkage_base.swift -emit-module -emit-module-path=%t/BaseModule.swiftmodule -emit-library -module-name BaseModule -o %t/BaseModule.%target-dylib-extension -Xfrontend -enable-resilience -Xfrontend -enable-class-resilience
7+
// RUN: %target-build-swift -I %t %s %t/BaseModule.%target-dylib-extension -o %t/a.out -Xfrontend -enable-class-resilience
8+
59
// Check if the program can be linked without undefined symbol errors.
610

711
import BaseModule

0 commit comments

Comments
 (0)