Skip to content

Commit 22d7c3c

Browse files
authored
Merge pull request #15754 from graydon/rdar-39191323-batch-mode-flag-double-vision-swift-4.2-branch
2 parents 803224c + d5d7670 commit 22d7c3c

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-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
@@ -551,10 +551,6 @@ Driver::buildCompilation(const ToolChain &TC,
551551
Incremental = false;
552552
}
553553

554-
bool BatchMode = ArgList->hasFlag(options::OPT_enable_batch_mode,
555-
options::OPT_disable_batch_mode,
556-
false);
557-
558554
bool SaveTemps = ArgList->hasArg(options::OPT_save_temps);
559555
bool ContinueBuildingAfterErrors =
560556
ArgList->hasArg(options::OPT_continue_building_after_errors);
@@ -588,6 +584,8 @@ Driver::buildCompilation(const ToolChain &TC,
588584

589585
// Determine the OutputInfo for the driver.
590586
OutputInfo OI;
587+
bool BatchMode = false;
588+
OI.CompilerMode = computeCompilerMode(*TranslatedArgList, Inputs, BatchMode);
591589
buildOutputInfo(TC, *TranslatedArgList, BatchMode, Inputs, OI);
592590

593591
if (Diags.hadAnyError())
@@ -1102,8 +1100,6 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
11021100
? file_types::TY_Nothing
11031101
: file_types::TY_Object;
11041102

1105-
OI.CompilerMode = computeCompilerMode(Args, Inputs);
1106-
11071103
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) {
11081104
if (BatchMode) {
11091105
Diags.diagnose(SourceLoc(), diag::warning_cannot_multithread_batch_mode);
@@ -1373,26 +1369,31 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13731369

13741370
OutputInfo::Mode
13751371
Driver::computeCompilerMode(const DerivedArgList &Args,
1376-
const InputFileList &Inputs) const {
1372+
const InputFileList &Inputs,
1373+
bool &BatchModeOut) const {
13771374

13781375
if (driverKind == Driver::DriverKind::Interactive)
13791376
return Inputs.empty() ? OutputInfo::Mode::REPL
13801377
: OutputInfo::Mode::Immediate;
13811378

1382-
const Arg *ArgRequiringWMO = Args.getLastArg(
1379+
const Arg *ArgRequiringSingleCompile = Args.getLastArg(
13831380
options::OPT_whole_module_optimization, options::OPT_index_file);
13841381

1385-
if (!ArgRequiringWMO)
1382+
BatchModeOut = Args.hasFlag(options::OPT_enable_batch_mode,
1383+
options::OPT_disable_batch_mode,
1384+
false);
1385+
1386+
if (!ArgRequiringSingleCompile)
13861387
return OutputInfo::Mode::StandardCompile;
13871388

1388-
// Test for -enable-batch-mode, rather than the BatchMode flag that is
1389-
// passed into the caller because the diagnostic is intended to warn against
1390-
// overriding *explicit* batch mode. No warning should be given if in batch
1391-
// mode by default.
1392-
if (Args.hasArg(options::OPT_enable_batch_mode))
1389+
// Override batch mode if given -wmo or -index-file.
1390+
if (BatchModeOut) {
1391+
BatchModeOut = false;
1392+
// Emit a warning about such overriding (FIXME: we might conditionalize
1393+
// this based on the user or xcode passing -disable-batch-mode).
13931394
Diags.diagnose(SourceLoc(), diag::warn_ignoring_batch_mode,
1394-
ArgRequiringWMO->getOption().getPrefixedName());
1395-
1395+
ArgRequiringSingleCompile->getOption().getPrefixedName());
1396+
}
13961397
return OutputInfo::Mode::SingleCompile;
13971398
}
13981399

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

validation-test/compiler_crashers/28869-swift-diagnosticengine-formatdiagnostictext-llvm-raw-ostream-llvm-stringref-llvm.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// REQUIRES: rdar38932729
910
protocol A:A&CLong

0 commit comments

Comments
 (0)