Skip to content

Commit 70abfd3

Browse files
committed
[Frontend] Remove TheSILModule
Now that SIL parsing is handled lazily, the CompilerInstance no longer needs to hang onto a SILModule.
1 parent e249a71 commit 70abfd3

File tree

3 files changed

+13
-72
lines changed

3 files changed

+13
-72
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ class CompilerInstance {
425425
DiagnosticEngine Diagnostics{SourceMgr};
426426
std::unique_ptr<ASTContext> Context;
427427
std::unique_ptr<Lowering::TypeConverter> TheSILTypes;
428-
std::unique_ptr<SILModule> TheSILModule;
429428
std::unique_ptr<DiagnosticVerifier> DiagVerifier;
430429

431430
/// Null if no tracker.
@@ -498,8 +497,6 @@ class CompilerInstance {
498497

499498
Lowering::TypeConverter &getSILTypes();
500499

501-
void createSILModule();
502-
503500
void addDiagnosticConsumer(DiagnosticConsumer *DC) {
504501
Diagnostics.addConsumer(*DC);
505502
}
@@ -517,16 +514,6 @@ class CompilerInstance {
517514

518515
UnifiedStatsReporter *getStatsReporter() const { return Stats.get(); }
519516

520-
SILModule *getSILModule() {
521-
return TheSILModule.get();
522-
}
523-
524-
std::unique_ptr<SILModule> takeSILModule();
525-
526-
bool hasSILModule() {
527-
return static_cast<bool>(TheSILModule);
528-
}
529-
530517
ModuleDecl *getMainModule() const;
531518

532519
MemoryBufferSerializedModuleLoader *
@@ -659,9 +646,6 @@ class CompilerInstance {
659646
public:
660647
void freeASTContext();
661648

662-
/// Frees up the SILModule that this instance is holding on to.
663-
void freeSILModule();
664-
665649
private:
666650
/// Load stdlib & return true if should continue, i.e. no error
667651
bool loadStdlib();

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ Lowering::TypeConverter &CompilerInstance::getSILTypes() {
186186
return *tc;
187187
}
188188

189-
void CompilerInstance::createSILModule() {
190-
assert(MainModule && "main module not created yet");
191-
// Assume WMO if a -primary-file option was not provided.
192-
TheSILModule = SILModule::createEmptyModule(
193-
getMainModule(), getSILTypes(), Invocation.getSILOptions(),
194-
Invocation.getFrontendOptions().InputsAndOutputs.isWholeModule());
195-
}
196-
197189
void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
198190
PrimaryBufferIDs.insert(BufID);
199191
}
@@ -679,10 +671,6 @@ CompilerInstance::openModuleDoc(const InputFile &input) {
679671
return None;
680672
}
681673

682-
std::unique_ptr<SILModule> CompilerInstance::takeSILModule() {
683-
return std::move(TheSILModule);
684-
}
685-
686674
/// Implicitly import the SwiftOnoneSupport module in non-optimized
687675
/// builds. This allows for use of popular specialized functions
688676
/// from the standard library, which makes the non-optimized builds
@@ -760,14 +748,6 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
760748
ModuleDecl *mainModule = getMainModule();
761749
Context->LoadedModules[mainModule->getName()] = mainModule;
762750

763-
if (Invocation.getInputKind() == InputFileKind::SIL) {
764-
assert(!InputSourceCodeBufferIDs.empty());
765-
assert(InputSourceCodeBufferIDs.size() == 1);
766-
assert(MainBufferID != NO_SUCH_BUFFER);
767-
assert(isPrimaryInput(MainBufferID) || isWholeModuleCompilation());
768-
createSILModule();
769-
}
770-
771751
if (Invocation.getImplicitStdlibKind() == ImplicitStdlibKind::Stdlib) {
772752
if (!loadStdlib())
773753
return;
@@ -989,8 +969,6 @@ void CompilerInstance::freeASTContext() {
989969
PrimarySourceFiles.clear();
990970
}
991971

992-
void CompilerInstance::freeSILModule() { TheSILModule.reset(); }
993-
994972
/// Perform "stable" optimizations that are invariant across compiler versions.
995973
static bool performMandatorySILPasses(CompilerInvocation &Invocation,
996974
SILModule *SM) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,30 +1461,24 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
14611461
}
14621462
}
14631463

1464-
enum class DeallocatableResources {
1465-
None,
1466-
SILModule,
1467-
SILModuleAndASTContext,
1468-
};
1469-
static DeallocatableResources
1470-
computeDeallocatableResources(const CompilerInstance &Instance) {
1471-
// If the stats reporter is installed, we need the ASTContext and SILModule
1472-
// to live through the entire compilation process.
1464+
static void freeASTContextIfPossible(CompilerInstance &Instance) {
1465+
// If the stats reporter is installed, we need the ASTContext to live through
1466+
// the entire compilation process.
14731467
if (Instance.getASTContext().Stats) {
1474-
return DeallocatableResources::None;
1468+
return;
14751469
}
14761470

14771471
// If we're going to dump the API of the module, we cannot tear down
14781472
// the ASTContext, as that would cause the module to be freed prematurely.
14791473
const auto &opts = Instance.getInvocation().getFrontendOptions();
14801474
if (!opts.DumpAPIPath.empty()) {
1481-
return DeallocatableResources::SILModule;
1475+
return;
14821476
}
14831477

14841478
// Verifying incremental dependencies relies on access to the Swift Module's
1485-
// source files. We can still free the SIL module, though.
1479+
// source files.
14861480
if (opts.EnableIncrementalDependencyVerifier) {
1487-
return DeallocatableResources::SILModule;
1481+
return;
14881482
}
14891483

14901484
// If there are multiple primary inputs it is too soon to free
@@ -1493,29 +1487,14 @@ computeDeallocatableResources(const CompilerInstance &Instance) {
14931487
// unlikely to reduce the peak heap size. So, only optimize the
14941488
// single-primary-case (or WMO).
14951489
if (opts.InputsAndOutputs.hasMultiplePrimaryInputs()) {
1496-
return DeallocatableResources::SILModule;
1490+
return;
14971491
}
14981492

1499-
return DeallocatableResources::SILModuleAndASTContext;
1500-
}
1501-
1502-
static void freeDeallocatableResourcesIfPossible(CompilerInstance &Instance) {
1503-
switch (computeDeallocatableResources(Instance)) {
1504-
case DeallocatableResources::None:
1505-
break;
1506-
case DeallocatableResources::SILModule:
1507-
Instance.freeSILModule();
1508-
break;
1509-
case DeallocatableResources::SILModuleAndASTContext:
1510-
Instance.freeSILModule();
1511-
1512-
// Make sure we emit dependencies now, because we can't do it after the
1513-
// context is gone.
1514-
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1493+
// Make sure we emit dependencies now, because we can't do it after the
1494+
// context is gone.
1495+
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
15151496

1516-
Instance.freeASTContext();
1517-
break;
1518-
}
1497+
Instance.freeASTContext();
15191498
}
15201499

15211500
static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
@@ -1528,7 +1507,7 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
15281507
Instance.getASTContext().LangOpts.EffectiveLanguageVersion;
15291508

15301509
// Free up some compiler resources now that we have an IRModule.
1531-
freeDeallocatableResourcesIfPossible(Instance);
1510+
freeASTContextIfPossible(Instance);
15321511

15331512
// Now that we have a single IR Module, hand it over to performLLVM.
15341513
return performLLVM(opts, Instance.getDiags(), nullptr, HashGlobal, IRModule,

0 commit comments

Comments
 (0)