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

Refactor the partitioning module to make it easier to introduce new algorithms #74275

Merged
merged 3 commits into from
Aug 25, 2020

Conversation

wesleywiser
Copy link
Member

@wesleywiser wesleywiser commented Jul 12, 2020

I've split the librustc_mir::monomorphize::partitioning module into a few files and introduced a Partitioner trait which allows us to decouple the partitioning algorithm from the code which integrates it into the query system. This should allow us to introduce new partitioning algorithms much more easily. I've also gone ahead and added a -Z flag to control which algorithm is used (currently there is only the default).

I left a few comments in places where things might be improved further.

r? @pnkfelix cc @rust-lang/wg-incr-comp

@wesleywiser
Copy link
Member Author

Let's make sure this doesn't hurt performance.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 13, 2020

⌛ Trying commit 42d7cf395b14b1b39b3050ffad364a1e15234f4a with merge 9b74ae087324a980952c4b760b1d7aab32b3ce65...


use crate::monomorphize::partitioning::PreInliningPartitioning;

pub fn merge_codegen_units<'tcx>(
Copy link
Member Author

Choose a reason for hiding this comment

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

I pulled this out into a separate module since it seemed like we might want a few different merge algorithms to choose from.

Copy link
Member

Choose a reason for hiding this comment

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

I think this makes sense - I don't think it would prohibit us from having partitioning strategies which don't have a merging phase.

@@ -0,0 +1,433 @@
//! Partitioning Codegen Units for Incremental Compilation
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment block is taken verbatim from its original location. Parts of it describe the partitioning process over all and parts are specific to the algorithm (now called DefaultPartitioner).

This could probably be left as is for now but eventually we should split it into two parts and move the bits about the algorithm into module documentation for the DefaultPartitioner algorithm.

target_cgu_count: usize,
);

fn place_inlined_mono_items(
Copy link
Member Author

@wesleywiser wesleywiser Jul 13, 2020

Choose a reason for hiding this comment

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

This name & signature was taken from the existing code. One that that was not immediately obvious to me was that this does a lot more than just add copies of #[inline] functions into CGUs. This function is primarily responsible for instantiating monomorphized functions in the modules that call them. (Perhaps that's what was meant by "inlined"?)

src/librustc_session/options.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jul 13, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 9b74ae087324a980952c4b760b1d7aab32b3ce65 (9b74ae087324a980952c4b760b1d7aab32b3ce65)

@rust-timer
Copy link
Collaborator

Queued 9b74ae087324a980952c4b760b1d7aab32b3ce65 with parent 9d09331, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (9b74ae087324a980952c4b760b1d7aab32b3ce65): comparison url.

@bjorn3
Copy link
Member

bjorn3 commented Jul 13, 2020

<0.1% speedup overall.

@wesleywiser wesleywiser changed the title [WIP] Refactor the partitioning module to make it easier to introduce new schemes Refactor the partitioning module to make it easier to introduce new schemes Jul 13, 2020
@wesleywiser wesleywiser changed the title Refactor the partitioning module to make it easier to introduce new schemes Refactor the partitioning module to make it easier to introduce new algorithms Jul 13, 2020
@wesleywiser
Copy link
Member Author

r? @pnkfelix cc @rust-lang/wg-incr-comp

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

Current review comments notwithstanding, LGTM.

@wesleywiser
Copy link
Member Author

Responded to review feedback so far.

@bors
Copy link
Contributor

bors commented Jul 15, 2020

☔ The latest upstream changes (presumably #74214) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 15, 2020
@bors
Copy link
Contributor

bors commented Jul 19, 2020

☔ The latest upstream changes (presumably #74091) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@richkadel richkadel left a comment

Choose a reason for hiding this comment

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

Sorry but I had to change this option's structure.

src/librustc_mir/monomorphize/partitioning/mod.rs Outdated Show resolved Hide resolved
src/librustc_mir/monomorphize/partitioning/mod.rs Outdated Show resolved Hide resolved
@wesleywiser
Copy link
Member Author

Rebased.

@pnkfelix if you are interested in doing the review, I don't mind waiting for that, otherwise we can find someone else from wg-incr-comp to do the review.

@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 7, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Aug 19, 2020

I left feedback over here on zulip (archive for those without zulip accounts); basically, I asked wesley to refactor the commit series so that the code shuffling is its own commit, so that the diff will better show what the actual changes are regarding the new trait.

This will allow us to prototype different partitioning schemes without
adding a lot of extra conditionals everywhere.
@wesleywiser
Copy link
Member Author

@pnkfelix I rebased and split out the trait into the first commit. The second commit has no functional changes, just moving the code into a new module.

internalization_candidates,
} = initial_partitioning;

let single_codegen_unit = initial_cgus.len() == 1;
Copy link
Member

Choose a reason for hiding this comment

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

Viewing in diff mode with whitespace changes hidden is a huge win here. :)

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 25, 2020

📌 Commit 98b943e has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented Aug 25, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2020
@pietroalbini
Copy link
Member

@bors treeclosed-

@bors
Copy link
Contributor

bors commented Aug 25, 2020

⌛ Testing commit 98b943e with merge 8ba2250...

@bors
Copy link
Contributor

bors commented Aug 25, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: pnkfelix
Pushing 8ba2250 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 25, 2020
@bors bors merged commit 8ba2250 into rust-lang:master Aug 25, 2020
nnethercote added a commit to nnethercote/rust that referenced this pull request May 24, 2023
Three of the four methods in `DefaultPartitioning` are defined in
`default.rs`. But `merge_codegen_units` is defined in a separate module,
`merging`, even though it's less than 100 lines of code and roughly the
same size as the other three methods. (Also, the `merging` module
currently sits alongside `default`, when it should be a submodule of
`default`, adding to the confusion.)

In rust-lang#74275 this explanation was given:

> I pulled this out into a separate module since it seemed like we might
> want a few different merge algorithms to choose from.

But in the three years since there have been no additional merging
algorithms, and there is no mechanism for choosing between different
merging algorithms. (There is a mechanism,
`-Zcgu-partitioning-strategy`, for choosing between different
partitioning strategies, but the merging algorithm is just one piece of
a partitioning strategy.)

This commit merges `merging` into `default`, making the code easier to
navigate and read.
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants