-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Skip MIR encoding for cargo check #49433
Conversation
I think this also works if you use "rustc --emit=metadata" (and you aren't using Cargo). |
Yes, this is exactly what |
src/librustc_metadata/encoder.rs
Outdated
@@ -833,6 +833,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { | |||
} | |||
} | |||
|
|||
fn metadata_output_only(&self) -> bool { | |||
// MIR optimisation can be skipped when we're just interested in the metadata. | |||
self.tcx.sess.opts.output_types.keys().count() == 1 && |
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.
Please add a len()
impl to OutputTypes in https://github.com/rust-lang/rust/blob/master/src/librustc/session/config.rs and call that instead of the keys(). count()
.
This solution is debatable. Basically, it should be possible to reconstruct something resembling a final linked result from component received from |
r? @nagisa |
I think the solution is fine. We don't specify that Let's see how much of a difference this even makes: |
Skip MIR optimisation for cargo check Resolves #48662. r? @michaelwoerister
After chatting a bit on IRC, @nagisa and I came to the conclusion that it would be better (i.e. more future-proof) to use |
💥 Test timed out |
@bors try |
Maybe we should discuss this in @rust-lang/compiler meeting. The PR, as implemented here does not really pose a regression to what one can do with |
@Mark-Simulacrum, something has gone wrong with the try-build. Could you restart it? I want to get some perf numbers in order to find out if the speedups are even worth the fuss |
src/librustc/session/config.rs
Outdated
@@ -246,6 +246,10 @@ impl OutputTypes { | |||
self.0.values() | |||
} | |||
|
|||
pub fn len(&self) -> usize { | |||
self.0.keys().count() |
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.
Doesn't BTreeMap
have a len
method?
So a mir-opt-level based solution would end up looking like this for almost every MIR pass. A number of passes here are all a good target for having their AFAIR currently It might make sense to stabilise this option to some degree and also review which passes are run at what levels. |
I don't understand why we need to touch anything about optimizations, instead of the current status of the PR which skips encoding? I expect serializing MIR to potentially be costlier than doing most of the enabled-by-default optimizations. |
Oh, that is a fair point, and I had completely missed that, due to how trivial the PR looked and how misleading the title was. I guess this approach works for me then provided we figure out what exactly would make sure that we still end up querying the "analysed" MIR for everything, so that MIR borrowck and friends are still executed. cc @nikomatsakis what ensures that "analysed" MIR is queried if "optimised" MIR is not? |
308f381
to
8414520
Compare
With the current commits, is MIR emitting suppressed, or is it still emitted unoptimised? It looks like you have changed the title, but I'm not sure if the patch reflects it. Edit: looks like disabling MIR inlining also suppress MIR encoding. Also, I'd prefer having this as a flag, similar to what @nagisa said. I have #44587 in mind, and we should not diverge rmeta from what is embedded inside the rlib. |
src/librustc_metadata/encoder.rs
Outdated
@@ -833,6 +833,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { | |||
} | |||
} | |||
|
|||
fn metadata_output_only(&self) -> bool { | |||
// MIR optimisation can be skipped when we're just interested in the metadata. | |||
self.tcx.sess.opts.output_types.len() == 1 && |
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.
Cargo also includes dep-info as output; we probably need to check if we have anything any output that requires codegen.
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.
Good catch! This method could be implemented as
fn metadata_output_only(&self) -> bool {
// MIR optimisation can be skipped when we're just interested in the metadata.
!self.tcx.sess.opts.output_types.should_trans()
}
005d032
to
5576ce8
Compare
How much does this speed up |
@bors try |
Skip MIR encoding for cargo check Resolves #48662. r? @michaelwoerister
@ishitatsuyuki Let's take a look. |
☀️ Test successful - status-travis |
@Mark-Simulacrum Can you please start a perf run? |
Perf started. |
Up to 10% faster on check, others are noise. |
I think we can merge this. Any concerns? @nagisa @michaelwoerister |
📌 Commit 5576ce8 has been approved by |
Skip MIR encoding for cargo check Resolves #48662. r? @michaelwoerister
☀️ Test successful - status-appveyor, status-travis |
Resolves #48662.
r? @michaelwoerister