Skip to content

Commit fe7444f

Browse files
committed
Add doesActionRequireSwiftStandardLibrary
1 parent 4c7ccf5 commit fe7444f

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,13 @@ class FrontendOptions {
294294
/// '.../lib/swift', otherwise '.../lib/swift_static'.
295295
bool UseSharedResourceFolder = true;
296296

297-
/// \return true if action only parses without doing other compilation steps.
297+
/// \return true if the given action only parses without doing other compilation steps.
298298
static bool shouldActionOnlyParse(ActionType);
299299

300+
/// \return true if the given action requires the standard library to be
301+
/// loaded before it is run.
302+
static bool doesActionRequireSwiftStandardLibrary(ActionType);
303+
300304
/// Return a hash code of any components from these options that should
301305
/// contribute to a Swift Bridging PCH hash.
302306
llvm::hash_code getPCHHashComponents() const {

lib/Frontend/FrontendOptions.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,63 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {
7373

7474
bool FrontendOptions::shouldActionOnlyParse(ActionType action) {
7575
switch (action) {
76-
case FrontendOptions::ActionType::Parse:
77-
case FrontendOptions::ActionType::DumpParse:
78-
case FrontendOptions::ActionType::EmitSyntax:
79-
case FrontendOptions::ActionType::DumpInterfaceHash:
80-
case FrontendOptions::ActionType::EmitImportedModules:
81-
case FrontendOptions::ActionType::ScanDependencies:
82-
case FrontendOptions::ActionType::ScanClangDependencies:
83-
case FrontendOptions::ActionType::PrintVersion:
76+
case ActionType::Parse:
77+
case ActionType::DumpParse:
78+
case ActionType::EmitSyntax:
79+
case ActionType::DumpInterfaceHash:
80+
case ActionType::EmitImportedModules:
81+
case ActionType::ScanDependencies:
82+
case ActionType::ScanClangDependencies:
83+
case ActionType::PrintVersion:
8484
return true;
8585
default:
8686
return false;
8787
}
8888
}
8989

90+
bool FrontendOptions::doesActionRequireSwiftStandardLibrary(ActionType action) {
91+
switch (action) {
92+
case ActionType::NoneAction:
93+
case ActionType::Parse:
94+
case ActionType::DumpParse:
95+
case ActionType::EmitSyntax:
96+
case ActionType::DumpInterfaceHash:
97+
case ActionType::EmitImportedModules:
98+
case ActionType::ScanDependencies:
99+
case ActionType::ScanClangDependencies:
100+
case ActionType::PrintVersion:
101+
case ActionType::EmitPCH:
102+
case ActionType::EmitPCM:
103+
case ActionType::DumpPCM:
104+
case ActionType::CompileModuleFromInterface:
105+
case ActionType::TypecheckModuleFromInterface:
106+
return false;
107+
case ActionType::ResolveImports:
108+
case ActionType::Typecheck:
109+
case ActionType::DumpAST:
110+
case ActionType::PrintAST:
111+
case ActionType::DumpScopeMaps:
112+
case ActionType::DumpTypeRefinementContexts:
113+
case ActionType::EmitSILGen:
114+
case ActionType::EmitSIL:
115+
case ActionType::EmitModuleOnly:
116+
case ActionType::MergeModules:
117+
case ActionType::EmitSIBGen:
118+
case ActionType::EmitSIB:
119+
case ActionType::Immediate:
120+
case ActionType::REPL:
121+
case ActionType::EmitAssembly:
122+
case ActionType::EmitIR:
123+
case ActionType::EmitBC:
124+
case ActionType::EmitObject:
125+
case ActionType::DumpTypeInfo:
126+
assert(!FrontendOptions::shouldActionOnlyParse(action) &&
127+
"Parse-only actions should not load modules!");
128+
return true;
129+
}
130+
llvm_unreachable("Unknown ActionType");
131+
}
132+
90133
void FrontendOptions::forAllOutputPaths(
91134
const InputFile &input, llvm::function_ref<void(StringRef)> fn) const {
92135
if (RequestedAction != FrontendOptions::ActionType::EmitModuleOnly &&

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ static bool performCompile(CompilerInstance &Instance,
18881888
// trigger a bunch of other errors due to the stdlib being missing, or at
18891889
// worst crash downstream as many call sites don't currently handle a missing
18901890
// stdlib.
1891-
if (!FrontendOptions::shouldActionOnlyParse(Action)) {
1891+
if (FrontendOptions::doesActionRequireSwiftStandardLibrary(Action)) {
18921892
if (Instance.loadStdlibIfNeeded())
18931893
return true;
18941894
}

0 commit comments

Comments
 (0)