Skip to content

Commit 241c5d9

Browse files
authored
Merge pull request swiftlang#32461 from hamishknight/its-all-linked
2 parents 942893d + 751e681 commit 241c5d9

33 files changed

+47
-126
lines changed

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class SILOptions {
4040
/// Controls the aggressiveness of the loop unroller.
4141
int UnrollThreshold = 250;
4242

43-
/// Controls whether to pull in SIL from partial modules during the
44-
/// merge modules step. Could perhaps be merged with the link mode
45-
/// above but the interactions between all the flags are tricky.
46-
bool MergePartialModules = false;
47-
4843
/// Remove all runtime assertions during optimizations.
4944
bool RemoveRuntimeAsserts = false;
5045

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ def sil_unroll_threshold : Separate<["-"], "sil-unroll-threshold">,
554554
MetaVarName<"<250>">,
555555
HelpText<"Controls the aggressiveness of loop unrolling">;
556556

557+
// FIXME: This option is now redundant and should eventually be removed.
557558
def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
558-
HelpText<"Merge SIL from all partial swiftmodules into the final module">;
559+
Alias<merge_modules>;
559560

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

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,6 @@ class SILModule {
561561
/// i.e. it can be linked by linkFunction.
562562
bool hasFunction(StringRef Name);
563563

564-
/// Link all definitions in all segments that are logically part of
565-
/// the same AST module.
566-
void linkAllFromCurrentModule();
567-
568564
/// Look up the SILWitnessTable representing the lowering of a protocol
569565
/// conformance, and collect the substitutions to apply to the referenced
570566
/// witnesses, if any.

include/swift/Serialization/SerializedSILLoader.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class SerializedSILLoader {
7474

7575
bool invalidateFunction(SILFunction *F);
7676

77-
/// Deserialize all SILFunctions, VTables, and WitnessTables in all
78-
/// SILModules.
79-
void getAll();
80-
8177
/// Deserialize all SILFunctions, VTables, and WitnessTables for
8278
/// a given Module.
8379
///

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
10491049
if (FEOpts.RequestedAction == FrontendOptions::ActionType::EmitModuleOnly)
10501050
Opts.StopOptimizationAfterSerialization = true;
10511051

1052-
if (Args.hasArg(OPT_sil_merge_partial_modules))
1053-
Opts.MergePartialModules = true;
1054-
10551052
// Propagate the typechecker's understanding of
10561053
// -experimental-skip-non-inlinable-function-bodies to SIL.
10571054
Opts.SkipNonInlinableFunctionBodies = TCOpts.SkipNonInlinableFunctionBodies;

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -982,22 +982,17 @@ void CompilerInstance::freeASTContext() {
982982
/// Perform "stable" optimizations that are invariant across compiler versions.
983983
static bool performMandatorySILPasses(CompilerInvocation &Invocation,
984984
SILModule *SM) {
985+
// Don't run diagnostic passes at all when merging modules.
985986
if (Invocation.getFrontendOptions().RequestedAction ==
986987
FrontendOptions::ActionType::MergeModules) {
987-
// Don't run diagnostic passes at all.
988-
} else if (!Invocation.getDiagnosticOptions().SkipDiagnosticPasses) {
989-
if (runSILDiagnosticPasses(*SM))
990-
return true;
991-
} else {
988+
return false;
989+
}
990+
if (Invocation.getDiagnosticOptions().SkipDiagnosticPasses) {
992991
// Even if we are not supposed to run the diagnostic passes, we still need
993992
// to run the ownership evaluator.
994-
if (runSILOwnershipEliminatorPass(*SM))
995-
return true;
993+
return runSILOwnershipEliminatorPass(*SM);
996994
}
997-
998-
if (Invocation.getSILOptions().MergePartialModules)
999-
SM->linkAllFromCurrentModule();
1000-
return false;
995+
return runSILDiagnosticPasses(*SM);
1001996
}
1002997

1003998
/// Perform SIL optimization passes if optimizations haven't been disabled.

lib/SIL/IR/SILModule.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,6 @@ bool SILModule::hasFunction(StringRef Name) {
427427
return getSILLoader()->hasSILFunction(Name);
428428
}
429429

430-
void SILModule::linkAllFromCurrentModule() {
431-
getSILLoader()->getAllForModule(getSwiftModule()->getName(),
432-
/*PrimaryFile=*/nullptr);
433-
}
434-
435430
void SILModule::invalidateSILLoaderCaches() {
436431
getSILLoader()->invalidateCaches();
437432
}

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17511751
"[dynamically_replaceable] function");
17521752

17531753
// In canonical SIL, direct reference to a shared_external declaration
1754-
// is an error; we should have deserialized a body. In raw SIL, we may
1755-
// not have deserialized the body yet.
1754+
// is an error; we should have deserialized a body. In raw SIL, including
1755+
// the merge-modules phase, we may not have deserialized the body yet as we
1756+
// may not have run the SILLinker pass.
17561757
if (F.getModule().getStage() >= SILStage::Canonical) {
17571758
if (RefF->isExternalDeclaration()) {
17581759
require(SingleFunction ||
@@ -5560,20 +5561,13 @@ void SILModule::verify() const {
55605561
// Uniquing set to catch symbol name collisions.
55615562
llvm::DenseSet<StringRef> symbolNames;
55625563

5563-
// When merging partial modules, we only link functions from the current
5564-
// module, without enabling "LinkAll" mode or running the SILLinker pass;
5565-
// in this case, we need to relax some of the checks.
5566-
bool SingleFunction = false;
5567-
if (getOptions().MergePartialModules)
5568-
SingleFunction = true;
5569-
55705564
// Check all functions.
55715565
for (const SILFunction &f : *this) {
55725566
if (!symbolNames.insert(f.getName()).second) {
55735567
llvm::errs() << "Symbol redefined: " << f.getName() << "!\n";
55745568
assert(false && "triggering standard assertion failure routine");
55755569
}
5576-
f.verify(SingleFunction);
5570+
f.verify(/*singleFunction*/ false);
55775571
}
55785572

55795573
// Check all globals.

lib/SILGen/SILGen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,12 +1928,12 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
19281928
}
19291929

19301930
// Also make sure to process any intermediate files that may contain SIL.
1931-
bool hasSIB = llvm::any_of(desc.getFiles(), [](const FileUnit *File) -> bool {
1932-
auto *SASTF = dyn_cast<SerializedASTFile>(File);
1933-
return SASTF && SASTF->isSIB();
1934-
});
1935-
if (hasSIB) {
1936-
auto primary = desc.context.dyn_cast<FileUnit *>();
1931+
bool shouldDeserialize =
1932+
llvm::any_of(desc.getFiles(), [](const FileUnit *File) -> bool {
1933+
return isa<SerializedASTFile>(File);
1934+
});
1935+
if (shouldDeserialize) {
1936+
auto *primary = desc.context.dyn_cast<FileUnit *>();
19371937
silMod->getSILLoader()->getAllForModule(silMod->getSwiftModule()->getName(),
19381938
primary);
19391939
}

lib/Serialization/DeserializeSIL.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,13 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
597597

598598
fn->setSerialized(IsSerialized_t(isSerialized));
599599

600-
if (SILMod.getOptions().MergePartialModules)
600+
// If the serialized function comes from the same module, we're merging
601+
// modules, and can update the the linkage directly. This is needed to
602+
// correctly update the linkage for forward declarations to entities defined
603+
// in another file of the same module – we want to ensure the linkage
604+
// reflects the fact that the entity isn't really external and shouldn't be
605+
// dropped from the resulting merged module.
606+
if (getFile()->getParentModule() == SILMod.getSwiftModule())
601607
fn->setLinkage(linkage);
602608

603609
// Don't override the transparency or linkage of a function with

0 commit comments

Comments
 (0)