Skip to content

Commit 4023105

Browse files
authored
Merge pull request #17864 from CodaFi/friendship-ended-with-PerformJobsState
[NFC] Drop PerformJobsState as a friend class
2 parents 5cbb3f7 + 81e9a3f commit 4023105

File tree

2 files changed

+86
-54
lines changed

2 files changed

+86
-54
lines changed

include/swift/Driver/Compilation.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ enum class PreserveOnSignal : bool {
7474
};
7575

7676
class Compilation {
77-
friend class PerformJobsState;
78-
7977
public:
8078
/// The filelist threshold value to pass to ensure file lists are never used
8179
static const size_t NEVER_USE_FILELIST = SIZE_MAX;
@@ -246,6 +244,10 @@ class Compilation {
246244
return TheOutputInfo;
247245
}
248246

247+
DiagnosticEngine &getDiags() const {
248+
return Diags;
249+
}
250+
249251
UnwrappedArrayView<const Action> getActions() const {
250252
return llvm::makeArrayRef(Actions);
251253
}
@@ -299,14 +301,24 @@ class Compilation {
299301
ContinueBuildingAfterErrors = Value;
300302
}
301303

304+
bool getShowIncrementalBuildDecisions() const {
305+
return ShowIncrementalBuildDecisions;
306+
}
302307
void setShowsIncrementalBuildDecisions(bool value = true) {
303308
ShowIncrementalBuildDecisions = value;
304309
}
305310

311+
bool getShowJobLifecycle() const {
312+
return ShowJobLifecycle;
313+
}
306314
void setShowJobLifecycle(bool value = true) {
307315
ShowJobLifecycle = value;
308316
}
309317

318+
bool getShowDriverTimeCompilation() const {
319+
return ShowDriverTimeCompilation;
320+
}
321+
310322
size_t getFilelistThreshold() const {
311323
return FilelistThreshold;
312324
}
@@ -315,6 +327,22 @@ class Compilation {
315327
return Stats.get();
316328
}
317329

330+
OutputLevel getOutputLevel() const {
331+
return Level;
332+
}
333+
334+
unsigned getBatchSeed() const {
335+
return BatchSeed;
336+
}
337+
338+
llvm::sys::TimePoint<> getLastBuildTime() const {
339+
return LastBuildTime;
340+
}
341+
342+
Optional<unsigned> getBatchCount() const {
343+
return BatchCount;
344+
}
345+
318346
/// Requests the path to a file containing all input source files. This can
319347
/// be shared across jobs.
320348
///

lib/Driver/Compilation.cpp

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace driver {
231231
DriverTimers;
232232

233233
void noteBuilding(const Job *cmd, StringRef reason) {
234-
if (!Comp.ShowIncrementalBuildDecisions)
234+
if (!Comp.getShowIncrementalBuildDecisions())
235235
return;
236236
if (ScheduledCommands.count(cmd))
237237
return;
@@ -254,15 +254,15 @@ namespace driver {
254254
/// its inputs are in FinishedCommands.
255255
void scheduleCommandIfNecessaryAndPossible(const Job *Cmd) {
256256
if (ScheduledCommands.count(Cmd)) {
257-
if (Comp.ShowJobLifecycle) {
257+
if (Comp.getShowJobLifecycle()) {
258258
llvm::outs() << "Already scheduled: " << LogJob(Cmd) << "\n";
259259
}
260260
return;
261261
}
262262

263263
if (auto Blocking = findUnfinishedJob(Cmd->getInputs())) {
264264
BlockingCommands[Blocking].push_back(Cmd);
265-
if (Comp.ShowJobLifecycle) {
265+
if (Comp.getShowJobLifecycle()) {
266266
llvm::outs() << "Blocked by: " << LogJob(Blocking)
267267
<< ", now blocking jobs: "
268268
<< LogJobArray(BlockingCommands[Blocking]) << "\n";
@@ -283,28 +283,28 @@ namespace driver {
283283
void addPendingJobToTaskQueue(const Job *Cmd) {
284284
// FIXME: Failing here should not take down the whole process.
285285
bool success =
286-
writeFilelistIfNecessary(Cmd, *Comp.TranslatedArgs.get(), Comp.Diags);
286+
writeFilelistIfNecessary(Cmd, Comp.getArgs(), Comp.getDiags());
287287
assert(success && "failed to write filelist");
288288
(void)success;
289289

290290
assert(Cmd->getExtraEnvironment().empty() &&
291291
"not implemented for compilations with multiple jobs");
292-
if (Comp.ShowJobLifecycle)
292+
if (Comp.getShowJobLifecycle())
293293
llvm::outs() << "Added to TaskQueue: " << LogJob(Cmd) << "\n";
294294
TQ->addTask(Cmd->getExecutable(), Cmd->getArgumentsForTaskExecution(),
295295
llvm::None, (void *)Cmd);
296296
}
297297

298298
/// When a task finishes, check other Jobs that may be blocked.
299299
void markFinished(const Job *Cmd, bool Skipped=false) {
300-
if (Comp.ShowJobLifecycle) {
300+
if (Comp.getShowJobLifecycle()) {
301301
llvm::outs() << "Job "
302302
<< (Skipped ? "skipped" : "finished")
303303
<< ": " << LogJob(Cmd) << "\n";
304304
}
305305
FinishedCommands.insert(Cmd);
306-
if (Comp.Stats) {
307-
auto &D = Comp.Stats->getDriverCounters();
306+
if (auto *Stats = Comp.getStatsReporter()) {
307+
auto &D = Stats->getDriverCounters();
308308
if (Skipped)
309309
D.NumDriverJobsSkipped++;
310310
else
@@ -313,7 +313,7 @@ namespace driver {
313313
auto BlockedIter = BlockingCommands.find(Cmd);
314314
if (BlockedIter != BlockingCommands.end()) {
315315
auto AllBlocked = std::move(BlockedIter->second);
316-
if (Comp.ShowJobLifecycle) {
316+
if (Comp.getShowJobLifecycle()) {
317317
llvm::outs() << "Scheduling maybe-unblocked jobs: "
318318
<< LogJobArray(AllBlocked) << "\n";
319319
}
@@ -333,7 +333,7 @@ namespace driver {
333333
// TODO: properly handle task began.
334334
const Job *BeganCmd = (const Job *)Context;
335335

336-
if (Comp.ShowDriverTimeCompilation) {
336+
if (Comp.getShowDriverTimeCompilation()) {
337337
llvm::SmallString<128> TimerName;
338338
llvm::raw_svector_ostream OS(TimerName);
339339
OS << LogJob(BeganCmd);
@@ -345,7 +345,7 @@ namespace driver {
345345
DriverTimers[BeganCmd]->startTimer();
346346
}
347347

348-
switch (Comp.Level) {
348+
switch (Comp.getOutputLevel()) {
349349
case OutputLevel::Normal:
350350
break;
351351
// For command line or verbose output, print out each command as it
@@ -369,10 +369,10 @@ namespace driver {
369369
/// disable incremental logic and schedule all existing deferred commands.
370370
void
371371
dependencyLoadFailed(StringRef DependenciesFile, bool Warn=true) {
372-
if (Warn && Comp.ShowIncrementalBuildDecisions)
373-
Comp.Diags.diagnose(SourceLoc(),
374-
diag::warn_unable_to_load_dependencies,
375-
DependenciesFile);
372+
if (Warn && Comp.getShowIncrementalBuildDecisions())
373+
Comp.getDiags().diagnose(SourceLoc(),
374+
diag::warn_unable_to_load_dependencies,
375+
DependenciesFile);
376376
Comp.disableIncrementalBuild();
377377
for (const Job *Cmd : DeferredCommands)
378378
scheduleCommandIfNecessaryAndPossible(Cmd);
@@ -497,11 +497,11 @@ namespace driver {
497497
TaskFinishedResponse
498498
unpackAndFinishBatch(int ReturnCode, StringRef Output,
499499
StringRef Errors, const BatchJob *B) {
500-
if (Comp.ShowJobLifecycle)
500+
if (Comp.getShowJobLifecycle())
501501
llvm::outs() << "Batch job finished: " << LogJob(B) << "\n";
502502
auto res = TaskFinishedResponse::ContinueExecution;
503503
for (const Job *J : B->getCombinedJobs()) {
504-
if (Comp.ShowJobLifecycle)
504+
if (Comp.getShowJobLifecycle())
505505
llvm::outs() << " ==> Unpacked batch constituent finished: "
506506
<< LogJob(J) << "\n";
507507
auto r = taskFinished(
@@ -546,11 +546,11 @@ namespace driver {
546546

547547
if (Pid != llvm::sys::ProcessInfo::InvalidPid) {
548548

549-
if (Comp.ShowDriverTimeCompilation) {
549+
if (Comp.getShowDriverTimeCompilation()) {
550550
DriverTimers[FinishedCmd]->stopTimer();
551551
}
552552

553-
switch (Comp.Level) {
553+
switch (Comp.getOutputLevel()) {
554554
case OutputLevel::PrintJobs:
555555
// Only print the jobs, not the outputs
556556
break;
@@ -592,17 +592,18 @@ namespace driver {
592592

593593
if (!isa<CompileJobAction>(FinishedCmd->getSource()) ||
594594
ReturnCode != EXIT_FAILURE) {
595-
Comp.Diags.diagnose(SourceLoc(), diag::error_command_failed,
596-
FinishedCmd->getSource().getClassName(),
597-
ReturnCode);
595+
Comp.getDiags().diagnose(SourceLoc(), diag::error_command_failed,
596+
FinishedCmd->getSource().getClassName(),
597+
ReturnCode);
598598
}
599599

600600
// See how ContinueBuildingAfterErrors gets set up in Driver.cpp for
601601
// more info.
602-
assert((Comp.ContinueBuildingAfterErrors || !Comp.EnableBatchMode) &&
602+
assert((Comp.getContinueBuildingAfterErrors() ||
603+
!Comp.getBatchModeEnabled()) &&
603604
"batch mode diagnostics require ContinueBuildingAfterErrors");
604605

605-
return Comp.ContinueBuildingAfterErrors ?
606+
return Comp.getContinueBuildingAfterErrors() ?
606607
TaskFinishedResponse::ContinueExecution :
607608
TaskFinishedResponse::StopExecution;
608609
}
@@ -626,11 +627,11 @@ namespace driver {
626627
TaskProcessInformation ProcInfo) {
627628
const Job *SignalledCmd = (const Job *)Context;
628629

629-
if (Comp.ShowDriverTimeCompilation) {
630+
if (Comp.getShowDriverTimeCompilation()) {
630631
DriverTimers[SignalledCmd]->stopTimer();
631632
}
632633

633-
if (Comp.Level == OutputLevel::Parseable) {
634+
if (Comp.getOutputLevel() == OutputLevel::Parseable) {
634635
// Parseable output was requested.
635636
SignalledCmd->forEachContainedJobAndPID(Pid, [&](const Job *J,
636637
Job::PID P) {
@@ -644,17 +645,19 @@ namespace driver {
644645
llvm::errs() << Output;
645646
}
646647
if (!ErrorMsg.empty())
647-
Comp.Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
648-
ErrorMsg);
648+
Comp.getDiags().diagnose(SourceLoc(),
649+
diag::error_unable_to_execute_command,
650+
ErrorMsg);
649651

650652
if (Signal.hasValue()) {
651-
Comp.Diags.diagnose(SourceLoc(), diag::error_command_signalled,
652-
SignalledCmd->getSource().getClassName(),
653-
Signal.getValue());
653+
Comp.getDiags().diagnose(SourceLoc(), diag::error_command_signalled,
654+
SignalledCmd->getSource().getClassName(),
655+
Signal.getValue());
654656
} else {
655-
Comp.Diags.diagnose(SourceLoc(),
656-
diag::error_command_signalled_without_signal_number,
657-
SignalledCmd->getSource().getClassName());
657+
Comp.getDiags()
658+
.diagnose(SourceLoc(),
659+
diag::error_command_signalled_without_signal_number,
660+
SignalledCmd->getSource().getClassName());
658661
}
659662

660663
// Since the task signalled, unconditionally set result to -2.
@@ -666,9 +669,9 @@ namespace driver {
666669

667670
public:
668671
PerformJobsState(Compilation &Comp, std::unique_ptr<TaskQueue> &&TaskQueue)
669-
: Comp(Comp), ActualIncrementalTracer(Comp.Stats.get()),
672+
: Comp(Comp), ActualIncrementalTracer(Comp.getStatsReporter()),
670673
TQ(std::move(TaskQueue)) {
671-
if (Comp.ShowIncrementalBuildDecisions || Comp.Stats)
674+
if (Comp.getShowIncrementalBuildDecisions() || Comp.getStatsReporter())
672675
IncrementalTracer = &ActualIncrementalTracer;
673676
}
674677

@@ -747,7 +750,7 @@ namespace driver {
747750
for (StringRef dependency : DepGraph.getExternalDependencies()) {
748751
llvm::sys::fs::file_status depStatus;
749752
if (!llvm::sys::fs::status(dependency, depStatus))
750-
if (depStatus.getLastModificationTime() < Comp.LastBuildTime)
753+
if (depStatus.getLastModificationTime() < Comp.getLastBuildTime())
751754
continue;
752755

753756
// If the dependency has been modified since the oldest built file,
@@ -775,7 +778,7 @@ namespace driver {
775778
template <typename Container>
776779
void transferJobsToTaskQueue(Container &Cmds, StringRef Kind) {
777780
for (const Job *Cmd : Cmds) {
778-
if (Comp.ShowJobLifecycle)
781+
if (Comp.getShowJobLifecycle())
779782
llvm::outs() << "Adding " << Kind
780783
<< " job to task queue: "
781784
<< LogJob(Cmd) << "\n";
@@ -791,11 +794,11 @@ namespace driver {
791794
CommandSetVector &NonBatchable) {
792795
for (const Job *Cmd : PendingExecution) {
793796
if (Comp.getToolChain().jobIsBatchable(Comp, Cmd)) {
794-
if (Comp.ShowJobLifecycle)
797+
if (Comp.getShowJobLifecycle())
795798
llvm::outs() << "Batchable: " << LogJob(Cmd) << "\n";
796799
Batchable.insert(Cmd);
797800
} else {
798-
if (Comp.ShowJobLifecycle)
801+
if (Comp.getShowJobLifecycle())
799802
llvm::outs() << "Not batchable: " << LogJob(Cmd) << "\n";
800803
NonBatchable.insert(Cmd);
801804
}
@@ -810,7 +813,7 @@ namespace driver {
810813
std::vector<const Job *> const &Batch) {
811814
if (Batch.empty())
812815
return;
813-
if (Comp.ShowJobLifecycle)
816+
if (Comp.getShowJobLifecycle())
814817
llvm::outs() << "Forming batch job from "
815818
<< Batch.size() << " constituents\n";
816819
auto const &TC = Comp.getToolChain();
@@ -838,8 +841,8 @@ namespace driver {
838841
size_t FillCount = TargetSize + ((P < Remainder) ? 1 : 0);
839842
std::fill_n(std::back_inserter(PartitionIndex), FillCount, P);
840843
}
841-
if (Comp.BatchSeed != 0) {
842-
std::minstd_rand gen(Comp.BatchSeed);
844+
if (Comp.getBatchSeed() != 0) {
845+
std::minstd_rand gen(Comp.getBatchSeed());
843846
std::shuffle(PartitionIndex.begin(), PartitionIndex.end(), gen);
844847
}
845848
assert(PartitionIndex.size() == NumJobs);
@@ -851,7 +854,7 @@ namespace driver {
851854
/// nonzero value, pseudo-randomly (but determinstically and nearly-evenly).
852855
void partitionIntoBatches(std::vector<const Job *> Batchable,
853856
BatchPartition &Partition) {
854-
if (Comp.ShowJobLifecycle) {
857+
if (Comp.getShowJobLifecycle()) {
855858
llvm::outs() << "Found " << Batchable.size() << " batchable jobs\n";
856859
llvm::outs() << "Forming into " << Partition.size() << " batches\n";
857860
}
@@ -865,14 +868,14 @@ namespace driver {
865868
assert(Idx < Partition.size());
866869
std::vector<const Job*> &P = Partition[Idx];
867870
if (P.empty() || TC.jobsAreBatchCombinable(Comp, P[0], Cmd)) {
868-
if (Comp.ShowJobLifecycle)
871+
if (Comp.getShowJobLifecycle())
869872
llvm::outs() << "Adding " << LogJob(Cmd)
870873
<< " to batch " << Idx << '\n';
871874
P.push_back(Cmd);
872875
} else {
873876
// Strange but theoretically possible that we have a batchable job
874877
// that's not combinable with others; tack a new batch on for it.
875-
if (Comp.ShowJobLifecycle)
878+
if (Comp.getShowJobLifecycle())
876879
llvm::outs() << "Adding " << LogJob(Cmd)
877880
<< " to new batch " << Partition.size() << '\n';
878881
Partition.push_back(std::vector<const Job*>());
@@ -930,8 +933,8 @@ namespace driver {
930933
return;
931934
}
932935

933-
size_t NumPartitions = (Comp.BatchCount.hasValue() ?
934-
Comp.BatchCount.getValue() :
936+
size_t NumPartitions = (Comp.getBatchCount().hasValue() ?
937+
Comp.getBatchCount().getValue() :
935938
TQ->getNumberOfParallelTasks());
936939
CommandSetVector Batchable, NonBatchable;
937940
std::vector<const Job *> Batches;
@@ -984,8 +987,9 @@ namespace driver {
984987
// exit / signal (or else a poll failed); unfortunately the task
985988
// causing it was dropped on the floor and we have no way to recover
986989
// it here, so we report a very poor, generic error.
987-
Comp.Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
988-
"<unknown>");
990+
Comp.getDiags().diagnose(SourceLoc(),
991+
diag::error_unable_to_execute_command,
992+
"<unknown>");
989993
Result = -2;
990994
AnyAbnormalExit = true;
991995
return;
@@ -1008,7 +1012,7 @@ namespace driver {
10081012
// If we got here, all the queued and pending work we know about is
10091013
// done; mark anything still in deferred state as skipped.
10101014
for (const Job *Cmd : DeferredCommands) {
1011-
if (Comp.Level == OutputLevel::Parseable) {
1015+
if (Comp.getOutputLevel() == OutputLevel::Parseable) {
10121016
// Provide output indicating this command was skipped if parseable
10131017
// output was requested.
10141018
parseable_output::emitSkippedMessage(llvm::errs(), *Cmd);
@@ -1104,7 +1108,7 @@ namespace driver {
11041108

11051109
int getResult() {
11061110
if (Result == 0)
1107-
Result = Comp.Diags.hadAnyError();
1111+
Result = Comp.getDiags().hadAnyError();
11081112
return Result;
11091113
}
11101114

0 commit comments

Comments
 (0)