Skip to content

Commit 111499d

Browse files
authored
Merge pull request #12256 from swiftix/sil-serialize-all-improvments
Remove the -sil-serialize-all option
2 parents 64f5b45 + 154e6c0 commit 111499d

File tree

110 files changed

+359
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+359
-503
lines changed

docs/HighLevelSILOptimizations.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,13 @@ Cloning code from the standard library
117117
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118118

119119
The Swift compiler can copy code from the standard library into the
120-
application. This allows the optimizer to inline calls from stdlib and improve
121-
the performance of code that uses common operators such as '++' or basic
122-
containers such as Array. However, importing code from the standard library can
123-
increase the binary size. Marking functions with @_semantics("stdlib_binary_only")
124-
will prevent the copying of the marked function from the standard library into the
125-
user program.
126-
127-
Notice that this annotation is similar to the resilient annotation that will
128-
disallow the cloning of code into the user application.
120+
application for functions marked @_inlineable. This allows the optimizer to
121+
inline calls from the stdlib and improve the performance of code that uses
122+
common operators such as '+=' or basic containers such as Array. However,
123+
importing code from the standard library can increase the binary size.
124+
125+
To prevent copying of functions from the standard library into the user
126+
program, make sure the function in question is not marked @_inlineable.
129127

130128
Array
131129
~~~~~

docs/Lexicon.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,6 @@ source code, tests, and commit messages. See also the `LLVM lexicon`_.
344344
"Swift Intermediate Language". A high-level IR used by the Swift compiler
345345
for flow-sensitive diagnostics, optimization, and LLVM IR generation.
346346

347-
-sil-serialize-all
348-
A mode where all functions in a library are made available for inlining by
349-
any client, regardless of access control. Also called "magic performance
350-
mode" as a reminder of how this drastically changes compilation. Not
351-
guaranteed to work on arbitrary code.
352-
353347
SR
354348
An issue reported on `bugs.swift.org <https://bugs.swift.org>`_. A
355349
backronym for "Swift Report"; really the name is derived from LLVM's

include/swift/AST/Module.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ enum class ResilienceStrategy : unsigned {
112112
/// Non-inlineable function bodies: resilient
113113
///
114114
/// This is the behavior with -enable-resilience.
115-
Resilient,
116-
117-
/// Public nominal types: fragile
118-
/// Non-inlineable function bodies: fragile
119-
///
120-
/// This is the behavior with -sil-serialize-all.
121-
Fragile
115+
Resilient
122116
};
123117

124118
/// The minimum unit of compilation.

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ class SILOptions {
150150
/// \brief Enable large loadable types IRGen pass.
151151
bool EnableLargeLoadableTypes = true;
152152

153-
/// Enables the "fully fragile" resilience strategy.
154-
///
155-
/// \see ResilienceStrategy::Fragile
156-
bool SILSerializeAll = false;
157-
158153
/// If set, SIL witness tables will be serialized.
159154
///
160155
/// It is supposed to be used only for compiling overlays.

include/swift/IRGen/Linking.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,6 @@ class LinkEntity {
567567
///
568568
bool isAvailableExternally(IRGenModule &IGM) const;
569569

570-
/// Returns true if this function or global variable may be inlined into
571-
/// another module.
572-
///
573-
bool isFragile(ForDefinition_t isDefinition) const;
574-
575570
const ValueDecl *getDecl() const {
576571
assert(isDeclKind(getKind()));
577572
return reinterpret_cast<ValueDecl*>(Pointer);
@@ -686,7 +681,6 @@ class LinkInfo {
686681
static LinkInfo get(const UniversalLinkageInfo &linkInfo,
687682
StringRef name,
688683
SILLinkage linkage,
689-
bool isFragile,
690684
bool isSILOnly,
691685
ForDefinition_t isDefinition,
692686
bool isWeakImported);

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
372372
def sil_link_all : Flag<["-"], "sil-link-all">,
373373
HelpText<"Link all SIL functions">;
374374

375-
def sil_serialize_all : Flag<["-"], "sil-serialize-all">,
376-
HelpText<"Serialize all generated SIL">;
377-
378375
def sil_serialize_witness_tables : Flag<["-"], "sil-serialize-witness-tables">,
379376
HelpText<"Serialize eligible SIL witness tables">;
380377

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,6 @@ class SILModule {
322322
return wholeModule;
323323
}
324324

325-
/// Returns true if everything in this SILModule is being serialized.
326-
bool isWholeModuleSerialized() const { return Options.SILSerializeAll; }
327-
328325
/// Returns true if it is the OnoneSupport module.
329326
bool isOnoneSupportModule() const;
330327

lib/AST/Decl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,6 @@ bool AbstractStorageDecl::hasFixedLayout() const {
14591459
switch (getDeclContext()->getParentModule()->getResilienceStrategy()) {
14601460
case ResilienceStrategy::Resilient:
14611461
return false;
1462-
case ResilienceStrategy::Fragile:
14631462
case ResilienceStrategy::Default:
14641463
return true;
14651464
}
@@ -2217,7 +2216,6 @@ bool NominalTypeDecl::hasFixedLayout() const {
22172216
switch (getParentModule()->getResilienceStrategy()) {
22182217
case ResilienceStrategy::Resilient:
22192218
return false;
2220-
case ResilienceStrategy::Fragile:
22212219
case ResilienceStrategy::Default:
22222220
return true;
22232221
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
13731373
if (Args.hasArg(OPT_sil_merge_partial_modules))
13741374
Opts.MergePartialModules = true;
13751375

1376-
Opts.SILSerializeAll |= Args.hasArg(OPT_sil_serialize_all);
13771376
Opts.SILSerializeWitnessTables |=
13781377
Args.hasArg(OPT_sil_serialize_witness_tables);
13791378
Opts.SILSerializeVTables |=

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ ModuleDecl *CompilerInstance::getMainModule() {
258258

259259
if (Invocation.getFrontendOptions().EnableResilience)
260260
MainModule->setResilienceStrategy(ResilienceStrategy::Resilient);
261-
else if (Invocation.getSILOptions().SILSerializeAll)
262-
MainModule->setResilienceStrategy(ResilienceStrategy::Fragile);
263261
}
264262
return MainModule;
265263
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,6 @@ static bool performCompile(CompilerInstance &Instance,
925925
serializationOpts.OutputPath = opts.ModuleOutputPath.c_str();
926926
serializationOpts.DocOutputPath = opts.ModuleDocOutputPath.c_str();
927927
serializationOpts.GroupInfoPath = opts.GroupInfoPath.c_str();
928-
serializationOpts.SerializeAllSIL =
929-
Invocation.getSILOptions().SILSerializeAll;
930928
if (opts.SerializeBridgingHeader)
931929
serializationOpts.ImportedHeader = opts.ImplicitObjCHeaderPath;
932930
serializationOpts.ModuleLinkName = opts.ModuleLinkName;

lib/IRGen/GenDecl.cpp

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,44 +1314,11 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const {
13141314
llvm_unreachable("bad link entity kind");
13151315
}
13161316

1317-
bool LinkEntity::isFragile(ForDefinition_t isDefinition) const {
1318-
switch (getKind()) {
1319-
case Kind::SILFunction:
1320-
return getSILFunction()->isSerialized();
1321-
1322-
case Kind::SILGlobalVariable:
1323-
return getSILGlobalVariable()->isSerialized();
1324-
1325-
case Kind::ReflectionAssociatedTypeDescriptor:
1326-
case Kind::ReflectionSuperclassDescriptor:
1327-
case Kind::AssociatedTypeMetadataAccessFunction:
1328-
case Kind::AssociatedTypeWitnessTableAccessFunction:
1329-
case Kind::GenericProtocolWitnessTableCache:
1330-
case Kind::GenericProtocolWitnessTableInstantiationFunction:
1331-
case Kind::ObjCClassRef:
1332-
return false;
1333-
1334-
default:
1335-
break;
1336-
}
1337-
if (isProtocolConformanceKind(getKind())) {
1338-
auto conformance = getProtocolConformance();
1339-
1340-
auto conformanceModule = conformance->getDeclContext()->getParentModule();
1341-
auto isCompletelySerialized = conformanceModule->getResilienceStrategy() ==
1342-
ResilienceStrategy::Fragile;
1343-
1344-
// The conformance is fragile if it is in a -sil-serialize-all module.
1345-
return isCompletelySerialized;
1346-
}
1347-
return false;
1348-
}
1349-
13501317
static std::tuple<llvm::GlobalValue::LinkageTypes,
13511318
llvm::GlobalValue::VisibilityTypes,
13521319
llvm::GlobalValue::DLLStorageClassTypes>
13531320
getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
1354-
bool isFragile, bool isSILOnly, ForDefinition_t isDefinition,
1321+
bool isSILOnly, ForDefinition_t isDefinition,
13551322
bool isWeakImported) {
13561323
#define RESULT(LINKAGE, VISIBILITY, DLL_STORAGE) \
13571324
std::make_tuple(llvm::GlobalValue::LINKAGE##Linkage, \
@@ -1372,29 +1339,6 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
13721339
info.UseDLLStorage ? llvm::GlobalValue::DLLImportStorageClass
13731340
: llvm::GlobalValue::DefaultStorageClass;
13741341

1375-
if (isFragile) {
1376-
// Fragile functions/globals must be visible from outside, regardless of
1377-
// their access level. If a caller is also fragile and inlined into another
1378-
// module it must be able to access this (not-inlined) function/global.
1379-
switch (linkage) {
1380-
case SILLinkage::Hidden:
1381-
case SILLinkage::Private:
1382-
linkage = SILLinkage::Public;
1383-
break;
1384-
1385-
case SILLinkage::HiddenExternal:
1386-
case SILLinkage::PrivateExternal:
1387-
linkage = SILLinkage::PublicExternal;
1388-
break;
1389-
1390-
case SILLinkage::Public:
1391-
case SILLinkage::Shared:
1392-
case SILLinkage::PublicExternal:
1393-
case SILLinkage::SharedExternal:
1394-
break;
1395-
}
1396-
}
1397-
13981342
switch (linkage) {
13991343
case SILLinkage::Public:
14001344
// Don't code-gen transparent functions. Internal linkage will enable llvm
@@ -1453,8 +1397,7 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
14531397
return std::make_tuple(isDefinition
14541398
? llvm::GlobalValue::AvailableExternallyLinkage
14551399
: llvm::GlobalValue::ExternalLinkage,
1456-
isFragile ? llvm::GlobalValue::DefaultVisibility
1457-
: llvm::GlobalValue::HiddenVisibility,
1400+
llvm::GlobalValue::HiddenVisibility,
14581401
ImportedStorage);
14591402

14601403
}
@@ -1472,7 +1415,7 @@ static void updateLinkageForDefinition(IRGenModule &IGM,
14721415
UniversalLinkageInfo linkInfo(IGM);
14731416
auto linkage =
14741417
getIRLinkage(linkInfo, entity.getLinkage(ForDefinition),
1475-
entity.isFragile(ForDefinition), entity.isSILOnly(),
1418+
entity.isSILOnly(),
14761419
ForDefinition, entity.isWeakImported(IGM.getSwiftModule()));
14771420
global->setLinkage(std::get<0>(linkage));
14781421
global->setVisibility(std::get<1>(linkage));
@@ -1504,7 +1447,7 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
15041447

15051448
std::tie(result.Linkage, result.Visibility, result.DLLStorageClass) =
15061449
getIRLinkage(linkInfo, entity.getLinkage(isDefinition),
1507-
entity.isFragile(isDefinition), entity.isSILOnly(),
1450+
entity.isSILOnly(),
15081451
isDefinition, entity.isWeakImported(swiftModule));
15091452

15101453
result.ForDefinition = isDefinition;
@@ -1515,20 +1458,19 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
15151458
LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
15161459
StringRef name,
15171460
SILLinkage linkage,
1518-
bool isFragile,
15191461
bool isSILOnly,
15201462
ForDefinition_t isDefinition,
15211463
bool isWeakImported) {
15221464
LinkInfo result;
1523-
1465+
15241466
result.Name += name;
15251467
std::tie(result.Linkage, result.Visibility, result.DLLStorageClass) =
1526-
getIRLinkage(linkInfo, linkage, isFragile, isSILOnly,
1468+
getIRLinkage(linkInfo, linkage, isSILOnly,
15271469
isDefinition, isWeakImported);
15281470
result.ForDefinition = isDefinition;
15291471
return result;
15301472
}
1531-
1473+
15321474
static bool isPointerTo(llvm::Type *ptrTy, llvm::Type *objTy) {
15331475
return cast<llvm::PointerType>(ptrTy)->getElementType() == objTy;
15341476
}

lib/IRGen/GenKeyPath.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
330330

331331
auto linkInfo = LinkInfo::get(IGM, "swift_keyPathGenericWitnessTable",
332332
SILLinkage::PublicExternal,
333-
/*fragile*/ false,
334333
/*sil only*/ false,
335334
NotForDefinition,
336335
/*weak imported*/ false);

lib/SIL/Linker.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,6 @@ using namespace Lowering;
2626

2727
STATISTIC(NumFuncLinked, "Number of SIL functions linked");
2828

29-
//===----------------------------------------------------------------------===//
30-
// Utility
31-
//===----------------------------------------------------------------------===//
32-
33-
/// \return True if the function \p F should be imported into the current
34-
/// module.
35-
static bool shouldImportFunction(SILFunction *F) {
36-
// Skip functions that are marked with the 'no import' tag. These
37-
// are functions that we don't want to copy from the module.
38-
if (F->hasSemanticsAttr("stdlib_binary_only")) {
39-
// If we are importing a function declaration mark it as external since we
40-
// are not importing the body.
41-
if (F->isExternalDeclaration())
42-
F->setLinkage(SILLinkage::PublicExternal);
43-
return false;
44-
}
45-
46-
return true;
47-
}
48-
4929
//===----------------------------------------------------------------------===//
5030
// Linker Helpers
5131
//===----------------------------------------------------------------------===//
@@ -55,9 +35,6 @@ bool SILLinkerVisitor::processFunction(SILFunction *F) {
5535
if (Mode == LinkingMode::LinkNone)
5636
return false;
5737

58-
if (!shouldImportFunction(F))
59-
return false;
60-
6138
// If F is a declaration, first deserialize it.
6239
if (F->isExternalDeclaration()) {
6340
auto *NewFn = Loader->lookupSILFunction(F);
@@ -334,9 +311,6 @@ bool SILLinkerVisitor::process() {
334311
while (!Worklist.empty()) {
335312
auto *Fn = Worklist.pop_back_val();
336313

337-
if (!shouldImportFunction(Fn))
338-
continue;
339-
340314
DEBUG(llvm::dbgs() << "Process imports in function: "
341315
<< Fn->getName() << "\n");
342316

@@ -346,9 +320,6 @@ bool SILLinkerVisitor::process() {
346320
if (visit(&I)) {
347321
for (auto *F : FunctionDeserializationWorklist) {
348322

349-
if (!shouldImportFunction(F))
350-
continue;
351-
352323
DEBUG(llvm::dbgs() << "Imported function: "
353324
<< F->getName() << "\n");
354325
F->setBare(IsBare);

lib/SIL/SIL.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ FormalLinkage swift::getDeclLinkage(const ValueDecl *D) {
5454
case AccessLevel::Open:
5555
return FormalLinkage::PublicUnique;
5656
case AccessLevel::Internal:
57-
// If we're serializing all function bodies, type metadata for internal
58-
// types needs to be public too.
59-
if (D->getDeclContext()->getParentModule()->getResilienceStrategy()
60-
== ResilienceStrategy::Fragile)
61-
return FormalLinkage::PublicUnique;
6257
return FormalLinkage::HiddenUnique;
6358
case AccessLevel::FilePrivate:
6459
case AccessLevel::Private:

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ SILFunction *SILGenModule::getEmittedFunction(SILDeclRef constant,
461461
if (isAvailableExternally(F->getLinkage())) {
462462
F->setLinkage(constant.getLinkage(ForDefinition));
463463
}
464-
if (isMakeModuleFragile()) {
465-
F->setSerialized(IsSerialized);
466-
}
467464
}
468465
return F;
469466
}
@@ -523,13 +520,6 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
523520

524521
assert(F && "SILFunction should have been defined");
525522

526-
if (isMakeModuleFragile()) {
527-
SILLinkage linkage = constant.getLinkage(forDefinition);
528-
if (linkage != SILLinkage::PublicExternal) {
529-
F->setSerialized(IsSerialized);
530-
}
531-
}
532-
533523
emittedFunctions[constant] = F;
534524

535525
// If we delayed emitting this function previously, we need it now.
@@ -994,9 +984,7 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
994984
M.createFunction(SILLinkage::Private,
995985
funcName, initSILType, nullptr,
996986
SILLocation(binding), IsNotBare, IsNotTransparent,
997-
isMakeModuleFragile()
998-
? IsSerialized
999-
: IsNotSerialized);
987+
IsNotSerialized);
1000988
f->setDebugScope(new (M) SILDebugScope(RegularLocation(binding), f));
1001989
SILGenFunction(*this, *f).emitLazyGlobalInitializer(binding, pbdEntry);
1002990
f->verify();

0 commit comments

Comments
 (0)