Skip to content

Commit 5792a72

Browse files
committed
Always link SIL for partial modules in SILGen
Previously we would only link `.sib` partial modules in SILGen, with other kinds of serialized ASTs being linked just before the SILOptimizer if `-sil-merge-partial-modules` was specified. However linking them always seems to be the desired behaviour, so adjust SILGen to link SIL for all serialized AST inputs.
1 parent 890df57 commit 5792a72

File tree

6 files changed

+18
-43
lines changed

6 files changed

+18
-43
lines changed

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.

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/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
}

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,10 @@ int main(int argc, char **argv) {
275275
auto SILMod = performASTLowering(CI.getMainModule(), CI.getSILTypes(),
276276
CI.getSILOptions());
277277

278-
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
279-
// us.
278+
// Load in all the SIL if we're allowed to.
280279
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
281-
auto SL = SerializedSILLoader::create(
282-
CI.getASTContext(), SILMod.get(), nullptr);
283-
284-
if (DisableSILLinking)
285-
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
286-
else
287-
SL->getAll();
280+
if (!DisableSILLinking)
281+
SILMod->getSILLoader()->getAll();
288282
}
289283

290284
if (CommandLineFunctionNames.empty() && FunctionNameFile.empty())

tools/sil-opt/SILOpt.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,10 @@ int main(int argc, char **argv) {
464464
}
465465
SILMod->setSerializeSILAction([]{});
466466

467-
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
468-
// us.
467+
// Load in all the SIL if we're allowed to.
469468
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
470-
auto SL = SerializedSILLoader::create(
471-
CI.getASTContext(), SILMod.get(), nullptr);
472-
if (DisableSILLinking)
473-
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
474-
else
475-
SL->getAll();
469+
if (!DisableSILLinking)
470+
SILMod->getSILLoader()->getAll();
476471
}
477472

478473
if (!RemarksFilename.empty()) {

0 commit comments

Comments
 (0)