Skip to content

Commit 195c718

Browse files
authored
Merge pull request swiftlang#69798 from tshortli/silgen-skip-non-exportable-inits
SILGen: Skip emitting non-exportable initializer expressions
2 parents 353d04f + 29c04a7 commit 195c718

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,14 @@ void SILGenModule::emitDefaultArgGenerator(SILDeclRef constant,
16481648

16491649
void SILGenModule::
16501650
emitStoredPropertyInitialization(PatternBindingDecl *pbd, unsigned i) {
1651+
// The SIL emitted for property init expressions is only needed by clients of
1652+
// resilient modules if the property belongs to a frozen type. When
1653+
// -experimental-skip-non-exportable-decls is specified, skip emitting
1654+
// property inits if possible.
1655+
if (M.getOptions().SkipNonExportableDecls &&
1656+
!pbd->getAnchoringVarDecl(i)->isInitExposedToClients())
1657+
return;
1658+
16511659
auto *var = pbd->getAnchoringVarDecl(i);
16521660
SILDeclRef constant(var, SILDeclRef::Kind::StoredPropertyInitializer);
16531661
emitOrDelayFunction(constant);

lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ struct GenGlobalAccessors : public PatternVisitor<GenGlobalAccessors>
205205
/// Emit a global initialization.
206206
void SILGenModule::emitGlobalInitialization(PatternBindingDecl *pd,
207207
unsigned pbdEntry) {
208+
// The SIL emitted for global initialization is never needed clients of
209+
// resilient modules, so skip it if -experimental-skip-non-exportable-decls
210+
// is specified.
211+
if (M.getOptions().SkipNonExportableDecls)
212+
return;
213+
208214
// Generic and dynamic static properties require lazy initialization, which
209215
// isn't implemented yet.
210216
if (pd->isStatic()) {

test/SILGen/skip-non-exportable-decls.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
import Swift
66

7+
// CHECK-NO-SKIP: sil_global private @$s4Test17internalGlobalVar_Wz : $Builtin.Word
8+
// CHECK-SKIP-NOT: s4Test17internalGlobalVar_Wz
9+
10+
// CHECK-NO-SKIP: sil_global hidden @$s4Test17internalGlobalVarSivp : $Int
11+
// CHECK-SKIP-NOT: s4Test17internalGlobalVarSivp
12+
13+
// CHECK-NO-SKIP: sil_global private @$s4Test15publicGlobalVar_Wz : $Builtin.Word
14+
// CHECK-SKIP-NOT: s4Test15publicGlobalVar_Wz
15+
16+
// CHECK: sil_global @$s4Test15publicGlobalVarSivp : $Int
17+
718
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test11privateFunc33_E3F0E1C7B46D05C8067CB98677DE566CLLyyF : $@convention(thin) () -> () {
819
// CHECK-SKIP-NOT: s4Test11privateFunc33_E3F0E1C7B46D05C8067CB98677DE566CLLyyF
920
private func privateFunc() {}
@@ -36,6 +47,20 @@ public func publicFuncWithNestedFuncs() {
3647
// CHECK: sil [serialized]{{.*}} @$s4Test13inlinableFuncyyF : $@convention(thin) () -> () {
3748
@inlinable internal func inlinableFunc() {}
3849

50+
// CHECK-NO-SKIP: sil private [global_init_once_fn]{{.*}} @$s4Test17internalGlobalVar_WZ : $@convention(c) (Builtin.RawPointer) -> () {
51+
// CHECK-SKIP-NOT: s4Test17internalGlobalVar_WZ
52+
53+
// CHECK-NO-SKIP: sil hidden [global_init]{{.*}} @$s4Test17internalGlobalVarSivau : $@convention(thin) () -> Builtin.RawPointer {
54+
// CHECK-SKIP-NOT: s4Test17internalGlobalVarSivau
55+
internal var internalGlobalVar = 1
56+
57+
// CHECK-NO-SKIP: sil private [global_init_once_fn]{{.*}} @$s4Test15publicGlobalVar_WZ : $@convention(c) (Builtin.RawPointer) -> () {
58+
// CHECK-SKIP-NOT: s4Test15publicGlobalVar_WZ
59+
60+
// CHECK-NO-SKIP: sil [global_init]{{.*}} @$s4Test15publicGlobalVarSivau : $@convention(thin) () -> Builtin.RawPointer {
61+
// CHECK-SKIP-NOT: s4Test15publicGlobalVarSivau
62+
public var publicGlobalVar = 1
63+
3964
// CHECK: sil [serialized]{{.*}} @$s4Test023inlinableFuncWithNestedC0yyF : $@convention(thin) () -> () {
4065
@inlinable internal func inlinableFuncWithNestedFunc() {
4166
defer { publicFunc() }
@@ -60,6 +85,23 @@ private class PrivateClass {
6085
}
6186

6287
public class PublicClass {
88+
// CHECK-NO-SKIP: sil [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivpfi : $@convention(thin) () -> Int {
89+
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivpfi
90+
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
91+
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivg
92+
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
93+
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivs
94+
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
95+
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivM
96+
var internalVar = 1
97+
98+
// CHECK-NO-SKIP: sil [transparent]{{.*}} @$s4Test11PublicClassC9publicVarSivpfi : $@convention(thin) () -> Int {
99+
// CHECK-SKIP-NOT: s4Test11PublicClassC9publicVarSivpfi
100+
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
101+
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
102+
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
103+
public var publicVar = 1
104+
63105
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC14internalMethodyyF : $@convention(method) (@guaranteed PublicClass) -> () {
64106
// CHECK-SKIP-NOT: s4Test11PublicClassC14internalMethodyyF
65107
internal func internalMethod() {}
@@ -81,16 +123,32 @@ extension PublicClass {
81123
internal func internalMethodInExtension() {}
82124
}
83125

126+
@frozen public struct FrozenPublicStruct {
127+
// CHECK: sil non_abi [transparent] [serialized]{{.*}} @$s4Test18FrozenPublicStructV11internalVarSivpfi : $@convention(thin) () -> Int {
128+
var internalVar = 1
129+
}
130+
84131
// CHECK-NO-SKIP-LABEL: sil_vtable PrivateClass {
85132
// CHECK-NO-SKIP-NEXT: #PrivateClass.init!allocator
86133
// CHECK-NO-SKIP-NEXT: #PrivateClass.deinit!deallocator
87134
// CHECK-NO-SKIP-NEXT: }
88135
// CHECK-SKIP-NOT: sil_vtable PrivateClass
89136

90137
// CHECK-LABEL: sil_vtable [serialized] PublicClass {
138+
// CHECK-NO-SKIP-NEXT: #PublicClass.internalVar!getter
139+
// CHECK-SKIP-NOT: #PublicClass.internalVar!getter
140+
// CHECK-NO-SKIP-NEXT: #PublicClass.internalVar!setter
141+
// CHECK-SKIP-NOT: #PublicClass.internalVar!setter
142+
// CHECK-NO-SKIP-NEXT: #PublicClass.internalVar!modify
143+
// CHECK-SKIP-NOT: #PublicClass.internalVar!modify
144+
// CHECK-NEXT: #PublicClass.publicVar!getter
145+
// CHECK-NEXT: #PublicClass.publicVar!setter
146+
// CHECK-NEXT: #PublicClass.publicVar!modify
91147
// CHECK-NO-SKIP-NEXT: #PublicClass.internalMethod
92148
// CHECK-SKIP-NOT: #PublicClass.internalMethod
93149
// CHECK-NO-SKIP-NEXT: #PublicClass.init!allocator
94150
// CHECK-SKIP-NOT: #PublicClass.init!allocator
95151
// CHECK-NEXT: #PublicClass.deinit!deallocator
96152
// CHECK-NEXT: }
153+
154+
// CHECK: sil_property #PublicClass.publicVar ()

0 commit comments

Comments
 (0)