-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Rdar 40526328 emit sigint for cancelled batch constituents #17167
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
swift-ci
merged 2 commits into
swiftlang:master
from
graydon:rdar-40526328-emit-SIGINT-for-cancelled-batch-constituents
Jun 14, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ | |
|
||
#include "CompilationRecord.h" | ||
|
||
#include <signal.h> | ||
|
||
#define DEBUG_TYPE "batch-mode" | ||
|
||
// Batch-mode has a sub-mode for testing that randomizes batch partitions, | ||
|
@@ -111,6 +113,7 @@ Compilation::Compilation(DiagnosticEngine &Diags, | |
bool EnableIncrementalBuild, | ||
bool EnableBatchMode, | ||
unsigned BatchSeed, | ||
Optional<unsigned> BatchCount, | ||
bool ForceOneBatchRepartition, | ||
bool SaveTemps, | ||
bool ShowDriverTimeCompilation, | ||
|
@@ -130,6 +133,7 @@ Compilation::Compilation(DiagnosticEngine &Diags, | |
OutputCompilationRecordForModuleOnlyBuild), | ||
EnableBatchMode(EnableBatchMode), | ||
BatchSeed(BatchSeed), | ||
BatchCount(BatchCount), | ||
ForceOneBatchRepartition(ForceOneBatchRepartition), | ||
SaveTemps(SaveTemps), | ||
ShowDriverTimeCompilation(ShowDriverTimeCompilation), | ||
|
@@ -456,6 +460,35 @@ namespace driver { | |
} | ||
} | ||
|
||
/// Check to see if a job produced a zero-length serialized diagnostics | ||
/// file, which is used to indicate batch-constituents that were batched | ||
/// together with a failing constituent but did not, themselves, produce any | ||
/// errors. | ||
bool jobWasBatchedWithFailingJobs(const Job *J) const { | ||
auto DiaPath = | ||
J->getOutput().getAnyOutputForType(file_types::TY_SerializedDiagnostics); | ||
if (DiaPath.empty()) | ||
return false; | ||
if (!llvm::sys::fs::is_regular_file(DiaPath)) | ||
return false; | ||
uint64_t Size; | ||
auto EC = llvm::sys::fs::file_size(DiaPath, Size); | ||
if (EC) | ||
return false; | ||
return Size == 0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for rearranging. I like the way this came out, hope you do, too. |
||
|
||
/// If a batch-constituent job happens to be batched together with a job | ||
/// that exits with an error, the batch-constituent may be considered | ||
/// "cancelled". | ||
bool jobIsCancelledBatchConstituent(int ReturnCode, | ||
const Job *ContainerJob, | ||
const Job *ConstituentJob) { | ||
return ReturnCode != 0 && | ||
isBatchJob(ContainerJob) && | ||
jobWasBatchedWithFailingJobs(ConstituentJob); | ||
} | ||
|
||
/// Unpack a \c BatchJob that has finished into its constituent \c Job | ||
/// members, and call \c taskFinished on each, propagating any \c | ||
/// TaskFinishedResponse other than \c | ||
|
@@ -481,6 +514,27 @@ namespace driver { | |
return res; | ||
} | ||
|
||
void | ||
emitParseableOutputForEachFinishedJob(ProcessId Pid, int ReturnCode, | ||
StringRef Output, | ||
const Job *FinishedCmd, | ||
TaskProcessInformation ProcInfo) { | ||
FinishedCmd->forEachContainedJobAndPID(Pid, [&](const Job *J, | ||
Job::PID P) { | ||
if (jobIsCancelledBatchConstituent(ReturnCode, FinishedCmd, J)) { | ||
// Simulate SIGINT-interruption to parseable-output consumer for any | ||
// constituent of a failing batch job that produced no errors of its | ||
// own. | ||
parseable_output::emitSignalledMessage(llvm::errs(), *J, P, | ||
"cancelled batch constituent", | ||
"", SIGINT, ProcInfo); | ||
} else { | ||
parseable_output::emitFinishedMessage(llvm::errs(), *J, P, ReturnCode, | ||
Output, ProcInfo); | ||
} | ||
}); | ||
} | ||
|
||
/// Callback which will be called immediately after a task has finished | ||
/// execution. Determines if execution should continue, and also schedule | ||
/// any additional Jobs which we now know we need to run. | ||
|
@@ -508,12 +562,8 @@ namespace driver { | |
llvm::errs() << Output; | ||
break; | ||
case OutputLevel::Parseable: | ||
// Parseable output was requested. | ||
FinishedCmd->forEachContainedJobAndPID(Pid, [&](const Job *J, | ||
Job::PID P) { | ||
parseable_output::emitFinishedMessage(llvm::errs(), *J, P, | ||
ReturnCode, Output, ProcInfo); | ||
}); | ||
emitParseableOutputForEachFinishedJob(Pid, ReturnCode, Output, | ||
FinishedCmd, ProcInfo); | ||
break; | ||
} | ||
} | ||
|
@@ -880,7 +930,9 @@ namespace driver { | |
return; | ||
} | ||
|
||
size_t NumPartitions = TQ->getNumberOfParallelTasks(); | ||
size_t NumPartitions = (Comp.BatchCount.hasValue() ? | ||
Comp.BatchCount.getValue() : | ||
TQ->getNumberOfParallelTasks()); | ||
CommandSetVector Batchable, NonBatchable; | ||
std::vector<const Job *> Batches; | ||
bool PretendTheCommandLineIsTooLongOnce = | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if the function were named based on that purpose, rather than on how it's planning to check.
jobWasBatchedWithFailingJobs
or something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I wish I had caught that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed