Skip to content

Commit 22e91fd

Browse files
authored
Merge pull request #15749 from graydon/batch-mode-flag-double-vision
2 parents 20ae19e + a9916df commit 22e91fd

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

include/swift/Driver/Driver.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ class OutputInfo {
6464
/// A compilation using a single frontend invocation without -primary-file.
6565
SingleCompile,
6666

67-
/// A single process that batches together multiple StandardCompile jobs.
67+
/// A single process that batches together multiple StandardCompile Jobs.
68+
///
69+
/// Note: this is a transient value to use _only_ for the individual
70+
/// BatchJobs that are the temporary containers for multiple StandardCompile
71+
/// Jobs built by ToolChain::constructBatchJob.
72+
///
73+
/// In particular, the driver treats a batch-mode-enabled Compilation as
74+
/// having OutputInfo::CompilerMode == StandardCompile, with the
75+
/// Compilation::BatchModeEnabled flag set to true, _not_ as a
76+
/// BatchModeCompile Compilation. The top-level OutputInfo::CompilerMode for
77+
/// a Compilation should never be BatchModeCompile.
6878
BatchModeCompile,
6979

7080
/// Invoke the REPL
@@ -389,8 +399,11 @@ class Driver {
389399
/// there is an actual conflict.
390400
/// \param Args The input arguments.
391401
/// \param Inputs The inputs to the driver.
402+
/// \param BatchModeOut An out-parameter flag that indicates whether to
403+
/// batch the jobs of the resulting \c Mode::StandardCompile compilation.
392404
OutputInfo::Mode computeCompilerMode(const llvm::opt::DerivedArgList &Args,
393-
const InputFileList &Inputs) const;
405+
const InputFileList &Inputs,
406+
bool &BatchModeOut) const;
394407
};
395408

396409
} // end namespace driver

lib/Driver/Driver.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,6 @@ Driver::buildCompilation(const ToolChain &TC,
594594
Incremental = false;
595595
}
596596

597-
bool BatchMode = ArgList->hasFlag(options::OPT_enable_batch_mode,
598-
options::OPT_disable_batch_mode,
599-
false);
600-
601597
bool SaveTemps = ArgList->hasArg(options::OPT_save_temps);
602598
bool ContinueBuildingAfterErrors =
603599
ArgList->hasArg(options::OPT_continue_building_after_errors);
@@ -631,6 +627,8 @@ Driver::buildCompilation(const ToolChain &TC,
631627

632628
// Determine the OutputInfo for the driver.
633629
OutputInfo OI;
630+
bool BatchMode = false;
631+
OI.CompilerMode = computeCompilerMode(*TranslatedArgList, Inputs, BatchMode);
634632
buildOutputInfo(TC, *TranslatedArgList, BatchMode, Inputs, OI);
635633

636634
if (Diags.hadAnyError())
@@ -1122,8 +1120,6 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
11221120
? file_types::TY_Nothing
11231121
: file_types::TY_Object;
11241122

1125-
OI.CompilerMode = computeCompilerMode(Args, Inputs);
1126-
11271123
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) {
11281124
if (BatchMode) {
11291125
Diags.diagnose(SourceLoc(), diag::warning_cannot_multithread_batch_mode);
@@ -1393,26 +1389,31 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13931389

13941390
OutputInfo::Mode
13951391
Driver::computeCompilerMode(const DerivedArgList &Args,
1396-
const InputFileList &Inputs) const {
1392+
const InputFileList &Inputs,
1393+
bool &BatchModeOut) const {
13971394

13981395
if (driverKind == Driver::DriverKind::Interactive)
13991396
return Inputs.empty() ? OutputInfo::Mode::REPL
14001397
: OutputInfo::Mode::Immediate;
14011398

1402-
const Arg *ArgRequiringWMO = Args.getLastArg(
1399+
const Arg *ArgRequiringSingleCompile = Args.getLastArg(
14031400
options::OPT_whole_module_optimization, options::OPT_index_file);
14041401

1405-
if (!ArgRequiringWMO)
1402+
BatchModeOut = Args.hasFlag(options::OPT_enable_batch_mode,
1403+
options::OPT_disable_batch_mode,
1404+
false);
1405+
1406+
if (!ArgRequiringSingleCompile)
14061407
return OutputInfo::Mode::StandardCompile;
14071408

1408-
// Test for -enable-batch-mode, rather than the BatchMode flag that is
1409-
// passed into the caller because the diagnostic is intended to warn against
1410-
// overriding *explicit* batch mode. No warning should be given if in batch
1411-
// mode by default.
1412-
if (Args.hasArg(options::OPT_enable_batch_mode))
1409+
// Override batch mode if given -wmo or -index-file.
1410+
if (BatchModeOut) {
1411+
BatchModeOut = false;
1412+
// Emit a warning about such overriding (FIXME: we might conditionalize
1413+
// this based on the user or xcode passing -disable-batch-mode).
14131414
Diags.diagnose(SourceLoc(), diag::warn_ignoring_batch_mode,
1414-
ArgRequiringWMO->getOption().getPrefixedName());
1415-
1415+
ArgRequiringSingleCompile->getOption().getPrefixedName());
1416+
}
14161417
return OutputInfo::Mode::SingleCompile;
14171418
}
14181419

test/Driver/batch_mode_with_WMO_or_index.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@
1212
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_index_batch
1313
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_batch_index
1414
// CHECK-INDEX: warning: ignoring '-enable-batch-mode' because '-index-file' was also specified
15+
//
16+
// This next one is a regression test for a specific failure in the past: wmo +
17+
// batch mode should not just result in wmo, but also preserve the num-threads
18+
// argument and (crucially) the resulting fact that the single wmo subprocess
19+
// generates multiple output files. The build system that invokes swiftc expects
20+
// multiple outputs.
21+
//
22+
// RUN: touch %t/a.swift %t/b.swift %t/c.swift
23+
// RUN: %swiftc_driver %t/a.swift %t/b.swift %t/c.swift -num-threads 4 -whole-module-optimization -enable-batch-mode -### >%t/stdout_mt_wmo 2>%t/stderr_mt_wmo
24+
// RUN: %FileCheck --check-prefix CHECK-WMO %s <%t/stderr_mt_wmo
25+
// RUN: %FileCheck --check-prefix CHECK-MULTITHREADED-WMO-ARGS %s <%t/stdout_mt_wmo
26+
// CHECK-MULTITHREADED-WMO-ARGS: -num-threads 4 {{.*}}-o {{.*}}/a-{{[a-z0-9]+}}.o -o {{.*}}/b-{{[a-z0-9]+}}.o -o {{.*}}/c-{{[a-z0-9]+}}.o

0 commit comments

Comments
 (0)