Skip to content

Commit f978cb0

Browse files
author
Harlan Haskins
authored
Merge pull request #24424 from harlanhaskins/an-absolutely-remarkable-thing
[ModuleInterface] Emit remarks when rebuilding from an interface
2 parents b6b5725 + dfe4491 commit f978cb0

12 files changed

+284
-31
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
22-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
21+
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && \
22+
defined(REMARK)))
23+
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
2324
#endif
2425

2526
#ifndef ERROR
@@ -37,6 +38,11 @@
3738
DIAG(NOTE,ID,Options,Text,Signature)
3839
#endif
3940

41+
#ifndef REMARK
42+
# define REMARK(ID,Options,Text,Signature) \
43+
DIAG(REMARK,ID,Options,Text,Signature)
44+
#endif
45+
4046
WARNING(warning_no_such_sdk,none,
4147
"no such SDK: '%0'", (StringRef))
4248

@@ -278,6 +284,20 @@ ERROR(error_extracting_flags_from_module_interface,none,
278284
ERROR(missing_dependency_of_module_interface,none,
279285
"missing dependency '%0' of module interface '%1': %2",
280286
(StringRef, StringRef, StringRef))
287+
REMARK(rebuilding_module_from_interface,none,
288+
"rebuilding module '%0' from interface '%1'", (StringRef, StringRef))
289+
NOTE(out_of_date_module_here,none,
290+
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
291+
(unsigned, StringRef))
292+
NOTE(module_interface_dependency_out_of_date,none,
293+
"dependency is out of date: '%0'",
294+
(StringRef))
295+
NOTE(compiled_module_invalid,none,
296+
"unable to load compiled module '%0'",
297+
(StringRef))
298+
NOTE(compiled_module_invalid_reason,none,
299+
"unable to load compiled module '%0': %1",
300+
(StringRef, StringRef))
281301
ERROR(error_extracting_dependencies_from_cached_module,none,
282302
"error extracting dependencies from cached module '%0'",
283303
(StringRef))
@@ -289,6 +309,7 @@ ERROR(unknown_forced_module_loading_mode,none,
289309
# if defined(DIAG)
290310
# undef DIAG
291311
# endif
312+
# undef REMARK
292313
# undef NOTE
293314
# undef WARNING
294315
# undef ERROR

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ class FrontendOptions {
272272
/// times) when compiling a module interface?
273273
bool SerializeModuleInterfaceDependencyHashes = false;
274274

275+
/// Should we warn if an imported module needed to be rebuilt from a
276+
/// module interface file?
277+
bool RemarkOnRebuildFromModuleInterface = false;
278+
275279
/// The different modes for validating TBD against the LLVM IR.
276280
enum class TBDValidationMode {
277281
Default, ///< Do the default validation for the current platform.

include/swift/Frontend/ParseableInterfaceModuleLoader.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,18 @@ namespace swift {
122122
/// directory, and loading the serialized .swiftmodules from there.
123123
class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
124124
friend class unittest::ParseableInterfaceModuleLoaderTest;
125-
explicit ParseableInterfaceModuleLoader(ASTContext &ctx, StringRef cacheDir,
126-
StringRef prebuiltCacheDir,
127-
DependencyTracker *tracker,
128-
ModuleLoadingMode loadMode)
125+
explicit ParseableInterfaceModuleLoader(
126+
ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
127+
DependencyTracker *tracker, ModuleLoadingMode loadMode,
128+
bool RemarkOnRebuildFromInterface)
129129
: SerializedModuleLoaderBase(ctx, tracker, loadMode),
130-
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir)
130+
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
131+
RemarkOnRebuildFromInterface(RemarkOnRebuildFromInterface)
131132
{}
132133

133134
std::string CacheDir;
134135
std::string PrebuiltCacheDir;
136+
bool RemarkOnRebuildFromInterface;
135137

136138
std::error_code findModuleFilesInDirectory(
137139
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
@@ -144,10 +146,12 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
144146
public:
145147
static std::unique_ptr<ParseableInterfaceModuleLoader>
146148
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
147-
DependencyTracker *tracker, ModuleLoadingMode loadMode) {
149+
DependencyTracker *tracker, ModuleLoadingMode loadMode,
150+
bool RemarkOnRebuildFromInterface = false) {
148151
return std::unique_ptr<ParseableInterfaceModuleLoader>(
149152
new ParseableInterfaceModuleLoader(ctx, cacheDir, prebuiltCacheDir,
150-
tracker, loadMode));
153+
tracker, loadMode,
154+
RemarkOnRebuildFromInterface));
151155
}
152156

153157
/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ def warn_long_expression_type_checking : Separate<["-"], "warn-long-expression-t
388388
def warn_long_expression_type_checking_EQ : Joined<["-"], "warn-long-expression-type-checking=">,
389389
Alias<warn_long_expression_type_checking>;
390390

391+
def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">,
392+
HelpText<"Emits a remark if an imported module needs to be re-compiled from its module interface">;
393+
391394
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;
392395

393396
def solver_disable_shrink :

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ bool ArgsToFrontendOptionsConverter::convert(
8383
Opts.SerializeModuleInterfaceDependencyHashes |=
8484
Args.hasArg(OPT_serialize_module_interface_dependency_hashes);
8585

86+
Opts.RemarkOnRebuildFromModuleInterface |=
87+
Args.hasArg(OPT_Rmodule_interface_rebuild);
88+
8689
computePrintStatsOptions();
8790
computeDebugTimeOptions();
8891
computeTBDOptions();

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
246246
} else if (MatchStart.startswith("expected-error")) {
247247
ExpectedClassification = llvm::SourceMgr::DK_Error;
248248
MatchStart = MatchStart.substr(strlen("expected-error"));
249+
} else if (MatchStart.startswith("expected-remark")) {
250+
ExpectedClassification = llvm::SourceMgr::DK_Remark;
251+
MatchStart = MatchStart.substr(strlen("expected-remark"));
249252
} else
250253
continue;
251254

lib/Frontend/Frontend.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,11 @@ bool CompilerInstance::setUpModuleLoaders() {
339339
if (MLM != ModuleLoadingMode::OnlySerialized) {
340340
auto const &Clang = clangImporter->getClangInstance();
341341
std::string ModuleCachePath = getModuleCachePathFromClang(Clang);
342-
StringRef PrebuiltModuleCachePath =
343-
Invocation.getFrontendOptions().PrebuiltModuleCachePath;
344-
auto PIML = ParseableInterfaceModuleLoader::create(*Context,
345-
ModuleCachePath,
346-
PrebuiltModuleCachePath,
347-
getDependencyTracker(),
348-
MLM);
342+
auto &FEOpts = Invocation.getFrontendOptions();
343+
StringRef PrebuiltModuleCachePath = FEOpts.PrebuiltModuleCachePath;
344+
auto PIML = ParseableInterfaceModuleLoader::create(
345+
*Context, ModuleCachePath, PrebuiltModuleCachePath,
346+
getDependencyTracker(), MLM, FEOpts.RemarkOnRebuildFromModuleInterface);
349347
Context->addModuleLoader(std::move(PIML));
350348
}
351349
Context->addModuleLoader(std::move(SML));

0 commit comments

Comments
 (0)