@@ -354,17 +354,26 @@ void ImportResolver::addImport(const UnboundImport &I, ModuleDecl *M) {
354354// MARK: Import module loading
355355// ===----------------------------------------------------------------------===//
356356
357- static ModuleDecl *
358- getModuleImpl (ImportPath::Module modulePath, ModuleDecl *loadingModule,
359- bool canImportBuiltin) {
357+ ModuleDecl *
358+ ImportResolver::getModule (ImportPath::Module modulePath) {
359+ auto loadingModule = SF.getParentModule ();
360+
360361 ASTContext &ctx = loadingModule->getASTContext ();
361362
362363 assert (!modulePath.empty ());
363364 auto moduleID = modulePath[0 ];
364365
365- // The Builtin module cannot be explicitly imported unless we're a .sil file.
366- if (canImportBuiltin && moduleID.Item == ctx.TheBuiltinModule ->getName ())
367- return ctx.TheBuiltinModule ;
366+ // The Builtin module cannot be explicitly imported unless:
367+ // 1. We're in a .sil file
368+ // 2. '-enable-builtin-module' was passed.
369+ //
370+ // FIXME: Eventually, it would be nice to separate '-parse-stdlib' from
371+ // implicitly importing Builtin, but we're not there yet.
372+ if (SF.Kind == SourceFileKind::SIL || ctx.LangOpts .EnableBuiltinModule ) {
373+ if (moduleID.Item == ctx.TheBuiltinModule ->getName ()) {
374+ return ctx.TheBuiltinModule ;
375+ }
376+ }
368377
369378 // If the imported module name is the same as the current module,
370379 // skip the Swift module loader and use the Clang module loader instead.
@@ -382,12 +391,6 @@ getModuleImpl(ImportPath::Module modulePath, ModuleDecl *loadingModule,
382391 return ctx.getModule (modulePath);
383392}
384393
385- ModuleDecl *
386- ImportResolver::getModule (ImportPath::Module modulePath) {
387- return getModuleImpl (modulePath, SF.getParentModule (),
388- /* canImportBuiltin=*/ SF.Kind == SourceFileKind::SIL);
389- }
390-
391394NullablePtr<ModuleDecl>
392395UnboundImport::getTopLevelModule (ModuleDecl *M, SourceFile &SF) {
393396 if (import .module .getModulePath ().size () == 1 )
@@ -737,11 +740,21 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
737740 if (!topLevelModule || topLevelModule.get ()->isNonSwiftModule ())
738741 return ;
739742
743+ ASTContext &ctx = SF.getASTContext ();
744+
745+ // If the module we're validating is the builtin one, then just return because
746+ // this module is essentially a header only import and does not concern
747+ // itself with resiliency. This can occur when one has passed
748+ // '-enable-builtin-module' and is explicitly importing the Builtin module in
749+ // their sources.
750+ if (topLevelModule.get () == ctx.TheBuiltinModule ) {
751+ return ;
752+ }
753+
740754 if (!SF.getParentModule ()->isResilient () ||
741755 topLevelModule.get ()->isResilient ())
742756 return ;
743757
744- ASTContext &ctx = SF.getASTContext ();
745758 ctx.Diags .diagnose (import .module .getModulePath ().front ().Loc ,
746759 diag::module_not_compiled_with_library_evolution,
747760 topLevelModule.get ()->getName (),
0 commit comments