Skip to content

Commit 29c04a7

Browse files
committed
SILGen: Skip emitting non-exportable stored property inits.
When -experimental-skip-non-exportable-decls is specified, the SIL for the initializers of stored properties is unneeded and should be skipped so long as the property does not belong to a `@frozen` type.
1 parent c8193e3 commit 29c04a7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ private class PrivateClass {
8585
}
8686

8787
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+
88105
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC14internalMethodyyF : $@convention(method) (@guaranteed PublicClass) -> () {
89106
// CHECK-SKIP-NOT: s4Test11PublicClassC14internalMethodyyF
90107
internal func internalMethod() {}
@@ -106,16 +123,32 @@ extension PublicClass {
106123
internal func internalMethodInExtension() {}
107124
}
108125

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

115137
// 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
116147
// CHECK-NO-SKIP-NEXT: #PublicClass.internalMethod
117148
// CHECK-SKIP-NOT: #PublicClass.internalMethod
118149
// CHECK-NO-SKIP-NEXT: #PublicClass.init!allocator
119150
// CHECK-SKIP-NOT: #PublicClass.init!allocator
120151
// CHECK-NEXT: #PublicClass.deinit!deallocator
121152
// CHECK-NEXT: }
153+
154+
// CHECK: sil_property #PublicClass.publicVar ()

0 commit comments

Comments
 (0)