Skip to content

[ExplicitModule] Propagate deterministic check to explicit modules #80068

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
3 changes: 0 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1425,9 +1425,6 @@ def enable_emit_generic_class_ro_t_list :
HelpText<"Enable emission of a section with references to class_ro_t of "
"generic class patterns">;

def enable_deterministic_check :
Flag<["-"], "enable-deterministic-check">,
HelpText<"Check compiler output determinism by running it twice">;
def always_compile_output_files :
Flag<["-"], "always-compile-output-files">,
HelpText<"Always compile output files even it might not change the results">;
Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2245,4 +2245,9 @@ def disable_sandbox:
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
HelpText<"Disable using the sandbox when executing subprocesses">;

def enable_deterministic_check :
Flag<["-"], "enable-deterministic-check">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, CacheInvariant]>,
HelpText<"Check compiler output determinism by running it twice">;

include "FrontendOptions.td"
13 changes: 13 additions & 0 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class ExplicitModuleDependencyResolver {
bridgingHeaderBuildCmd.push_back(clangDep->moduleCacheKey);
}
}
addDeterministicCheckFlags(bridgingHeaderBuildCmd);
}

SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
Expand All @@ -183,6 +184,7 @@ class ExplicitModuleDependencyResolver {
remapPathsFromCommandLine(commandline, [&](StringRef path) {
return cache.getScanService().remapPath(path);
});
addDeterministicCheckFlags(commandline);
}

auto dependencyInfoCopy = resolvingDepInfo;
Expand Down Expand Up @@ -583,6 +585,17 @@ class ExplicitModuleDependencyResolver {
return llvm::Error::success();
}

void addDeterministicCheckFlags(std::vector<std::string> &cmd) {
// Propagate the deterministic check to explicit built module command.
if (!instance.getInvocation().getFrontendOptions().DeterministicCheck)
return;
cmd.push_back("-enable-deterministic-check");
cmd.push_back("-always-compile-output-files");
// disable cache replay because that defeat the purpose of the check.
if (instance.getInvocation().getCASOptions().EnableCaching)
cmd.push_back("-cache-disable-replay");
}

private:
const ModuleDependencyID &moduleID;
ModuleDependenciesCache &cache;
Expand Down
43 changes: 43 additions & 0 deletions test/CAS/deterministic_check.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -module-load-mode prefer-serialized \
// RUN: %t/test.swift -o %t/deps.json -I %t -import-objc-header %t/Bridging.h \
// RUN: -enable-deterministic-check -cache-compile-job -cas-path %t/cas 2>&1 | %FileCheck %s

// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
// RUN: %FileCheck %s --check-prefix=CMD --input-file=%t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd 2>&1 | %FileCheck %s
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
// RUN: %FileCheck %s --check-prefix=CMD --input-file=%t/B.cmd
// RUN: %swift_frontend_plain @%t/B.cmd 2>&1 | %FileCheck %s

// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json Test bridgingHeader | %FileCheck %s --check-prefix=CMD

// CHECK: remark: produced matching output file
// CMD: -enable-deterministic-check
// CMD: -always-compile-output-files
// CMD: -cache-disable-replay

//--- test.swift
import A
import B
public func test() {}

//--- A.swiftinterface
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name A -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -user-module-version 1.0
public func a() { }

//--- b.h
void b(void);

//--- module.modulemap
module B {
header "b.h"
export *
}

//--- Bridging.h
void bridge(void);
36 changes: 36 additions & 0 deletions test/ScanDependencies/deterministic_check.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -module-load-mode prefer-serialized \
// RUN: %t/test.swift -o %t/deps.json -I %t -enable-deterministic-check 2>&1 | %FileCheck %s

// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
// RUN: %FileCheck %s --check-prefix=CMD --input-file=%t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd 2>&1 | %FileCheck %s
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
// RUN: %FileCheck %s --check-prefix=CMD --input-file=%t/B.cmd
// RUN: %swift_frontend_plain @%t/B.cmd 2>&1 | %FileCheck %s

// CHECK: remark: produced matching output file
// CMD: -enable-deterministic-check
// CMD: -always-compile-output-files

//--- test.swift
import A
import B
public func test() {}

//--- A.swiftinterface
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name A -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -user-module-version 1.0
public func a() { }

//--- b.h
void b(void);

//--- module.modulemap
module B {
header "b.h"
export *
}