Skip to content

Commit 27ed8b0

Browse files
committed
[SIL] Infer isWholeModule() from associated context
Rather than maintain a separate bit, check if the associated decl context is for the ModuleDecl.
1 parent 2d9b63e commit 27ed8b0

File tree

6 files changed

+13
-30
lines changed

6 files changed

+13
-30
lines changed

include/swift/AST/SILGenRequests.h

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ struct SILGenDescriptor {
8181
/// If the module or file contains SIL that needs parsing, returns the file
8282
/// to be parsed, or \c nullptr if parsing isn't required.
8383
SourceFile *getSourceFileToParse() const;
84-
85-
/// Whether the SIL is being emitted for a whole module.
86-
bool isWholeModule() const;
8784
};
8885

8986
void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);

include/swift/SIL/SILModule.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,6 @@ class SILModule {
262262
/// The indexed profile data to be used for PGO, or nullptr.
263263
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
264264

265-
/// True if this SILModule really contains the whole module, i.e.
266-
/// optimizations can assume that they see the whole module.
267-
bool wholeModule;
268-
269265
/// The options passed into this SILModule.
270266
const SILOptions &Options;
271267

@@ -281,8 +277,7 @@ class SILModule {
281277
llvm::SetVector<DeleteNotificationHandler*> NotificationHandlers;
282278

283279
SILModule(ModuleDecl *M, Lowering::TypeConverter &TC,
284-
const SILOptions &Options, const DeclContext *associatedDC,
285-
bool wholeModule);
280+
const SILOptions &Options, const DeclContext *associatedDC);
286281

287282
SILModule(const SILModule&) = delete;
288283
void operator=(const SILModule&) = delete;
@@ -357,8 +352,7 @@ class SILModule {
357352
/// later parse SIL bodies directly into, without converting from an AST.
358353
static std::unique_ptr<SILModule>
359354
createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC,
360-
const SILOptions &Options,
361-
bool WholeModule = false);
355+
const SILOptions &Options);
362356

363357
/// Get the Swift module associated with this SIL module.
364358
ModuleDecl *getSwiftModule() const { return TheSwiftModule; }
@@ -382,7 +376,7 @@ class SILModule {
382376
/// Returns true if this SILModule really contains the whole module, i.e.
383377
/// optimizations can assume that they see the whole module.
384378
bool isWholeModule() const {
385-
return wholeModule;
379+
return isa<ModuleDecl>(AssociatedDeclContext);
386380
}
387381

388382
bool isStdlibModule() const;

lib/SIL/IR/SILModule.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ class SILModule::SerializationCallback final
9393
};
9494

9595
SILModule::SILModule(ModuleDecl *SwiftModule, TypeConverter &TC,
96-
const SILOptions &Options, const DeclContext *associatedDC,
97-
bool wholeModule)
96+
const SILOptions &Options, const DeclContext *associatedDC)
9897
: TheSwiftModule(SwiftModule),
9998
AssociatedDeclContext(associatedDC),
100-
Stage(SILStage::Raw), wholeModule(wholeModule), Options(Options),
101-
serialized(false), SerializeSILAction(), Types(TC) {
99+
Stage(SILStage::Raw), Options(Options), serialized(false),
100+
SerializeSILAction(), Types(TC) {
102101
assert(AssociatedDeclContext);
103102

104103
// We always add the base SILModule serialization callback.
@@ -125,10 +124,9 @@ SILModule::~SILModule() {
125124
}
126125

127126
std::unique_ptr<SILModule>
128-
SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, const SILOptions &Options,
129-
bool WholeModule) {
130-
return std::unique_ptr<SILModule>(
131-
new SILModule(M, TC, Options, M, WholeModule));
127+
SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC,
128+
const SILOptions &Options) {
129+
return std::unique_ptr<SILModule>(new SILModule(M, TC, Options, M));
132130
}
133131

134132
ASTContext &SILModule::getASTContext() const {

lib/SIL/Parser/ParseSIL.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
116116
assert(bufferID);
117117

118118
auto *mod = SF->getParentModule();
119-
auto silMod = SILModule::createEmptyModule(mod, desc.conv, desc.opts,
120-
desc.isWholeModule());
119+
auto silMod = SILModule::createEmptyModule(mod, desc.conv, desc.opts);
121120
SILParserState parserState(silMod.get());
122121
Parser parser(*bufferID, *SF, parserState.Impl.get());
123122
PrettyStackTraceParser StackTrace(parser);
@@ -126,8 +125,7 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
126125
if (hadError) {
127126
// The rest of the SIL pipeline expects well-formed SIL, so if we encounter
128127
// a parsing error, just return an empty SIL module.
129-
return SILModule::createEmptyModule(mod, desc.conv, desc.opts,
130-
desc.isWholeModule());
128+
return SILModule::createEmptyModule(mod, desc.conv, desc.opts);
131129
}
132130
return silMod;
133131
}

lib/SILGen/SILGen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ SILGenSourceFileRequest::evaluate(Evaluator &evaluator,
18681868
auto *unit = desc.context.get<FileUnit *>();
18691869
auto *mod = unit->getParentModule();
18701870
auto M = std::unique_ptr<SILModule>(
1871-
new SILModule(mod, desc.conv, desc.opts, unit, /*wholeModule*/ false));
1871+
new SILModule(mod, desc.conv, desc.opts, unit));
18721872
SILGenModuleRAII scope(*M, mod);
18731873

18741874
if (auto *file = dyn_cast<SourceFile>(unit)) {
@@ -1891,7 +1891,7 @@ SILGenWholeModuleRequest::evaluate(Evaluator &evaluator,
18911891

18921892
auto *mod = desc.context.get<ModuleDecl *>();
18931893
auto M = std::unique_ptr<SILModule>(
1894-
new SILModule(mod, desc.conv, desc.opts, mod, /*wholeModule*/ true));
1894+
new SILModule(mod, desc.conv, desc.opts, mod));
18951895
SILGenModuleRAII scope(*M, mod);
18961896

18971897
for (auto file : mod->getFiles()) {

lib/SILGen/SILGenRequests.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ ArrayRef<FileUnit *> SILGenDescriptor::getFiles() const {
6565
return llvm::makeArrayRef(*context.getAddrOfPtr1());
6666
}
6767

68-
bool SILGenDescriptor::isWholeModule() const {
69-
return context.is<ModuleDecl *>();
70-
}
71-
7268
SourceFile *SILGenDescriptor::getSourceFileToParse() const {
7369
#ifndef NDEBUG
7470
auto sfCount = llvm::count_if(getFiles(), [](FileUnit *file) {

0 commit comments

Comments
 (0)