Skip to content
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

[BatchMode] Sort batch inputs rather than asserting; they are not always sorted. #15531

Merged
merged 1 commit into from
Mar 28, 2018

Conversation

graydon
Copy link
Contributor

@graydon graydon commented Mar 27, 2018

Some jobs sent to batch mode's helper function for batching are queued by out-of-order actions like flushed deferred jobs, or jobs discovered by traversing the dependency graph. These are not in an order that's a subsequence of the top-level compilation input sequence. Rather than asserting that they are, as we did before, we change to just forcibly sorting the jobs into the right order.

@graydon graydon requested a review from jrose-apple March 27, 2018 01:21
@graydon
Copy link
Contributor Author

graydon commented Mar 27, 2018

@swift-ci please test

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to write a test case for this?

@@ -319,7 +310,9 @@ ToolChain::constructBatchJob(ArrayRef<const Job *> jobs,
if (jobs.empty())
return nullptr;

assert(jobsAreSubsequenceOfCompilationInputs(jobs, C));
llvm::SmallVector<const Job *, 16> sortedJobs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: no need for llvm::.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

assert(jobsAreSubsequenceOfCompilationInputs(jobs, C));
llvm::SmallVector<const Job *, 16> sortedJobs;
sortJobsToMatchCompilationInputs(jobs, sortedJobs, C);
jobs = sortedJobs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidungar would probably prefer you just use sortedJobs everywhere else; if you want to keep the diff small, you could rename the parameter to unsortedJobs instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @jrose-apple , you read my mind!

Compilation &C) {
llvm::SmallVector<const Job *, 16> sortedJobs;
static void sortJobsToMatchCompilationInputs(ArrayRef<const Job *> jobs,
llvm::SmallVectorImpl<const Job *> &sortedJobs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: no llvm::. I'd also consider just having this take an already-populated SmallVectorImpl (or a MutableArrayRef) and sorting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a sort (in the sense of a thing you can adapt an in-place sorting algorithm to easily) so much as it's a "build a new vector in the order dictated by the input files list". But I'll fix the names anyways :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, I suppose not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice function name. Is there a comment anywhere explaining why we want the order to match the inputs?

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ed6c599d077137582f023f219a8edda1328ee08b

@graydon graydon force-pushed the sort-jobs-dont-assert branch from ed6c599 to e4bc944 Compare March 28, 2018 05:48
@graydon
Copy link
Contributor Author

graydon commented Mar 28, 2018

@jrose-apple updated with test and comments addressed

@graydon
Copy link
Contributor Author

graydon commented Mar 28, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ed6c599d077137582f023f219a8edda1328ee08b

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ed6c599d077137582f023f219a8edda1328ee08b

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test looks good, code change went too far!

@@ -30,6 +30,7 @@

using namespace swift;
using namespace swift::driver;
using namespace llvm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, please don't do this. My comments last time were specific to SmallVector and SmallVectorImpl, two types used commonly enough that we import them into the swift namespace in swift/Basic/LLVM.h. That's not a fixed list (in general, it's fine to add more llvm/ADT/ types), but we don't want all LLVM things going unqualified.

@graydon graydon force-pushed the sort-jobs-dont-assert branch from e4bc944 to b677adb Compare March 28, 2018 15:57
@graydon
Copy link
Contributor Author

graydon commented Mar 28, 2018

@jrose-apple pushed update with llvm:: back where it ought to be, and @davidungar's request for an explanatory comment added to the sort routine.

Compilation &C) {
llvm::SmallVector<const Job *, 16> sortedJobs;
/// Due to SR-631 / rdar://20535574, the success or failure of a Swift compilation
/// is currently sensitive to e order in which files are processed, in terms of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "e order". I also think citing a specific SR / Radar isn't so great here—that's the one we know about, but we'd want to do experiments to make sure there wasn't any order-dependency left in the non-incremental parts of the work.

Sorry for all this nitpicking!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple S'ok, as I've said before, you're picky but I can't remember a nit you've picked that didn't need picking; better than my sloppy reviewing style! And being subject to it is a good exercise in cultivating equanimity anyway: the PR will land when it's ready, and not before :)

Meanwhile: pushed a fix.

@davidungar
Copy link
Contributor

@graydon Thanks for the clarification in the comment. It will help me someday!

@graydon graydon force-pushed the sort-jobs-dont-assert branch from b677adb to af538f1 Compare March 28, 2018 16:25
@graydon
Copy link
Contributor Author

graydon commented Mar 28, 2018

@swift-ci please test and merge

1 similar comment
@graydon
Copy link
Contributor Author

graydon commented Mar 28, 2018

@swift-ci please test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants