Skip to content

Commit f05be88

Browse files
authored
Merge pull request #19802 from graydon/rdar-43955209-breaking-up-is-hard-to-do
[Driver] <rdar://43955209> Remove obsolete/fragile batch mode 'repartitioning' code.
2 parents 3b96d21 + 29fa909 commit f05be88

File tree

7 files changed

+21
-107
lines changed

7 files changed

+21
-107
lines changed

include/swift/Driver/Compilation.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ class Compilation {
180180
/// by \c BatchCount.
181181
const Optional<unsigned> BatchSizeLimit;
182182

183-
/// In order to test repartitioning, set to true if
184-
/// -driver-force-one-batch-repartition is present.
185-
const bool ForceOneBatchRepartition = false;
186-
187183
/// True if temporary files should not be deleted.
188184
const bool SaveTemps;
189185

@@ -236,7 +232,6 @@ class Compilation {
236232
unsigned BatchSeed = 0,
237233
Optional<unsigned> BatchCount = None,
238234
Optional<unsigned> BatchSizeLimit = None,
239-
bool ForceOneBatchRepartition = false,
240235
bool SaveTemps = false,
241236
bool ShowDriverTimeCompilation = false,
242237
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr);
@@ -298,8 +293,6 @@ class Compilation {
298293
return EnableBatchMode;
299294
}
300295

301-
bool getForceOneBatchRepartition() const { return ForceOneBatchRepartition; }
302-
303296
bool getContinueBuildingAfterErrors() const {
304297
return ContinueBuildingAfterErrors;
305298
}

include/swift/Option/Options.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ def driver_batch_count : Separate<["-"], "driver-batch-count">,
116116
def driver_batch_size_limit : Separate<["-"], "driver-batch-size-limit">,
117117
InternalDebugOpt,
118118
HelpText<"Use the given number as the upper limit on dynamic batch-mode partition size">;
119-
def driver_force_one_batch_repartition : Flag<["-"], "driver-force-one-batch-repartition">,
120-
InternalDebugOpt,
121-
HelpText<"Force one batch repartitioning for testing">;
122119

123120
def driver_force_response_files : Flag<["-"], "driver-force-response-files">,
124121
InternalDebugOpt,

lib/Driver/Compilation.cpp

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ Compilation::Compilation(DiagnosticEngine &Diags,
115115
unsigned BatchSeed,
116116
Optional<unsigned> BatchCount,
117117
Optional<unsigned> BatchSizeLimit,
118-
bool ForceOneBatchRepartition,
119118
bool SaveTemps,
120119
bool ShowDriverTimeCompilation,
121120
std::unique_ptr<UnifiedStatsReporter> StatsReporter)
@@ -136,7 +135,6 @@ Compilation::Compilation(DiagnosticEngine &Diags,
136135
BatchSeed(BatchSeed),
137136
BatchCount(BatchCount),
138137
BatchSizeLimit(BatchSizeLimit),
139-
ForceOneBatchRepartition(ForceOneBatchRepartition),
140138
SaveTemps(SaveTemps),
141139
ShowDriverTimeCompilation(ShowDriverTimeCompilation),
142140
Stats(std::move(StatsReporter)),
@@ -886,42 +884,6 @@ namespace driver {
886884
});
887885
}
888886

889-
// Due to the multiplication of the number of additional files and the
890-
// number of files in a batch, it's pretty easy to construct too-long
891-
// command lines here, which will then fail to exec. We address this crudely
892-
// by re-forming batches with a finer partition when we overflow.
893-
//
894-
// Now that we're passing OutputFileMaps to frontends, this should never
895-
// happen, but keep this as insurance, because the decision to pass output
896-
// file maps cannot know the exact length of the command line, so may
897-
// possibly fail to use the OutputFileMap.
898-
//
899-
// In order to be able to exercise as much of the code paths as possible,
900-
// take a flag to force a retry, but only once.
901-
bool shouldRetryWithMorePartitions(std::vector<const Job *> const &Batches,
902-
bool &PretendTheCommandLineIsTooLongOnce,
903-
size_t &NumPartitions) {
904-
905-
// Stop rebatching if we can't subdivide batches any further.
906-
if (NumPartitions > PendingExecution.size())
907-
return false;
908-
909-
for (auto const *B : Batches) {
910-
if (!llvm::sys::commandLineFitsWithinSystemLimits(B->getExecutable(),
911-
B->getArguments()) ||
912-
PretendTheCommandLineIsTooLongOnce) {
913-
PretendTheCommandLineIsTooLongOnce = false;
914-
// To avoid redoing the batch loop too many times, repartition pretty
915-
// aggressively by doubling partition count / halving size.
916-
NumPartitions *= 2;
917-
LLVM_DEBUG(llvm::dbgs()
918-
<< "Should have used a supplementary output file map.\n");
919-
return true;
920-
}
921-
}
922-
return false;
923-
}
924-
925887
// Selects the number of partitions based on the user-provided batch
926888
// count and/or the number of parallel tasks we can run, subject to a
927889
// fixed per-batch safety cap, to avoid overcommitting memory.
@@ -1049,28 +1011,19 @@ namespace driver {
10491011
size_t NumPartitions = pickNumberOfPartitions();
10501012
CommandSetVector Batchable, NonBatchable;
10511013
std::vector<const Job *> Batches;
1052-
bool PretendTheCommandLineIsTooLongOnce =
1053-
Comp.getForceOneBatchRepartition();
1054-
do {
1055-
// We might be restarting loop; clear these before proceeding.
1056-
Batchable.clear();
1057-
NonBatchable.clear();
1058-
Batches.clear();
10591014

1060-
// Split the batchable from non-batchable pending jobs.
1061-
getPendingBatchableJobs(Batchable, NonBatchable);
1015+
// Split the batchable from non-batchable pending jobs.
1016+
getPendingBatchableJobs(Batchable, NonBatchable);
10621017

1063-
// Partition the batchable jobs into sets.
1064-
BatchPartition Partition(NumPartitions);
1065-
partitionIntoBatches(Batchable.takeVector(), Partition);
1018+
// Partition the batchable jobs into sets.
1019+
BatchPartition Partition(NumPartitions);
1020+
partitionIntoBatches(Batchable.takeVector(), Partition);
10661021

1067-
// Construct a BatchJob from each batch in the partition.
1068-
for (auto const &Batch : Partition) {
1069-
formBatchJobFromPartitionBatch(Batches, Batch);
1070-
}
1022+
// Construct a BatchJob from each batch in the partition.
1023+
for (auto const &Batch : Partition) {
1024+
formBatchJobFromPartitionBatch(Batches, Batch);
1025+
}
10711026

1072-
} while (shouldRetryWithMorePartitions(
1073-
Batches, PretendTheCommandLineIsTooLongOnce, NumPartitions));
10741027
PendingExecution.clear();
10751028

10761029
// Save batches so we can locate and decompose them on task-exit.

lib/Driver/Driver.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,6 @@ Driver::buildCompilation(const ToolChain &TC,
915915
const Optional<unsigned> DriverBatchCount = getDriverBatchCount(*ArgList, Diags);
916916
const Optional<unsigned> DriverBatchSizeLimit =
917917
getDriverBatchSizeLimit(*ArgList, Diags);
918-
const bool DriverForceOneBatchRepartition =
919-
ArgList->hasArg(options::OPT_driver_force_one_batch_repartition);
920918
const bool SaveTemps = ArgList->hasArg(options::OPT_save_temps);
921919
const bool ShowDriverTimeCompilation =
922920
ArgList->hasArg(options::OPT_driver_time_compilation);
@@ -939,7 +937,6 @@ Driver::buildCompilation(const ToolChain &TC,
939937
DriverBatchSeed,
940938
DriverBatchCount,
941939
DriverBatchSizeLimit,
942-
DriverForceOneBatchRepartition,
943940
SaveTemps,
944941
ShowDriverTimeCompilation,
945942
std::move(StatsReporter));

lib/Driver/ToolChain.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@ ToolChain::constructBatchJob(ArrayRef<const Job *> unsortedJobs,
344344
JobContext context{C, inputJobs.getArrayRef(), inputActions.getArrayRef(),
345345
*output, OI};
346346
auto invocationInfo = constructInvocation(*batchCJA, context);
347+
// Batch mode can produce quite long command lines; in almost every case these
348+
// will trigger use of supplementary output file maps, but in some rare corner
349+
// cases (very few files, very long paths) they might not. However, in those
350+
// cases we _should_ degrade to using response files to pass arguments to the
351+
// frontend, which is done automatically by code elsewhere.
352+
//
353+
// The `allowsResponseFiles` flag on the `invocationInfo` we have here exists
354+
// only to model external tools that don't know about response files, such as
355+
// platform linkers; when talking to the frontend (which we control!) it
356+
// should always be true. But double check with an assert here in case someone
357+
// failed to set it in `constructInvocation`.
358+
assert(invocationInfo.allowsResponseFiles);
347359
return llvm::make_unique<BatchJob>(
348360
*batchCJA, inputJobs.takeVector(), std::move(output), executablePath,
349361
std::move(invocationInfo.Arguments),

test/Driver/batch_mode_force_one_batch_repartition.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

validation-test/Driver/batch_mode_overlong_argv.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)