@@ -740,17 +740,6 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage,
740740 ModuleDecl *mainModule = getMainModule ();
741741 Context->LoadedModules [mainModule->getName ()] = mainModule;
742742
743- // If we aren't in a parse-only context, load the standard library.
744- if (LimitStage > SourceFile::Unprocessed &&
745- Invocation.getImplicitStdlibKind () == ImplicitStdlibKind::Stdlib
746- && !loadStdlib ()) {
747- // If we failed to load the stdlib, mark the main module as having
748- // "failed to load", as it will contain no files.
749- // FIXME: We need to better handle a missing stdlib.
750- mainModule->setFailedToLoad ();
751- return ;
752- }
753-
754743 // Make sure the main file is the first file in the module, so do this now.
755744 if (MainBufferID != NO_SUCH_BUFFER) {
756745 auto *mainFile = createSourceFileForMainModule (
@@ -813,23 +802,27 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage,
813802 finishTypeChecking ();
814803}
815804
816- bool CompilerInstance::loadStdlib () {
805+ bool CompilerInstance::loadStdlibIfNeeded () {
806+ // If we aren't expecting an implicit stdlib import, there's nothing to do.
807+ if (getImplicitImportInfo ().StdlibKind != ImplicitStdlibKind::Stdlib)
808+ return false ;
809+
817810 FrontendStatsTracer tracer (getStatsReporter (), " load-stdlib" );
818- ModuleDecl *M = Context->getStdlibModule (true );
811+ ModuleDecl *M = Context->getStdlibModule (/* loadIfAbsent */ true );
819812
820813 if (!M) {
821814 Diagnostics.diagnose (SourceLoc (), diag::error_stdlib_not_found,
822815 Invocation.getTargetTriple ());
823- return false ;
816+ return true ;
824817 }
825818
826- // If we failed to load, we should have already diagnosed
819+ // If we failed to load, we should have already diagnosed.
827820 if (M->failedToLoad ()) {
828821 assert (Diagnostics.hadAnyError () &&
829822 " Module failed to load but nothing was diagnosed?" );
830- return false ;
823+ return true ;
831824 }
832- return true ;
825+ return false ;
833826}
834827
835828bool CompilerInstance::loadPartialModulesAndImplicitImports () {
0 commit comments