Skip to content

[Batch mode] Warn the user if -enable-batch-mode gets overridden by -whole-module-optimization or -index-file. #15578

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
merged 1 commit into from
Mar 29, 2018
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: 3 additions & 0 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ WARNING(warn_opt_remark_disabled, none,
"requires a single compiler invocation: consider enabling the "
"-whole-module-optimization flag", ())

WARNING(warn_ignoring_batch_mode,none,
"ignoring '-enable-batch-mode' because '%0' was also specified", (StringRef))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG
Expand Down
9 changes: 9 additions & 0 deletions include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class Driver {
///
/// \param TC The current tool chain.
/// \param Args The input arguments.
/// \param BatchMode Whether the driver has been explicitly or implicitly
/// instructed to use batch mode.
/// \param Inputs The inputs to the driver.
/// \param[out] OI The OutputInfo in which to store the resulting output
/// information.
Expand Down Expand Up @@ -382,6 +384,13 @@ class Driver {
/// \param Args The arguments passed to the driver (excluding the path to the
/// driver)
void parseDriverKind(ArrayRef<const char *> Args);

/// Examine potentially conficting arguments and warn the user if
/// there is an actual conflict.
/// \param Args The input arguments.
/// \param Inputs The inputs to the driver.
OutputInfo::Mode computeCompilerMode(const llvm::opt::DerivedArgList &Args,
const InputFileList &Inputs) const;
};

} // end namespace driver
Expand Down
41 changes: 29 additions & 12 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,19 +1098,11 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
// By default, the driver does not link its output; this will be updated
// appropriately below if linking is required.

if (driverKind == DriverKind::Interactive) {
OI.CompilerMode = OutputInfo::Mode::Immediate;
if (Inputs.empty())
OI.CompilerMode = OutputInfo::Mode::REPL;
OI.CompilerOutputType = file_types::TY_Nothing;
OI.CompilerOutputType = driverKind == DriverKind::Interactive
? file_types::TY_Nothing
: file_types::TY_Object;

} else { // DriverKind::Batch
OI.CompilerMode = OutputInfo::Mode::StandardCompile;
if (Args.hasArg(options::OPT_whole_module_optimization,
options::OPT_index_file))
OI.CompilerMode = OutputInfo::Mode::SingleCompile;
OI.CompilerOutputType = file_types::TY_Object;
}
OI.CompilerMode = computeCompilerMode(Args, Inputs);

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

}

OutputInfo::Mode
Driver::computeCompilerMode(const DerivedArgList &Args,
const InputFileList &Inputs) const {

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

const Arg *ArgRequiringWMO = Args.getLastArg(
options::OPT_whole_module_optimization, options::OPT_index_file);

if (!ArgRequiringWMO)
return OutputInfo::Mode::StandardCompile;

// Test for -enable-batch-mode, rather than the BatchMode flag that is
// passed into the caller because the diagnostic is intended to warn against
// overriding *explicit* batch mode. No warning should be given if in batch
// mode by default.
if (Args.hasArg(options::OPT_enable_batch_mode))
Diags.diagnose(SourceLoc(), diag::warn_ignoring_batch_mode,
ArgRequiringWMO->getOption().getPrefixedName());

return OutputInfo::Mode::SingleCompile;
}

void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
const ToolChain &TC, const OutputInfo &OI,
const OutputFileMap *OFM,
Expand Down
14 changes: 14 additions & 0 deletions test/Driver/batch_mode_with_WMO_or_index.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %empty-directory(%t)
//
// RUN: %swiftc_driver -whole-module-optimization -enable-batch-mode %S/../Inputs/empty.swift -### 2>%t/stderr_WMO_batch | %FileCheck %s
// RUN: %swiftc_driver -enable-batch-mode -whole-module-optimization %S/../Inputs/empty.swift -### 2>%t/stderr_batch_WMO | %FileCheck %s
// CHECK-NOT: -primary-file
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_WMO_batch
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_batch_WMO
// CHECK-WMO: warning: ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified
//
// RUN: %swiftc_driver -index-file -enable-batch-mode %S/../Inputs/empty.swift -### 2>%t/stderr_index_batch | %FileCheck %s
// RUN: %swiftc_driver -enable-batch-mode -index-file %S/../Inputs/empty.swift -### 2>%t/stderr_batch_index | %FileCheck %s
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_index_batch
// RUN: %FileCheck -check-prefix CHECK-INDEX %s <%t/stderr_batch_index
// CHECK-INDEX: warning: ignoring '-enable-batch-mode' because '-index-file' was also specified