@@ -287,44 +287,45 @@ struct ModuleRebuildInfo {
287287
288288 // / Emits a diagnostic for all out-of-date compiled or forwarding modules
289289 // / encountered while trying to load a module.
290- void diagnose (ASTContext &ctx, SourceLoc loc, StringRef moduleName,
291- StringRef interfacePath, StringRef prebuiltCacheDir) {
292- ctx.Diags .diagnose (loc, diag::rebuilding_module_from_interface,
293- moduleName, interfacePath);
290+ template <typename ... DiagArgs>
291+ void diagnose (ASTContext &ctx, DiagnosticEngine &diags,
292+ StringRef prebuiltCacheDir, SourceLoc loc,
293+ DiagArgs &&...diagArgs) {
294+ diags.diagnose (loc, std::forward<DiagArgs>(diagArgs)...);
294295 auto SDKVer = getSDKBuildVersion (ctx.SearchPathOpts .SDKPath );
295296 llvm::SmallString<64 > buffer = prebuiltCacheDir;
296297 llvm::sys::path::append (buffer, " SystemVersion.plist" );
297298 auto PBMVer = getSDKBuildVersionFromPlist (buffer.str ());
298299 if (!SDKVer.empty () && !PBMVer.empty ()) {
299300 // Remark the potential version difference.
300- ctx. Diags .diagnose (loc, diag::sdk_version_pbm_version, SDKVer,
301+ diags .diagnose (loc, diag::sdk_version_pbm_version, SDKVer,
301302 PBMVer);
302303 }
303304 // We may have found multiple failing modules, that failed for different
304305 // reasons. Emit a note for each of them.
305306 for (auto &mod : outOfDateModules) {
306- ctx. Diags .diagnose (loc, diag::out_of_date_module_here,
307+ diags .diagnose (loc, diag::out_of_date_module_here,
307308 (unsigned )mod.kind , mod.path );
308309
309310 // Diagnose any out-of-date dependencies in this module.
310311 for (auto &dep : mod.outOfDateDependencies ) {
311- ctx. Diags .diagnose (loc, diag::module_interface_dependency_out_of_date,
312+ diags .diagnose (loc, diag::module_interface_dependency_out_of_date,
312313 dep);
313314 }
314315
315316 // Diagnose any missing dependencies in this module.
316317 for (auto &dep : mod.missingDependencies ) {
317- ctx. Diags .diagnose (loc, diag::module_interface_dependency_missing, dep);
318+ diags .diagnose (loc, diag::module_interface_dependency_missing, dep);
318319 }
319320
320321 // If there was a compiled module that wasn't able to be read, diagnose
321322 // the reason we couldn't read it.
322323 if (auto status = mod.serializationStatus ) {
323324 if (auto reason = invalidModuleReason (*status)) {
324- ctx. Diags .diagnose (loc, diag::compiled_module_invalid_reason,
325+ diags .diagnose (loc, diag::compiled_module_invalid_reason,
325326 mod.path , reason);
326327 } else {
327- ctx. Diags .diagnose (loc, diag::compiled_module_invalid, mod.path );
328+ diags .diagnose (loc, diag::compiled_module_invalid, mod.path );
328329 }
329330 }
330331 }
@@ -957,12 +958,33 @@ class ModuleInterfaceLoaderImpl {
957958 }
958959
959960 std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
961+
960962 // We didn't discover a module corresponding to this interface.
961963 // Diagnose that we didn't find a loadable module, if we were asked to.
962- auto remarkRebuild = [&]() {
963- rebuildInfo.diagnose (ctx, diagnosticLoc, moduleName,
964- interfacePath, prebuiltCacheDir);
964+ //
965+ // Note that we use `diags` so that we emit this remark even when we're
966+ // emitting other messages to `emptyDiags` (see below); these act as status
967+ // messages to explain what's taking so long.
968+ auto remarkRebuildAll = [&]() {
969+ rebuildInfo.diagnose (ctx, diags, prebuiltCacheDir, diagnosticLoc,
970+ diag::rebuilding_module_from_interface, moduleName,
971+ interfacePath);
972+ };
973+ // Diagnose only for the standard library; it should be prebuilt in typical
974+ // workflows, but if it isn't, building it may take several minutes and a
975+ // lot of memory, so users may think the compiler is busy-hung.
976+ auto remarkRebuildStdlib = [&]() {
977+ if (moduleName != " Swift" )
978+ return ;
979+
980+ auto moduleTriple = getTargetSpecificModuleTriple (ctx.LangOpts .Target );
981+ rebuildInfo.diagnose (ctx, diags, prebuiltCacheDir, SourceLoc (),
982+ diag::rebuilding_stdlib_from_interface,
983+ moduleTriple.str ());
965984 };
985+ auto remarkRebuild = Opts.remarkOnRebuildFromInterface
986+ ? llvm::function_ref<void ()>(remarkRebuildAll)
987+ : remarkRebuildStdlib;
966988
967989 bool failed = false ;
968990 std::string backupPath = getBackupPublicModuleInterfacePath ();
@@ -996,11 +1018,8 @@ class ModuleInterfaceLoaderImpl {
9961018 if (rebuildInfo.sawOutOfDateModule (modulePath))
9971019 builder.addExtraDependency (modulePath);
9981020 failed = builder.buildSwiftModule (cachedOutputPath,
999- /* shouldSerializeDeps*/ true ,
1000- &moduleBuffer,
1001- Opts.remarkOnRebuildFromInterface ?
1002- remarkRebuild:
1003- llvm::function_ref<void ()>());
1021+ /* shouldSerializeDeps*/ true ,
1022+ &moduleBuffer, remarkRebuild);
10041023 }
10051024 if (!failed) {
10061025 // If succeeded, we are done.
@@ -1033,9 +1052,7 @@ class ModuleInterfaceLoaderImpl {
10331052 // calcualted using the canonical interface file path to make sure we
10341053 // can find it from the canonical interface file.
10351054 auto failedAgain = fallbackBuilder.buildSwiftModule (cachedOutputPath,
1036- /* shouldSerializeDeps*/ true , &moduleBuffer,
1037- Opts.remarkOnRebuildFromInterface ? remarkRebuild:
1038- llvm::function_ref<void ()>());
1055+ /* shouldSerializeDeps*/ true , &moduleBuffer, remarkRebuild);
10391056 if (failedAgain)
10401057 return std::make_error_code (std::errc::invalid_argument);
10411058 assert (moduleBuffer);
0 commit comments