Skip to content

[5.1] [ModuleInterface] Emit remarks when rebuilding from an interface #24470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
//
//===----------------------------------------------------------------------===//

#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && \
defined(REMARK)))
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
#endif

#ifndef ERROR
Expand All @@ -37,6 +38,11 @@
DIAG(NOTE,ID,Options,Text,Signature)
#endif

#ifndef REMARK
# define REMARK(ID,Options,Text,Signature) \
DIAG(REMARK,ID,Options,Text,Signature)
#endif

WARNING(warning_no_such_sdk,none,
"no such SDK: '%0'", (StringRef))

Expand Down Expand Up @@ -278,6 +284,20 @@ ERROR(error_extracting_flags_from_module_interface,none,
ERROR(missing_dependency_of_module_interface,none,
"missing dependency '%0' of module interface '%1': %2",
(StringRef, StringRef, StringRef))
REMARK(rebuilding_module_from_interface,none,
"rebuilding module '%0' from interface '%1'", (StringRef, StringRef))
NOTE(out_of_date_module_here,none,
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
(unsigned, StringRef))
NOTE(module_interface_dependency_out_of_date,none,
"dependency is out of date: '%0'",
(StringRef))
NOTE(compiled_module_invalid,none,
"unable to load compiled module '%0'",
(StringRef))
NOTE(compiled_module_invalid_reason,none,
"unable to load compiled module '%0': %1",
(StringRef, StringRef))
ERROR(error_extracting_dependencies_from_cached_module,none,
"error extracting dependencies from cached module '%0'",
(StringRef))
Expand All @@ -289,6 +309,7 @@ ERROR(unknown_forced_module_loading_mode,none,
# if defined(DIAG)
# undef DIAG
# endif
# undef REMARK
# undef NOTE
# undef WARNING
# undef ERROR
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ class FrontendOptions {
/// times) when compiling a module interface?
bool SerializeModuleInterfaceDependencyHashes = false;

/// Should we warn if an imported module needed to be rebuilt from a
/// module interface file?
bool RemarkOnRebuildFromModuleInterface = false;

/// The different modes for validating TBD against the LLVM IR.
enum class TBDValidationMode {
Default, ///< Do the default validation for the current platform.
Expand Down
18 changes: 11 additions & 7 deletions include/swift/Frontend/ParseableInterfaceModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,18 @@ namespace swift {
/// directory, and loading the serialized .swiftmodules from there.
class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
friend class unittest::ParseableInterfaceModuleLoaderTest;
explicit ParseableInterfaceModuleLoader(ASTContext &ctx, StringRef cacheDir,
StringRef prebuiltCacheDir,
DependencyTracker *tracker,
ModuleLoadingMode loadMode)
explicit ParseableInterfaceModuleLoader(
ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
DependencyTracker *tracker, ModuleLoadingMode loadMode,
bool RemarkOnRebuildFromInterface)
: SerializedModuleLoaderBase(ctx, tracker, loadMode),
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir)
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
RemarkOnRebuildFromInterface(RemarkOnRebuildFromInterface)
{}

std::string CacheDir;
std::string PrebuiltCacheDir;
bool RemarkOnRebuildFromInterface;

std::error_code findModuleFilesInDirectory(
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
Expand All @@ -144,10 +146,12 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
public:
static std::unique_ptr<ParseableInterfaceModuleLoader>
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
DependencyTracker *tracker, ModuleLoadingMode loadMode) {
DependencyTracker *tracker, ModuleLoadingMode loadMode,
bool RemarkOnRebuildFromInterface = false) {
return std::unique_ptr<ParseableInterfaceModuleLoader>(
new ParseableInterfaceModuleLoader(ctx, cacheDir, prebuiltCacheDir,
tracker, loadMode));
tracker, loadMode,
RemarkOnRebuildFromInterface));
}

/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ def warn_long_expression_type_checking : Separate<["-"], "warn-long-expression-t
def warn_long_expression_type_checking_EQ : Joined<["-"], "warn-long-expression-type-checking=">,
Alias<warn_long_expression_type_checking>;

def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">,
HelpText<"Emits a remark if an imported module needs to be re-compiled from its module interface">;

def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;

def solver_disable_shrink :
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ bool ArgsToFrontendOptionsConverter::convert(
Opts.SerializeModuleInterfaceDependencyHashes |=
Args.hasArg(OPT_serialize_module_interface_dependency_hashes);

Opts.RemarkOnRebuildFromModuleInterface |=
Args.hasArg(OPT_Rmodule_interface_rebuild);

computePrintStatsOptions();
computeDebugTimeOptions();
computeTBDOptions();
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/DiagnosticVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
} else if (MatchStart.startswith("expected-error")) {
ExpectedClassification = llvm::SourceMgr::DK_Error;
MatchStart = MatchStart.substr(strlen("expected-error"));
} else if (MatchStart.startswith("expected-remark")) {
ExpectedClassification = llvm::SourceMgr::DK_Remark;
MatchStart = MatchStart.substr(strlen("expected-remark"));
} else
continue;

Expand Down
12 changes: 5 additions & 7 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,11 @@ bool CompilerInstance::setUpModuleLoaders() {
if (MLM != ModuleLoadingMode::OnlySerialized) {
auto const &Clang = clangImporter->getClangInstance();
std::string ModuleCachePath = getModuleCachePathFromClang(Clang);
StringRef PrebuiltModuleCachePath =
Invocation.getFrontendOptions().PrebuiltModuleCachePath;
auto PIML = ParseableInterfaceModuleLoader::create(*Context,
ModuleCachePath,
PrebuiltModuleCachePath,
getDependencyTracker(),
MLM);
auto &FEOpts = Invocation.getFrontendOptions();
StringRef PrebuiltModuleCachePath = FEOpts.PrebuiltModuleCachePath;
auto PIML = ParseableInterfaceModuleLoader::create(
*Context, ModuleCachePath, PrebuiltModuleCachePath,
getDependencyTracker(), MLM, FEOpts.RemarkOnRebuildFromModuleInterface);
Context->addModuleLoader(std::move(PIML));
}
Context->addModuleLoader(std::move(SML));
Expand Down
Loading