Skip to content

Stop using -sil-serialize-all when building the standard library #12191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ function(_compile_swift_files
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
if (NOT SWIFT_STDLIB_ENABLE_RESILIENCE)
if (SWIFT_STDLIB_SIL_SERIALIZE_ALL)
list(APPEND swift_flags "-Xfrontend" "-sil-serialize-all")
list(APPEND swift_flags "-Xfrontend" "-sil-serialize-witness-tables"
"-Xfrontend" "-sil-serialize-vtables")
endif()
endif()
endif()
Expand Down
6 changes: 6 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class SILOptions {
/// User code should never be compiled with this flag set.
bool SILSerializeWitnessTables = false;

/// If set, SIL vtables will be serialized.
///
/// It is supposed to be used only for compiling overlays.
/// User code should never be compiled with this flag set.
bool SILSerializeVTables = false;

SILOptions() {}

/// Return a hash code of any components from these options that should
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ def sil_serialize_all : Flag<["-"], "sil-serialize-all">,
def sil_serialize_witness_tables : Flag<["-"], "sil-serialize-witness-tables">,
HelpText<"Serialize eligible SIL witness tables">;

def sil_serialize_vtables : Flag<["-"], "sil-serialize-vtables">,
HelpText<"Serialize eligible SIL vtables">;

def sil_verify_all : Flag<["-"], "sil-verify-all">,
HelpText<"Verify SIL after each transform">;

Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.SILSerializeAll |= Args.hasArg(OPT_sil_serialize_all);
Opts.SILSerializeWitnessTables |=
Args.hasArg(OPT_sil_serialize_witness_tables);
Opts.SILSerializeVTables |=
Args.hasArg(OPT_sil_serialize_vtables);

// Parse the optimization level.
// Default to Onone settings if no option is passed.
Expand Down
1 change: 0 additions & 1 deletion lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class FunctionLivenessComputation {
// a pipeline, as it may break some optimizations.
if (F->isKeepAsPublic()) {
F->setLinkage(SILLinkage::Public);
F->setSerialized(IsSerialized);
DEBUG(llvm::dbgs() << "DFE: Preserve the specialization "
<< F->getName() << '\n');
return true;
Expand Down
5 changes: 3 additions & 2 deletions lib/SILOptimizer/IPO/UsePrespecialized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
if (SpecType->hasArchetype())
continue;

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

Expand Down
5 changes: 3 additions & 2 deletions lib/SILOptimizer/Utils/Generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,11 +2274,12 @@ void swift::trySpecializeApplyOfGeneric(
if (F->isSerialized() && RefF->isSerialized())
Serialized = IsSerializable;

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

ReabstractionInfo ReInfo(Apply, RefF, Apply.getSubstitutions());
if (!ReInfo.canBeSpecialized())
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
const DeclContext *assocDC = SILMod->getAssociatedContext();
assert(assocDC && "cannot serialize SIL without an associated DeclContext");
for (const SILVTable &vt : SILMod->getVTables()) {
if (ShouldSerializeAll &&
if ((ShouldSerializeAll || SILMod->getOptions().SILSerializeVTables) &&
vt.getClass()->isChildContextOf(assocDC))
writeSILVTable(vt);
}
Expand Down
7 changes: 6 additions & 1 deletion stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ add_custom_target(swift-test-stdlib ALL
if(SWIFT_STDLIB_ENABLE_RESILIENCE)
set(STDLIB_SIL_SERIALIZE_ALL)
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES)
set(STDLIB_SIL_SERIALIZE_VTABLES)
else()
if(SWIFT_STDLIB_SIL_SERIALIZE_ALL)
set(STDLIB_SIL_SERIALIZE_ALL "-Xfrontend" "-sil-serialize-all")
set(STDLIB_SIL_SERIALIZE_ALL)
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES "-Xfrontend" "-sil-serialize-witness-tables")
set(STDLIB_SIL_SERIALIZE_VTABLES "-Xfrontend" "-sil-serialize-vtables")
list(APPEND STDLIB_SIL_SERIALIZE_ALL ${STDLIB_SIL_SERIALIZE_WITNESS_TABLES}
${STDLIB_SIL_SERIALIZE_VTABLES})
else()
set(STDLIB_SIL_SERIALIZE_ALL)
set(STDLIB_SIL_SERIALIZE_WITNESS_TABLES)
set(STDLIB_SIL_SERIALIZE_VTABLES)
endif()
endif()

Expand Down
1 change: 1 addition & 0 deletions stdlib/public/SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if(SWIFT_BUILD_STATIC_SDK_OVERLAY)
endif()

list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "${STDLIB_SIL_SERIALIZE_WITNESS_TABLES}")
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "${STDLIB_SIL_SERIALIZE_VTABLES}")

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")

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/eager_specialize.sil
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ bb0(%0 : $*T):

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

////////////////////////////////////////////////////////////////////
// Check the ability to produce explicit partial specializations.
Expand Down
8 changes: 4 additions & 4 deletions test/SILOptimizer/prespecialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// CHECK-LABEL: sil [noinline] @_T013prespecialize4testySaySiGz_Si4sizetF
//
// function_ref specialized Collection<A where ...>.makeIterator() -> IndexingIterator<A>
// CHECK: function_ref @_T0s10CollectionPssAARzs16IndexingIteratorVyxG0C0RtzlE04makeC0AEyFs14CountableRangeVySiG_Tgq5
// CHECK: function_ref @_T0s10CollectionPssAARzs16IndexingIteratorVyxG0C0RtzlE04makeC0AEyFs14CountableRangeVySiG_Tg5
//
// function_ref specialized IndexingIterator.next() -> A.Element?
// CHECK: function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyFs14CountableRangeVySiG_Tgq5
// CHECK: function_ref @_T0s16IndexingIteratorV4next7ElementQzSgyFs14CountableRangeVySiG_Tg5
//
// Look for generic specialization <Swift.Int> of Swift.Array.subscript.getter : (Swift.Int) -> A
// CHECK: function_ref {{@_T0SaxSicigSi_Tgq5|@_TTSg5Si___TFSaap9subscriptFSix}}
// CHECK: function_ref {{@_T0SaxSicigSi_Tg5|@_TTSg5Si___TFSaap9subscriptFSix}}
// CHECK: return
@inline(never)
public func test(_ a: inout [Int], size: Int) {
Expand All @@ -30,7 +30,7 @@ public func test(_ a: inout [Int], size: Int) {

// CHECK-LABEL: sil [noinline] @_T013prespecialize3runyyF
// Look for generic specialization <Swift.Int> of Swift.Array.init (repeating : A, count : Swift.Int) -> Swift.Array<A>
// CHECK: function_ref @_T0S2ayxGx9repeating_Si5counttcfCSi_Tgq5
// CHECK: function_ref @_T0S2ayxGx9repeating_Si5counttcfCSi_Tg5
// CHECK: return
@inline(never)
public func run() {
Expand Down
3 changes: 3 additions & 0 deletions test/SILOptimizer/stack_promotion_array_literal.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %target-swift-frontend -parse-as-library -O -module-name=test %s -emit-sil | %FileCheck %s
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
// XFAIL: linux
// rdar://problem/34758773


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