Skip to content

Commit a055d46

Browse files
author
David Ungar
authored
Merge pull request #15578 from davidungar/PR-19-warn-WMO-batch
[Batch mode] Warn the user if -enable-batch-mode gets overridden by -whole-module-optimization or -index-file.
2 parents 683fb47 + 43b8913 commit a055d46

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ WARNING(warn_opt_remark_disabled, none,
141141
"requires a single compiler invocation: consider enabling the "
142142
"-whole-module-optimization flag", ())
143143

144+
WARNING(warn_ignoring_batch_mode,none,
145+
"ignoring '-enable-batch-mode' because '%0' was also specified", (StringRef))
146+
144147
#ifndef DIAG_NO_UNDEF
145148
# if defined(DIAG)
146149
# undef DIAG

include/swift/Driver/Driver.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ class Driver {
237237
///
238238
/// \param TC The current tool chain.
239239
/// \param Args The input arguments.
240+
/// \param BatchMode Whether the driver has been explicitly or implicitly
241+
/// instructed to use batch mode.
240242
/// \param Inputs The inputs to the driver.
241243
/// \param[out] OI The OutputInfo in which to store the resulting output
242244
/// information.
@@ -382,6 +384,13 @@ class Driver {
382384
/// \param Args The arguments passed to the driver (excluding the path to the
383385
/// driver)
384386
void parseDriverKind(ArrayRef<const char *> Args);
387+
388+
/// Examine potentially conficting arguments and warn the user if
389+
/// there is an actual conflict.
390+
/// \param Args The input arguments.
391+
/// \param Inputs The inputs to the driver.
392+
OutputInfo::Mode computeCompilerMode(const llvm::opt::DerivedArgList &Args,
393+
const InputFileList &Inputs) const;
385394
};
386395

387396
} // end namespace driver

lib/Driver/Driver.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,19 +1098,11 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
10981098
// By default, the driver does not link its output; this will be updated
10991099
// appropriately below if linking is required.
11001100

1101-
if (driverKind == DriverKind::Interactive) {
1102-
OI.CompilerMode = OutputInfo::Mode::Immediate;
1103-
if (Inputs.empty())
1104-
OI.CompilerMode = OutputInfo::Mode::REPL;
1105-
OI.CompilerOutputType = file_types::TY_Nothing;
1101+
OI.CompilerOutputType = driverKind == DriverKind::Interactive
1102+
? file_types::TY_Nothing
1103+
: file_types::TY_Object;
11061104

1107-
} else { // DriverKind::Batch
1108-
OI.CompilerMode = OutputInfo::Mode::StandardCompile;
1109-
if (Args.hasArg(options::OPT_whole_module_optimization,
1110-
options::OPT_index_file))
1111-
OI.CompilerMode = OutputInfo::Mode::SingleCompile;
1112-
OI.CompilerOutputType = file_types::TY_Object;
1113-
}
1105+
OI.CompilerMode = computeCompilerMode(Args, Inputs);
11141106

11151107
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) {
11161108
if (BatchMode) {
@@ -1379,6 +1371,31 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13791371

13801372
}
13811373

1374+
OutputInfo::Mode
1375+
Driver::computeCompilerMode(const DerivedArgList &Args,
1376+
const InputFileList &Inputs) const {
1377+
1378+
if (driverKind == Driver::DriverKind::Interactive)
1379+
return Inputs.empty() ? OutputInfo::Mode::REPL
1380+
: OutputInfo::Mode::Immediate;
1381+
1382+
const Arg *ArgRequiringWMO = Args.getLastArg(
1383+
options::OPT_whole_module_optimization, options::OPT_index_file);
1384+
1385+
if (!ArgRequiringWMO)
1386+
return OutputInfo::Mode::StandardCompile;
1387+
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))
1393+
Diags.diagnose(SourceLoc(), diag::warn_ignoring_batch_mode,
1394+
ArgRequiringWMO->getOption().getPrefixedName());
1395+
1396+
return OutputInfo::Mode::SingleCompile;
1397+
}
1398+
13821399
void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
13831400
const ToolChain &TC, const OutputInfo &OI,
13841401
const OutputFileMap *OFM,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: %swiftc_driver -whole-module-optimization -enable-batch-mode %S/../Inputs/empty.swift -### 2>%t/stderr_WMO_batch | %FileCheck %s
4+
// RUN: %swiftc_driver -enable-batch-mode -whole-module-optimization %S/../Inputs/empty.swift -### 2>%t/stderr_batch_WMO | %FileCheck %s
5+
// CHECK-NOT: -primary-file
6+
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_WMO_batch
7+
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_batch_WMO
8+
// CHECK-WMO: warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
9+
//
10+
// RUN: %swiftc_driver -index-file -enable-batch-mode %S/../Inputs/empty.swift -### 2>%t/stderr_index_batch | %FileCheck %s
11+
// RUN: %swiftc_driver -enable-batch-mode -index-file %S/../Inputs/empty.swift -### 2>%t/stderr_batch_index | %FileCheck %s
12+
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_index_batch
13+
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_batch_index
14+
// CHECK-INDEX: warning: ignoring '-enable-batch-mode' because '-index-file' was also specified

0 commit comments

Comments
 (0)