Skip to content

Commit b8bddb5

Browse files
committed
SILGen: Honor -experimental-skip-non-exportable-decls.
When the flag is specified, only emit SIL for declarations that are exposed to clients. Resolves rdar://116774565
1 parent a7daf13 commit b8bddb5

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ bool SILGenModule::shouldSkipDecl(Decl *D) {
801801
if (!D->isAvailableDuringLowering())
802802
return true;
803803

804+
if (getASTContext().SILOpts.SkipNonExportableDecls &&
805+
!D->isExposedToClients())
806+
return true;
807+
804808
return false;
805809
}
806810

@@ -1419,6 +1423,8 @@ void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
14191423
}
14201424

14211425
void SILGenModule::emitFunction(FuncDecl *fd) {
1426+
assert(!shouldSkipDecl(fd));
1427+
14221428
Types.setCaptureTypeExpansionContext(SILDeclRef(fd), M);
14231429

14241430
SILDeclRef::Loc decl = fd;

lib/SILGen/SILGenType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ SILGenModule::emitVTableMethod(ClassDecl *theClass, SILDeclRef derived,
4747
auto *baseDecl = cast<AbstractFunctionDecl>(base.getDecl());
4848
auto *derivedDecl = cast<AbstractFunctionDecl>(derived.getDecl());
4949

50+
if (shouldSkipDecl(baseDecl))
51+
return llvm::None;
52+
5053
// Note: We intentionally don't support extension members here.
5154
//
5255
// Once extensions can override or introduce new vtable entries, this will
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-SKIP
3+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test -experimental-skip-non-exportable-decls | %FileCheck %s --check-prefixes=CHECK,CHECK-SKIP
4+
5+
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test11privateFunc33_E3F0E1C7B46D05C8067CB98677DE566CLLyyF : $@convention(thin) () -> () {
6+
// CHECK-SKIP-NOT: s4Test11privateFunc33_E3F0E1C7B46D05C8067CB98677DE566CLLyyF
7+
private func privateFunc() {}
8+
9+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test12internalFuncyyF : $@convention(thin) () -> () {
10+
// CHECK-SKIP-NOT: s4Test12internalFuncyyF
11+
internal func internalFunc() {}
12+
13+
// CHECK: sil{{.*}} @$s4Test10publicFuncyyF : $@convention(thin) () -> () {
14+
public func publicFunc() {}
15+
16+
private class PrivateClass {
17+
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCfd : $@convention(method) (@guaranteed PrivateClass) -> @owned Builtin.NativeObject {
18+
// CHECK-SKIP-NOT: s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCfd
19+
20+
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCfD : $@convention(method) (@owned PrivateClass) -> () {
21+
// CHECK-SKIP-NOT: s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCfD
22+
23+
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCADycfC : $@convention(method) (@thick PrivateClass.Type) -> @owned PrivateClass {
24+
// CHECK-SKIP-NOT: s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCADycfC
25+
26+
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCADycfc : $@convention(method) (@owned PrivateClass) -> @owned PrivateClass {
27+
// CHECK-SKIP-NOT: s4Test12PrivateClass33_E3F0E1C7B46D05C8067CB98677DE566CLLCADycfc
28+
}
29+
30+
public class PublicClass {
31+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC14internalMethodyyF : $@convention(method) (@guaranteed PublicClass) -> () {
32+
// CHECK-SKIP-NOT: s4Test11PublicClassC14internalMethodyyF
33+
internal func internalMethod() {}
34+
35+
// CHECK: sil{{.*}} @$s4Test11PublicClassCfd : $@convention(method) (@guaranteed PublicClass) -> @owned Builtin.NativeObject {
36+
37+
// CHECK: sil{{.*}} @$s4Test11PublicClassCfD : $@convention(method) (@owned PublicClass) -> () {
38+
39+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassCACycfC : $@convention(method) (@thick PublicClass.Type) -> @owned PublicClass {
40+
// CHECK-SKIP-NOT: s4Test11PublicClassCACycfC
41+
42+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassCACycfc : $@convention(method) (@owned PublicClass) -> @owned PublicClass {
43+
// CHECK-SKIP-NOT: s4Test11PublicClassCACycfc
44+
}
45+
46+
extension PublicClass {
47+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC25internalMethodInExtensionyyF : $@convention(method) (@guaranteed PublicClass) -> () {
48+
// CHECK-SKIP-NOT: s4Test11PublicClassC25internalMethodInExtensionyyF
49+
internal func internalMethodInExtension() {}
50+
}
51+
52+
// CHECK-NO-SKIP-LABEL: sil_vtable PrivateClass {
53+
// CHECK-NO-SKIP-NEXT: #PrivateClass.init!allocator
54+
// CHECK-NO-SKIP-NEXT: #PrivateClass.deinit!deallocator
55+
// CHECK-NO-SKIP-NEXT: }
56+
// CHECK-SKIP-NOT: sil_vtable PrivateClass
57+
58+
// CHECK-LABEL: sil_vtable [serialized] PublicClass {
59+
// CHECK-NO-SKIP-NEXT: #PublicClass.internalMethod
60+
// CHECK-SKIP-NOT: #PublicClass.internalMethod
61+
// CHECK-NO-SKIP-NEXT: #PublicClass.init!allocator
62+
// CHECK-SKIP-NOT: #PublicClass.init!allocator
63+
// CHECK-NEXT: #PublicClass.deinit!deallocator
64+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)