Skip to content

Commit c8193e3

Browse files
committed
SILGen: Skip emitting non-exportable global inits.
When -experimental-skip-non-exportable-decls is specified, the SIL for the initializers and unsafe mutable addressors of global variables is unneeded and should be skipped.
1 parent 353d04f commit c8193e3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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: 25 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() }

0 commit comments

Comments
 (0)