@@ -287,44 +287,45 @@ struct ModuleRebuildInfo {
287
287
288
288
// / Emits a diagnostic for all out-of-date compiled or forwarding modules
289
289
// / 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)...);
294
295
auto SDKVer = getSDKBuildVersion (ctx.SearchPathOpts .SDKPath );
295
296
llvm::SmallString<64 > buffer = prebuiltCacheDir;
296
297
llvm::sys::path::append (buffer, " SystemVersion.plist" );
297
298
auto PBMVer = getSDKBuildVersionFromPlist (buffer.str ());
298
299
if (!SDKVer.empty () && !PBMVer.empty ()) {
299
300
// 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,
301
302
PBMVer);
302
303
}
303
304
// We may have found multiple failing modules, that failed for different
304
305
// reasons. Emit a note for each of them.
305
306
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,
307
308
(unsigned )mod.kind , mod.path );
308
309
309
310
// Diagnose any out-of-date dependencies in this module.
310
311
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,
312
313
dep);
313
314
}
314
315
315
316
// Diagnose any missing dependencies in this module.
316
317
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);
318
319
}
319
320
320
321
// If there was a compiled module that wasn't able to be read, diagnose
321
322
// the reason we couldn't read it.
322
323
if (auto status = mod.serializationStatus ) {
323
324
if (auto reason = invalidModuleReason (*status)) {
324
- ctx. Diags .diagnose (loc, diag::compiled_module_invalid_reason,
325
+ diags .diagnose (loc, diag::compiled_module_invalid_reason,
325
326
mod.path , reason);
326
327
} else {
327
- ctx. Diags .diagnose (loc, diag::compiled_module_invalid, mod.path );
328
+ diags .diagnose (loc, diag::compiled_module_invalid, mod.path );
328
329
}
329
330
}
330
331
}
@@ -957,12 +958,33 @@ class ModuleInterfaceLoaderImpl {
957
958
}
958
959
959
960
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
961
+
960
962
// We didn't discover a module corresponding to this interface.
961
963
// 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 ());
965
984
};
985
+ auto remarkRebuild = Opts.remarkOnRebuildFromInterface
986
+ ? llvm::function_ref<void ()>(remarkRebuildAll)
987
+ : remarkRebuildStdlib;
966
988
967
989
bool failed = false ;
968
990
std::string backupPath = getBackupPublicModuleInterfacePath ();
@@ -996,11 +1018,8 @@ class ModuleInterfaceLoaderImpl {
996
1018
if (rebuildInfo.sawOutOfDateModule (modulePath))
997
1019
builder.addExtraDependency (modulePath);
998
1020
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);
1004
1023
}
1005
1024
if (!failed) {
1006
1025
// If succeeded, we are done.
@@ -1033,9 +1052,7 @@ class ModuleInterfaceLoaderImpl {
1033
1052
// calcualted using the canonical interface file path to make sure we
1034
1053
// can find it from the canonical interface file.
1035
1054
auto failedAgain = fallbackBuilder.buildSwiftModule (cachedOutputPath,
1036
- /* shouldSerializeDeps*/ true , &moduleBuffer,
1037
- Opts.remarkOnRebuildFromInterface ? remarkRebuild:
1038
- llvm::function_ref<void ()>());
1055
+ /* shouldSerializeDeps*/ true , &moduleBuffer, remarkRebuild);
1039
1056
if (failedAgain)
1040
1057
return std::make_error_code (std::errc::invalid_argument);
1041
1058
assert (moduleBuffer);
0 commit comments