[Explicit Modules] On an explicit interface build, early exit if the expected output is up-to-date.

This commit is contained in:
Artem Chikin
2022-08-16 16:42:44 -07:00
parent 6ca24c9239
commit 256c0ff04a
6 changed files with 42 additions and 0 deletions

View File

@@ -979,6 +979,10 @@ REMARK(cross_import_added,none,
REMARK(module_loaded,none,
"loaded module at %0",
(StringRef))
REMARK(explicit_interface_build_skipped,none,
"Skipped rebuilding module at %0 - up-to-date",
(StringRef))
WARNING(cannot_find_project_version,none,
"cannot find user version number for %0 module '%1'; version number ignored", (StringRef, StringRef))

View File

@@ -215,6 +215,9 @@ namespace swift {
/// Emit a remark after loading a module.
bool EnableModuleLoadingRemarks = false;
/// Emit a remark on early exit in explicit interface build
bool EnableSkipExplicitInterfaceModuleBuildRemarks = false;
///
/// Support for alternate usage modes

View File

@@ -340,6 +340,10 @@ def remark_loading_module : Flag<["-"], "Rmodule-loading">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
HelpText<"Emit a remark and file path of each loaded module">;
def remark_skip_explicit_interface_build : Flag<["-"], "Rskip-explicit-interface-build">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
HelpText<"Emit a remark if an explicit module interface invocation has an early exit because the expected output is up-to-date">;
def emit_tbd : Flag<["-"], "emit-tbd">,
HelpText<"Emit a TBD file">,
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>;

View File

@@ -797,6 +797,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableModuleLoadingRemarks = Args.hasArg(OPT_remark_loading_module);
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
llvm::Triple Target = Opts.Target;
StringRef TargetArg;
std::string TargetArgScratch;

View File

@@ -1345,6 +1345,21 @@ bool ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface(
ArrayRef<std::string> CompiledCandidates,
DependencyTracker *tracker) {
// First, check if the expected output already exists and possibly up-to-date w.r.t.
// all of the dependencies it was built with. If so, early exit.
UpToDateModuleCheker checker(Instance.getASTContext(),
RequireOSSAModules_t(Instance.getSILOptions()));
ModuleRebuildInfo rebuildInfo;
SmallVector<FileDependency, 3> allDeps;
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
if (checker.swiftModuleIsUpToDate(outputPath, rebuildInfo, allDeps, moduleBuffer)) {
if (Instance.getASTContext().LangOpts.EnableSkipExplicitInterfaceModuleBuildRemarks) {
Instance.getDiags().diagnose(SourceLoc(),
diag::explicit_interface_build_skipped, outputPath);
}
return false;
}
// Read out the compiler version.
llvm::BumpPtrAllocator alloc;
llvm::StringSaver ArgSaver(alloc);

View File

@@ -0,0 +1,14 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -parse-stdlib
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExplicitModule -explicit-interface-module-build -o %/t/ExplicitModule.swiftmodule %s
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExplicitModule -explicit-interface-module-build -o %/t/ExplicitModule.swiftmodule %s -Rskip-explicit-interface-build 2>&1 | %FileCheck %s
import Swift
extension Int {
public static var fortytwo: Int = 42
}
// CHECK: <unknown>:0: remark: Skipped rebuilding module at {{.*}}ExplicitModule.swiftmodule - up-to-date