Skip to content

Commit c148737

Browse files
Support deterministic checking in explicit module build
1 parent cd9c1e1 commit c148737

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,19 +1360,25 @@ bool ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface(
13601360
ArrayRef<std::string> CompiledCandidates,
13611361
DependencyTracker *tracker) {
13621362

1363-
// First, check if the expected output already exists and possibly up-to-date w.r.t.
1364-
// all of the dependencies it was built with. If so, early exit.
1365-
UpToDateModuleCheker checker(Instance.getASTContext(),
1366-
RequireOSSAModules_t(Instance.getSILOptions()));
1367-
ModuleRebuildInfo rebuildInfo;
1368-
SmallVector<FileDependency, 3> allDeps;
1369-
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
1370-
if (checker.swiftModuleIsUpToDate(outputPath, rebuildInfo, allDeps, moduleBuffer)) {
1371-
if (Instance.getASTContext().LangOpts.EnableSkipExplicitInterfaceModuleBuildRemarks) {
1372-
Instance.getDiags().diagnose(SourceLoc(),
1373-
diag::explicit_interface_build_skipped, outputPath);
1363+
if (!Instance.getInvocation().getIRGenOptions().AlwaysCompile) {
1364+
// First, check if the expected output already exists and possibly
1365+
// up-to-date w.r.t. all of the dependencies it was built with. If so, early
1366+
// exit.
1367+
UpToDateModuleCheker checker(
1368+
Instance.getASTContext(),
1369+
RequireOSSAModules_t(Instance.getSILOptions()));
1370+
ModuleRebuildInfo rebuildInfo;
1371+
SmallVector<FileDependency, 3> allDeps;
1372+
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
1373+
if (checker.swiftModuleIsUpToDate(outputPath, rebuildInfo, allDeps,
1374+
moduleBuffer)) {
1375+
if (Instance.getASTContext()
1376+
.LangOpts.EnableSkipExplicitInterfaceModuleBuildRemarks) {
1377+
Instance.getDiags().diagnose(
1378+
SourceLoc(), diag::explicit_interface_build_skipped, outputPath);
1379+
}
1380+
return false;
13741381
}
1375-
return false;
13761382
}
13771383

13781384
// Read out the compiler version.

test/Frontend/output_determinism_check.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
/// object files should match when forcing object generation.
88
// RUN: %target-swift-frontend -module-name test -c -o %t/test.o -primary-file %s -enable-swift-deterministic-check -always-compile-output-files 2>&1 | %FileCheck %s --check-prefix=OBJECT_OUTPUT
99

10+
/// Explicit module build. Check building swiftmodule from interface file.
11+
/// TODO: Implicit module build use a different compiler instance so it doesn't support checking yet.
12+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/test.swiftinterface %s -O -enable-swift-deterministic-check 2>&1 | %FileCheck %s --check-prefix=INTERFACE_OUTPUT
13+
/// Hit cache and not emit the second time.
14+
// RUN: rm %t/test.swiftmodule
15+
// RUN: not %target-swift-frontend -compile-module-from-interface %t/test.swiftinterface -explicit-interface-module-build -o %t/test.swiftmodule -enable-swift-deterministic-check 2>&1 | %FileCheck --check-prefix=MODULE_MISMATCH %s
16+
/// Force swiftmodule generation.
17+
// RUN: %target-swift-frontend -compile-module-from-interface %t/test.swiftinterface -explicit-interface-module-build -o %t/test.swiftmodule -enable-swift-deterministic-check -always-compile-output-files 2>&1 | %FileCheck --check-prefix=MODULE_OUTPUT %s
18+
1019
// MODULE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftmodule'
1120
// SIB_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.sib'
1221
// OBJECT_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.o'
1322
// OBJECT_MISMATCH: error: output file '{{.*}}{{/|\\}}test.o' is missing from second compilation for deterministic check
23+
// INTERFACE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftinterface'
24+
// MODULE_MISMATCH: error: output file '{{.*}}{{/|\\}}test.swiftmodule' is missing from second compilation for deterministic check
1425

1526
public var x = 1
1627
public func test() {}

0 commit comments

Comments
 (0)