Skip to content

Commit 256c0ff

Browse files
committed
[Explicit Modules] On an explicit interface build, early exit if the expected output is up-to-date.
1 parent 6ca24c9 commit 256c0ff

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,10 @@ REMARK(cross_import_added,none,
979979
REMARK(module_loaded,none,
980980
"loaded module at %0",
981981
(StringRef))
982+
983+
REMARK(explicit_interface_build_skipped,none,
984+
"Skipped rebuilding module at %0 - up-to-date",
985+
(StringRef))
982986

983987
WARNING(cannot_find_project_version,none,
984988
"cannot find user version number for %0 module '%1'; version number ignored", (StringRef, StringRef))

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ namespace swift {
215215

216216
/// Emit a remark after loading a module.
217217
bool EnableModuleLoadingRemarks = false;
218+
219+
/// Emit a remark on early exit in explicit interface build
220+
bool EnableSkipExplicitInterfaceModuleBuildRemarks = false;
218221

219222
///
220223
/// Support for alternate usage modes

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ def remark_loading_module : Flag<["-"], "Rmodule-loading">,
340340
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
341341
HelpText<"Emit a remark and file path of each loaded module">;
342342

343+
def remark_skip_explicit_interface_build : Flag<["-"], "Rskip-explicit-interface-build">,
344+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
345+
HelpText<"Emit a remark if an explicit module interface invocation has an early exit because the expected output is up-to-date">;
346+
343347
def emit_tbd : Flag<["-"], "emit-tbd">,
344348
HelpText<"Emit a TBD file">,
345349
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
797797

798798
Opts.EnableModuleLoadingRemarks = Args.hasArg(OPT_remark_loading_module);
799799

800+
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
801+
800802
llvm::Triple Target = Opts.Target;
801803
StringRef TargetArg;
802804
std::string TargetArgScratch;

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,21 @@ bool ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface(
13451345
ArrayRef<std::string> CompiledCandidates,
13461346
DependencyTracker *tracker) {
13471347

1348+
// First, check if the expected output already exists and possibly up-to-date w.r.t.
1349+
// all of the dependencies it was built with. If so, early exit.
1350+
UpToDateModuleCheker checker(Instance.getASTContext(),
1351+
RequireOSSAModules_t(Instance.getSILOptions()));
1352+
ModuleRebuildInfo rebuildInfo;
1353+
SmallVector<FileDependency, 3> allDeps;
1354+
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
1355+
if (checker.swiftModuleIsUpToDate(outputPath, rebuildInfo, allDeps, moduleBuffer)) {
1356+
if (Instance.getASTContext().LangOpts.EnableSkipExplicitInterfaceModuleBuildRemarks) {
1357+
Instance.getDiags().diagnose(SourceLoc(),
1358+
diag::explicit_interface_build_skipped, outputPath);
1359+
}
1360+
return false;
1361+
}
1362+
13481363
// Read out the compiler version.
13491364
llvm::BumpPtrAllocator alloc;
13501365
llvm::StringSaver ArgSaver(alloc);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -parse-stdlib
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExplicitModule -explicit-interface-module-build -o %/t/ExplicitModule.swiftmodule %s
6+
7+
// 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
8+
9+
import Swift
10+
extension Int {
11+
public static var fortytwo: Int = 42
12+
}
13+
14+
// CHECK: <unknown>:0: remark: Skipped rebuilding module at {{.*}}ExplicitModule.swiftmodule - up-to-date

0 commit comments

Comments
 (0)