Skip to content

Commit 0918780

Browse files
authored
Merge pull request #12191 from swiftix/sil-serialize-all-improvments
Stop using -sil-serialize-all when building the standard library
2 parents 13d4149 + a136d59 commit 0918780

File tree

13 files changed

+35
-13
lines changed

13 files changed

+35
-13
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ function(_compile_swift_files
256256
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
257257
if (NOT SWIFT_STDLIB_ENABLE_RESILIENCE)
258258
if (SWIFT_STDLIB_SIL_SERIALIZE_ALL)
259-
list(APPEND swift_flags "-Xfrontend" "-sil-serialize-all")
259+
list(APPEND swift_flags "-Xfrontend" "-sil-serialize-witness-tables"
260+
"-Xfrontend" "-sil-serialize-vtables")
260261
endif()
261262
endif()
262263
endif()

include/swift/AST/SILOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ class SILOptions {
161161
/// User code should never be compiled with this flag set.
162162
bool SILSerializeWitnessTables = false;
163163

164+
/// If set, SIL vtables will be serialized.
165+
///
166+
/// It is supposed to be used only for compiling overlays.
167+
/// User code should never be compiled with this flag set.
168+
bool SILSerializeVTables = false;
169+
164170
SILOptions() {}
165171

166172
/// Return a hash code of any components from these options that should

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ def sil_serialize_all : Flag<["-"], "sil-serialize-all">,
378378
def sil_serialize_witness_tables : Flag<["-"], "sil-serialize-witness-tables">,
379379
HelpText<"Serialize eligible SIL witness tables">;
380380

381+
def sil_serialize_vtables : Flag<["-"], "sil-serialize-vtables">,
382+
HelpText<"Serialize eligible SIL vtables">;
383+
381384
def sil_verify_all : Flag<["-"], "sil-verify-all">,
382385
HelpText<"Verify SIL after each transform">;
383386

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
13761376
Opts.SILSerializeAll |= Args.hasArg(OPT_sil_serialize_all);
13771377
Opts.SILSerializeWitnessTables |=
13781378
Args.hasArg(OPT_sil_serialize_witness_tables);
1379+
Opts.SILSerializeVTables |=
1380+
Args.hasArg(OPT_sil_serialize_vtables);
13791381

13801382
// Parse the optimization level.
13811383
// Default to Onone settings if no option is passed.

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class FunctionLivenessComputation {
113113
// a pipeline, as it may break some optimizations.
114114
if (F->isKeepAsPublic()) {
115115
F->setLinkage(SILLinkage::Public);
116-
F->setSerialized(IsSerialized);
117116
DEBUG(llvm::dbgs() << "DFE: Preserve the specialization "
118117
<< F->getName() << '\n');
119118
return true;

lib/SILOptimizer/IPO/UsePrespecialized.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
9999
if (SpecType->hasArchetype())
100100
continue;
101101

102-
// Create a name of the specialization.
102+
// Create a name of the specialization. All external pre-specializations
103+
// are serialized without bodies. Thus use IsNotSerialized here.
103104
Mangle::GenericSpecializationMangler NewGenericMangler(ReferencedF,
104-
Subs, ReferencedF->isSerialized(),
105+
Subs, IsNotSerialized,
105106
/*isReAbstracted*/ true);
106107
std::string ClonedName = NewGenericMangler.mangle();
107108

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,11 +2274,12 @@ void swift::trySpecializeApplyOfGeneric(
22742274
if (F->isSerialized() && RefF->isSerialized())
22752275
Serialized = IsSerializable;
22762276

2277-
// If it is OnoneSupport consider all specializations as serialized.
2277+
// If it is OnoneSupport consider all specializations as non-serialized
2278+
// as we do not SIL serialize their bodies.
22782279
// It is important to set this flag here, because it affects the
22792280
// mangling of the specialization's name.
22802281
if (Apply.getModule().isOptimizedOnoneSupportModule())
2281-
Serialized = IsSerialized;
2282+
Serialized = IsNotSerialized;
22822283

22832284
ReabstractionInfo ReInfo(Apply, RefF, Apply.getSubstitutions());
22842285
if (!ReInfo.canBeSpecialized())

lib/Serialization/SerializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
22622262
const DeclContext *assocDC = SILMod->getAssociatedContext();
22632263
assert(assocDC && "cannot serialize SIL without an associated DeclContext");
22642264
for (const SILVTable &vt : SILMod->getVTables()) {
2265-
if (ShouldSerializeAll &&
2265+
if ((ShouldSerializeAll || SILMod->getOptions().SILSerializeVTables) &&
22662266
vt.getClass()->isChildContextOf(assocDC))
22672267
writeSILVTable(vt);
22682268
}

stdlib/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,18 @@ add_custom_target(swift-test-stdlib ALL
9494
if(SWIFT_STDLIB_ENABLE_RESILIENCE)
9595
set(STDLIB_SIL_SERIALIZE_ALL)
9696
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES)
97+
set(STDLIB_SIL_SERIALIZE_VTABLES)
9798
else()
9899
if(SWIFT_STDLIB_SIL_SERIALIZE_ALL)
99-
set(STDLIB_SIL_SERIALIZE_ALL "-Xfrontend" "-sil-serialize-all")
100+
set(STDLIB_SIL_SERIALIZE_ALL)
100101
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES "-Xfrontend" "-sil-serialize-witness-tables")
102+
set(STDLIB_SIL_SERIALIZE_VTABLES "-Xfrontend" "-sil-serialize-vtables")
103+
list(APPEND STDLIB_SIL_SERIALIZE_ALL ${STDLIB_SIL_SERIALIZE_WITNESS_TABLES}
104+
${STDLIB_SIL_SERIALIZE_VTABLES})
101105
else()
102106
set(STDLIB_SIL_SERIALIZE_ALL)
103107
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES)
108+
set(STDLIB_SIL_SERIALIZE_VTABLES)
104109
endif()
105110
endif()
106111

stdlib/public/SDK/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if(SWIFT_BUILD_STATIC_SDK_OVERLAY)
99
endif()
1010

1111
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "${STDLIB_SIL_SERIALIZE_WITNESS_TABLES}")
12+
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "${STDLIB_SIL_SERIALIZE_VTABLES}")
1213

1314
set(all_overlays "Accelerate;AppKit;ARKit;AssetsLibrary;AVFoundation;CallKit;CloudKit;Contacts;CoreAudio;CoreData;CoreFoundation;CoreGraphics;CoreImage;CoreLocation;CoreMedia;CryptoTokenKit;Dispatch;Foundation;GameplayKit;GLKit;HomeKit;IOKit;Intents;MapKit;MediaPlayer;Metal;MetalKit;ModelIO;ObjectiveC;OpenCL;os;Photos;QuartzCore;SafariServices;SceneKit;simd;SpriteKit;UIKit;Vision;WatchKit;XCTest;XPC")
1415

test/SILOptimizer/eager_specialize.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ bb0(%0 : $*T):
581581

582582
// Check that a public specialization for Int64 was produced.
583583
// specialized exportSpecializations<A> (A) -> ()
584-
// CHECK-DEADFUNCELIM-LABEL: sil [serialized] @_T016eager_specialize21exportSpecializationsyxlFs5Int64V_Tg5 : $@convention(thin) (Int64) -> ()
584+
// CHECK-DEADFUNCELIM-LABEL: sil @_T016eager_specialize21exportSpecializationsyxlFs5Int64V_Tg5 : $@convention(thin) (Int64) -> ()
585585

586586
////////////////////////////////////////////////////////////////////
587587
// Check the ability to produce explicit partial specializations.

test/SILOptimizer/prespecialize.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// CHECK-LABEL: sil [noinline] @_T013prespecialize4testySaySiGz_Si4sizetF
1212
//
1313
// function_ref specialized Collection<A where ...>.makeIterator() -> IndexingIterator<A>
14-
// CHECK: function_ref @_T0s10CollectionPssAARzs16IndexingIteratorVyxG0C0RtzlE04makeC0AEyFs14CountableRangeVySiG_Tgq5
14+
// CHECK: function_ref @_T0s10CollectionPssAARzs16IndexingIteratorVyxG0C0RtzlE04makeC0AEyFs14CountableRangeVySiG_Tg5
1515
//
1616
// function_ref specialized IndexingIterator.next() -> A.Element?
17-
// CHECK: function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyFs14CountableRangeVySiG_Tgq5
17+
// CHECK: function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyFs14CountableRangeVySiG_Tg5
1818
//
1919
// Look for generic specialization <Swift.Int> of Swift.Array.subscript.getter : (Swift.Int) -> A
20-
// CHECK: function_ref {{@_T0SaxSicigSi_Tgq5|@_TTSg5Si___TFSaap9subscriptFSix}}
20+
// CHECK: function_ref {{@_T0SaxSicigSi_Tg5|@_TTSg5Si___TFSaap9subscriptFSix}}
2121
// CHECK: return
2222
@inline(never)
2323
public func test(_ a: inout [Int], size: Int) {
@@ -30,7 +30,7 @@ public func test(_ a: inout [Int], size: Int) {
3030

3131
// CHECK-LABEL: sil [noinline] @_T013prespecialize3runyyF
3232
// Look for generic specialization <Swift.Int> of Swift.Array.init (repeating : A, count : Swift.Int) -> Swift.Array<A>
33-
// CHECK: function_ref @_T0S2ayxGx9repeating_Si5counttcfCSi_Tgq5
33+
// CHECK: function_ref @_T0S2ayxGx9repeating_Si5counttcfCSi_Tg5
3434
// CHECK: return
3535
@inline(never)
3636
public func run() {

test/SILOptimizer/stack_promotion_array_literal.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %target-swift-frontend -parse-as-library -O -module-name=test %s -emit-sil | %FileCheck %s
22
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
3+
// XFAIL: linux
4+
// rdar://problem/34758773
5+
36

47
// This is an end-to-end test to check if the array literal in the loop is
58
// stack promoted.

0 commit comments

Comments
 (0)