Skip to content

[Legacy Driver] Obsolete and remove batch compilation mode from the legacy driver #81569

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
Jun 17, 2025
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/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ 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))

WARNING(warn_ignoring_wmo, none,
"ignoring '-wmo' because '-dump-ast' was also specified", ())

Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ WARNING(warning_locale_path_not_found,none,
"translation is disabled", (StringRef))
WARNING(warning_cannot_find_locale_file,none,
"cannot find translations for '%0' at '%1': no such file", (StringRef, StringRef))
WARNING(warning_cannot_multithread_batch_mode,none,
"ignoring -num-threads argument; cannot multithread batch mode", ())
ERROR(error_cannot_explicit_interface_build_in_mode,none,
"'-explicit-interface-module-build' only supported when building a module from interface ('-compile-module-from-interface' or '-typecheck-module-from-interface')'", ())
ERROR(error_unsupported_option_argument,none,
Expand Down
38 changes: 3 additions & 35 deletions include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class Compilation {
DiagnosticEngine &Diags;

/// The ToolChain this Compilation was built with, that it may reuse to build
/// subsequent BatchJobs.
/// subsequent Jobs.
const ToolChain &TheToolChain;

/// The OutputInfo, which the Compilation stores a copy of upon
/// construction, and which it may use to build subsequent batch
/// construction, and which it may use to build subsequent
/// jobs itself.
OutputInfo TheOutputInfo;

Expand Down Expand Up @@ -167,22 +167,6 @@ class Compilation {
/// even if they returned an error status.
bool ContinueBuildingAfterErrors = false;

/// Indicates whether groups of parallel frontend jobs should be merged
/// together and run in composite "batch jobs" when possible, to reduce
/// redundant work.
const bool EnableBatchMode;

/// Provides a randomization seed to batch-mode partitioning, for debugging.
const unsigned BatchSeed;

/// Overrides parallelism level and \c BatchSizeLimit, sets exact
/// count of batches, if in batch-mode.
const std::optional<unsigned> BatchCount;

/// Overrides maximum batch size, if in batch-mode and not overridden
/// by \c BatchCount.
const std::optional<unsigned> BatchSizeLimit;

/// True if temporary files should not be deleted.
const bool SaveTemps;

Expand Down Expand Up @@ -244,10 +228,6 @@ class Compilation {
std::unique_ptr<llvm::opt::DerivedArgList> TranslatedArgs,
InputFileList InputsWithTypes,
size_t FilelistThreshold,
bool EnableBatchMode = false,
unsigned BatchSeed = 0,
std::optional<unsigned> BatchCount = std::nullopt,
std::optional<unsigned> BatchSizeLimit = std::nullopt,
bool SaveTemps = false,
bool ShowDriverTimeCompilation = false,
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
Expand Down Expand Up @@ -302,10 +282,6 @@ class Compilation {
return DerivedOutputFileMap;
}

bool getBatchModeEnabled() const {
return EnableBatchMode;
}

bool getContinueBuildingAfterErrors() const {
return ContinueBuildingAfterErrors;
}
Expand Down Expand Up @@ -352,14 +328,6 @@ class Compilation {
return Level;
}

unsigned getBatchSeed() const {
return BatchSeed;
}

std::optional<unsigned> getBatchCount() const { return BatchCount; }

std::optional<unsigned> getBatchSizeLimit() const { return BatchSizeLimit; }

/// Requests the path to a file containing all input source files. This can
/// be shared across jobs.
///
Expand Down Expand Up @@ -399,7 +367,7 @@ class Compilation {
/// Unfortunately the success or failure of a Swift compilation is currently
/// sensitive to the order in which files are processed, at least in terms of
/// the order of processing extensions (and likely other ways we haven't
/// discovered yet). So long as this is true, we need to make sure any batch
/// discovered yet). So long as this is true, we need to make sure any
/// job we build names its inputs in an order that's a subsequence of the
/// sequence of inputs the driver was initially invoked with.
///
Expand Down
24 changes: 3 additions & 21 deletions include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ class OutputInfo {
/// A compilation using a single frontend invocation without -primary-file.
SingleCompile,

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

/// Invoke the REPL
REPL,

Expand Down Expand Up @@ -171,7 +158,7 @@ class Driver {
/// allowable OutputInfo::Mode values.
enum class DriverKind {
Interactive, // swift
Batch, // swiftc
Standard, // swiftc
SILOpt, // sil-opt
SILFuncExtractor,// sil-func-extractor
SILNM, // sil-nm
Expand Down Expand Up @@ -313,14 +300,12 @@ 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.
void buildOutputInfo(const ToolChain &TC,
const llvm::opt::DerivedArgList &Args,
const bool BatchMode, const InputFileList &Inputs,
const InputFileList &Inputs,
OutputInfo &OI) const;

/// Construct the list of Actions to perform for the given arguments,
Expand Down Expand Up @@ -472,11 +457,8 @@ class Driver {
/// there is an actual conflict.
/// \param Args The input arguments.
/// \param Inputs The inputs to the driver.
/// \param BatchModeOut An out-parameter flag that indicates whether to
/// batch the jobs of the resulting \c Mode::StandardCompile compilation.
OutputInfo::Mode computeCompilerMode(const llvm::opt::DerivedArgList &Args,
const InputFileList &Inputs,
bool &BatchModeOut) const;
const InputFileList &Inputs) const;
};

} // end namespace driver
Expand Down
48 changes: 1 addition & 47 deletions include/swift/Driver/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ class Job {
StringRef Terminator = "\n") const;

/// Call the provided Callback with any Jobs (and their possibly-quasi-PIDs)
/// contained within this Job; if this job is not a BatchJob, just pass \c
/// this and the provided \p OSPid back to the Callback.
/// contained within this Job;
virtual void forEachContainedJobAndPID(
llvm::sys::procid_t OSPid,
llvm::function_ref<void(const Job *, Job::PID)> Callback) const {
Expand All @@ -411,51 +410,6 @@ class Job {
StringRef getFirstSwiftPrimaryInput() const;
};

/// A BatchJob comprises a _set_ of jobs, each of which is sufficiently similar
/// to the others that the whole set can be combined into a single subprocess
/// (and thus run potentially more-efficiently than running each Job in the set
/// individually).
///
/// Not all Jobs can be combined into a BatchJob: at present, only those Jobs
/// that come from CompileJobActions, and which otherwise have the exact same
/// input file list and arguments as one another, aside from their primary-file.
/// See ToolChain::jobsAreBatchCombinable for details.

class BatchJob : public Job {

/// The set of constituents making up the batch.
const SmallVector<const Job *, 4> CombinedJobs;

/// A negative number to use as the base value for assigning quasi-PID to Jobs
/// in the \c CombinedJobs array. Quasi-PIDs count _down_ from this value.
const Job::PID QuasiPIDBase;

public:
BatchJob(const JobAction &Source, SmallVectorImpl<const Job *> &&Inputs,
std::unique_ptr<CommandOutput> Output, const char *Executable,
llvm::opt::ArgStringList Arguments,
EnvironmentVector ExtraEnvironment, std::vector<FilelistInfo> Infos,
ArrayRef<const Job *> Combined, Job::PID &NextQuasiPID,
std::optional<ResponseFileInfo> ResponseFile = std::nullopt);

ArrayRef<const Job*> getCombinedJobs() const {
return CombinedJobs;
}

/// Call the provided callback for each Job in the batch, passing the
/// corresponding quasi-PID with each Job.
void forEachContainedJobAndPID(
llvm::sys::procid_t OSPid,
llvm::function_ref<void(const Job *, Job::PID)> Callback) const override {
Job::PID QPid = QuasiPIDBase;
assert(QPid < 0);
for (auto const *J : CombinedJobs) {
assert(QPid != std::numeric_limits<Job::PID>::min());
Callback(J, QPid--);
}
}
};

} // end namespace driver
} // end namespace swift

Expand Down
29 changes: 1 addition & 28 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ToolChain {
bool shouldUseSupplementaryOutputFileMapInFrontendInvocation() const;

/// Reify the existing behavior that SingleCompile compile actions do not
/// filter, but batch-mode and single-file compilations do. Some clients are
/// filter, single-file compilations do. Some clients are
/// relying on this (i.e., they pass inputs that don't have ".swift" as an
/// extension.) It would be nice to eliminate this distinction someday.
bool shouldFilterFrontendInputsByType() const;
Expand Down Expand Up @@ -281,33 +281,6 @@ class ToolChain {
std::unique_ptr<CommandOutput> output,
const OutputInfo &OI) const;

/// Return true iff the input \c Job \p A is an acceptable candidate for
/// batching together into a BatchJob, via a call to \c
/// constructBatchJob. This is true when the \c Job is a built from a \c
/// CompileJobAction in a \c Compilation \p C running in \c
/// OutputInfo::Mode::StandardCompile output mode, with a single \c TY_Swift
/// \c InputAction.
bool jobIsBatchable(const Compilation &C, const Job *A) const;

/// Equivalence relation that holds iff the two input Jobs \p A and \p B are
/// acceptable candidates for combining together into a \c BatchJob, via a
/// call to \c constructBatchJob. This is true when each job independently
/// satisfies \c jobIsBatchable, and the two jobs have identical executables,
/// output types and environments (i.e. they are identical aside from their
/// inputs).
bool jobsAreBatchCombinable(const Compilation &C, const Job *A,
const Job *B) const;

/// Construct a \c BatchJob that subsumes the work of a set of Jobs. Any pair
/// of elements in \p Jobs are assumed to satisfy the equivalence relation \c
/// jobsAreBatchCombinable, i.e. they should all be "the same" job in in all
/// ways other than their choices of inputs. The provided \p NextQuasiPID
/// should be a negative number that persists between calls; this method will
/// decrement it to assign quasi-PIDs to each of the \p Jobs passed.
std::unique_ptr<Job> constructBatchJob(ArrayRef<const Job *> Jobs,
int64_t &NextQuasiPID,
Compilation &C) const;

/// Return the default language type to use for the given extension.
/// If the extension is empty or is otherwise not recognized, return
/// the invalid type \c TY_INVALID.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def ModuleWrapOption : OptionFlag;
def NoDriverOption : OptionFlag;

// Some options should not be available depending on whether this is the
// interactive driver 'swift', or the batch compiler 'swiftc'.
// interactive driver 'swift', or the aot compiler 'swiftc'.
def NoInteractiveOption : OptionFlag;
def NoBatchOption : OptionFlag;

Expand Down
Loading