[Frontend] Bail early if the stdlib is missing

Rather than trying to continue the compilation
with an empty main module, let's bail out early if
we expect an implicit stdlib import and fail to
load in the stdlib.
This commit is contained in:
Hamish Knight
2020-05-29 16:13:42 -07:00
parent ae624f3947
commit ab6c15f4b3
4 changed files with 32 additions and 26 deletions

View File

@@ -1250,6 +1250,17 @@ static bool performCompile(CompilerInstance &Instance,
if (Invocation.getInputKind() == InputFileKind::LLVM)
return compileLLVMIR(Instance);
// If we aren't in a parse-only context and expect an implicit stdlib import,
// load in the standard library. If we either fail to find it or encounter an
// error while loading it, bail early. Continuing the compilation will at best
// trigger a bunch of other errors due to the stdlib being missing, or at
// worst crash downstream as many call sites don't currently handle a missing
// stdlib.
if (!FrontendOptions::shouldActionOnlyParse(Action)) {
if (Instance.loadStdlibIfNeeded())
return true;
}
if (FrontendOptions::shouldActionOnlyParse(Action)) {
// Disable delayed parsing of type and function bodies when we've been
// asked to dump the resulting AST.