After we get the jobs, the compilation is going to peform them in its swift::driver::Compilation::performJobs method. This method calls through to the swfit::driver::Compilation::performJobsImpl.
/* /wtsc/swift/lib/Driver/Compilation.cpp */
...
int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
...
bool abnormalExit;
int result = performJobsImpl(abnormalExit, std::move(TQ));
...
return result;
}
...
And the swift::driver::Compilation::performJobsImpl will construct an instance of PerformJobState which is responsible to shedule, batch, and execute jobs.
/* /wtsc/swift/lib/Driver/Compilation.cpp */
...
int Compilation::performJobsImpl(bool &abnormalExit,
std::unique_ptr<TaskQueue> &&TQ) {
PerformJobsState State(*this, std::move(TQ));
State.runJobs();
...
return State.getResult();
}
...
Inside swift::driver::PerformJobsState::runJobs method, we can see it does schedule, batch, execute jobs step by step.
/* /wtsc/swift/lib/Driver/Compilation.cpp */
...
/// Schedule and run initial, additional, and batch jobs.
void runJobs() {
scheduleJobsBeforeBatching();
formBatchJobsAndAddPendingJobsToTaskQueue();
runTaskQueueToCompletion();
checkUnfinishedJobs();
}
...
Those steps ensure that each job invocations is executed in right order efficiently.