@@ -688,7 +688,6 @@ namespace driver {
688
688
NonBatchable.insert (Cmd);
689
689
}
690
690
}
691
- PendingExecution.clear ();
692
691
}
693
692
694
693
// / If \p Batch is nonempty, construct a new \c BatchJob from its
@@ -770,6 +769,30 @@ namespace driver {
770
769
}
771
770
}
772
771
772
+ // FIXME: at the moment we're not passing OutputFileMaps to frontends, so
773
+ // due to the multiplication of the number of additional files and the
774
+ // number of files in a batch, it's pretty easy to construct too-long
775
+ // command lines here, which will then fail to exec. We address this crudely
776
+ // by re-forming batches with a finer partition when we overflow.
777
+ bool shouldRetryWithMorePartitions (std::vector<const Job *> const &Batches,
778
+ size_t &NumPartitions) {
779
+
780
+ // Stop rebatching if we can't subdivide batches any further.
781
+ if (NumPartitions > PendingExecution.size ())
782
+ return false ;
783
+
784
+ for (auto const *B : Batches) {
785
+ if (!llvm::sys::commandLineFitsWithinSystemLimits (B->getExecutable (),
786
+ B->getArguments ())) {
787
+ // To avoid redoing the batch loop too many times, repartition pretty
788
+ // aggressively by doubling partition count / halving size.
789
+ NumPartitions *= 2 ;
790
+ return true ;
791
+ }
792
+ }
793
+ return false ;
794
+ }
795
+
773
796
// / Select jobs that are batch-combinable from \c PendingExecution, combine
774
797
// / them together into \p BatchJob instances (also inserted into \p
775
798
// / BatchJobs), and enqueue all \c PendingExecution jobs (whether batched or
@@ -783,19 +806,29 @@ namespace driver {
783
806
return ;
784
807
}
785
808
786
- // Split the batchable from non-batchable pending jobs.
809
+ size_t NumPartitions = Comp. NumberOfParallelCommands ;
787
810
CommandSetVector Batchable, NonBatchable;
788
- getPendingBatchableJobs (Batchable, NonBatchable);
811
+ std::vector<const Job *> Batches;
812
+ do {
813
+ // We might be restarting loop; clear these before proceeding.
814
+ Batchable.clear ();
815
+ NonBatchable.clear ();
816
+ Batches.clear ();
789
817
790
- // Partition the batchable jobs into sets.
791
- BatchPartition Partition (Comp.NumberOfParallelCommands );
792
- partitionIntoBatches (Batchable.takeVector (), Partition);
818
+ // Split the batchable from non-batchable pending jobs.
819
+ getPendingBatchableJobs (Batchable, NonBatchable);
793
820
794
- // Construct a BatchJob from each batch in the partition.
795
- std::vector<const Job *> Batches;
796
- for (auto const &Batch : Partition) {
797
- formBatchJobFromPartitionBatch (Batches, Batch);
798
- }
821
+ // Partition the batchable jobs into sets.
822
+ BatchPartition Partition (NumPartitions);
823
+ partitionIntoBatches (Batchable.takeVector (), Partition);
824
+
825
+ // Construct a BatchJob from each batch in the partition.
826
+ for (auto const &Batch : Partition) {
827
+ formBatchJobFromPartitionBatch (Batches, Batch);
828
+ }
829
+
830
+ } while (shouldRetryWithMorePartitions (Batches, NumPartitions));
831
+ PendingExecution.clear ();
799
832
800
833
// Save batches so we can locate and decompose them on task-exit.
801
834
for (const Job *Cmd : Batches)
@@ -810,15 +843,29 @@ namespace driver {
810
843
do {
811
844
using namespace std ::placeholders;
812
845
// Ask the TaskQueue to execute.
813
- TQ->execute (std::bind (&PerformJobsState::taskBegan, this ,
814
- _1, _2),
815
- std::bind (&PerformJobsState::taskFinished, this ,
816
- _1, _2, _3, _4, _5),
817
- std::bind (&PerformJobsState::taskSignalled, this ,
818
- _1, _2, _3, _4, _5, _6));
819
-
820
- // Returning from TaskQueue::execute should mean either an empty
821
- // TaskQueue or a failed subprocess.
846
+ if (TQ->execute (std::bind (&PerformJobsState::taskBegan, this ,
847
+ _1, _2),
848
+ std::bind (&PerformJobsState::taskFinished, this ,
849
+ _1, _2, _3, _4, _5),
850
+ std::bind (&PerformJobsState::taskSignalled, this ,
851
+ _1, _2, _3, _4, _5, _6))) {
852
+ if (Result == EXIT_SUCCESS) {
853
+ // FIXME: Error from task queue while Result == EXIT_SUCCESS most
854
+ // likely means some fork/exec or posix_spawn failed; TaskQueue saw
855
+ // "an error" at some stage before even calling us with a process
856
+ // exit / signal (or else a poll failed); unfortunately the task
857
+ // causing it was dropped on the floor and we have no way to recover
858
+ // it here, so we report a very poor, generic error.
859
+ Comp.Diags .diagnose (SourceLoc (), diag::error_unable_to_execute_command,
860
+ " <unknown>" );
861
+ Result = -2 ;
862
+ AnyAbnormalExit = true ;
863
+ return ;
864
+ }
865
+ }
866
+
867
+ // Returning without error from TaskQueue::execute should mean either an
868
+ // empty TaskQueue or a failed subprocess.
822
869
assert (!(Result == 0 && TQ->hasRemainingTasks ()));
823
870
824
871
// Task-exit callbacks from TaskQueue::execute may have unblocked jobs,
0 commit comments