-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rework definition of MIR phases to more closely reflect semantic concerns #99102
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? @oli-obk (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
fb078cb
to
0f43aec
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 0f43aec8691e29c5f9a1ae3bc97a15379b3c43a7 with merge e760531213653adf44edf5e5e9fdf64bcd9459b6... |
☀️ Try build successful - checks-actions |
Queued e760531213653adf44edf5e5e9fdf64bcd9459b6 with parent 17355a3, future comparison URL. |
Finished benchmarking commit (e760531213653adf44edf5e5e9fdf64bcd9459b6): comparison url. Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Footnotes |
0f43aec
to
59c4c42
Compare
I've updated the main comment |
This comment has been minimized.
This comment has been minimized.
59c4c42
to
25ed9a5
Compare
25ed9a5
to
2c93f9c
Compare
Attached a commit to the end that simplifies some of the |
To sum up, the approximate mapping between the old pub enum MirPhase {
Built, // MirPhase::Built,
Const, //
ConstsPromoted, // AnalysisPhase::Initial
Derefered, // AnalysisPhase::PostCleanup
DropsLowered, //
GeneratorsLowered, // (`StateTransform` run before `Deaggregator` in the change)
Deaggregated, // RuntimePhase::Initial
// RuntimePhase::PostCleanup
Optimized, // RuntimePhase::Optimized
} Hopefully this can help people better viewing the code changes. |
☔ The latest upstream changes (presumably #99908) made this pull request unmergeable. Please resolve the merge conflicts. |
2c93f9c
to
d56751c
Compare
Finished benchmarking commit (f07d6e8): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
@JakobDegen The original CI perf run was perf-neutral, but the one from the merge was clearly regressive. Could the "commit to the end that simplifies some of the run_passes logic" be the cause? |
Running valgrind does point at that as being the cause. I'm somewhat surprised by this though. First of all I didn't expect this code to be that hot, but it's also not clear to me why this version is so much slower. I'm mostly just shuffling some computations around. I'll keep investigating |
/// - Const prop lints: The lint pass which reports eg `200_u8 + 200_u8` as an error is run as a | ||
/// part of analysis to runtime MIR lowering. This means that transformations which may supress | ||
/// such errors may not run on analysis MIR. |
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.
That's not really a semantic difference, is it?
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.
The same program before has a different meaning before and after the pass, since before the pass the inclusion of certain patterns will imply that a diagnostic is emitted. "Semantic" might be slightly too strict a term to describe the inclusion of an extra diagnostic though
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 understood "semantic" to refer to the operational semantics of the language. I would likely to strictly separate that from "soft" concerns such as lints.
@JakobDegen any progress on looking into the performance regression? |
Didn't find anything interesting locally. Best thing I'd know to do is revert that commit and try putting back whatever parts I can that don't cause a perf regression. Not sure whether I'll have a chance to do that within the next few weeks though |
cachegrind on the many-assoc-items-Check-Full regression:
Even comparing that with the diff shows no obvious avenues for improvement. |
if validate { | ||
validate_body(tcx, body, format!("after pass {}", pass.name())); | ||
validate_body(tcx, body, format!("after pass {}", name)); |
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.
If new_phase == Some(MirPhase::Runtime(RuntimePhase::Optimized))
, doesn't this now run validation each time around the loop, rather than just once at the end?
if validate { | ||
validate_body(tcx, body, format!("after pass {}", pass.name())); | ||
validate_body(tcx, body, format!("after pass {}", name)); |
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.
If new_phase == Some(MirPhase::Runtime(RuntimePhase::Optimized))
, doesn't this now run validation each time around the loop, rather than just once at the end?
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.
new_phase == Some(MirPhase::Runtime(RuntimePhase::Optimized))
is only ever true exactly once (on the appropriate PhaseChange
pass)
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.
Oh I see, I was not aware of this non-local invariant.
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.
Yeah, it's not ideal, my suggestion below would make this much more obvious as a side-effect
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes; | ||
trace!(?overridden_passes); | ||
|
||
if validate { | ||
validate_body(tcx, body, format!("start of phase transition from {:?}", start_phase)); |
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.
So we are no longer doing pre-validation to ensure we have sensible input?
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.
There isn't really a "pre" step - the input to all passes is the output to another. And the first pass that runs after Mir building is a nop (although I suppose it might be principled to insert an explicit invocation of the validator immediately after Mir building)
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.
That is relying on a non-local invariant though, so if it is ever broken it could be hard to debug. The previous check was set up to ensure that it is definitely this pass that is to blame, no matter how much things changed elsewhere in the compiler, possibly by someone who is not aware of this invariant.
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.
Oh hmm, had not considered that angle. Yeah, that sounds reasonable to me. Will re-add this next time I touch this logic (probably fairly soon)
let new_phase = pass.phase_change(); | ||
let dump_enabled = (is_enabled && pass.is_mir_dump_enabled()) || new_phase.is_some(); | ||
let validate = (validate && is_enabled) | ||
|| new_phase == Some(MirPhase::Runtime(RuntimePhase::Optimized)); |
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.
Honestly with all the is_enabled
being manually applied everywherre, I would say this logic is now more complicated and harder to understand than it was before. E.g. this will validate even after disabled passes if new_phase == Some(MirPhase::Runtime(RuntimePhase::Optimized))
.
I'm in favor of that, IMO it made the logic more complicated than it was before. (I very much hope it can be simplified, but I don't think this commit achieves that.) |
Yes, that's actually intentional - the fact that the old pass manager didn't do this was a bug imo. I made a mistake not properly communicating what was going on here, but I think the change to the pass manager is actually correct. It fixes its behavior around disabled passes, and I think it's just more upfront about the complexity of the logic here. I sympathize with your disliking the complexity, but I don't think reverting is the right way to go (unless perf says it is). The right thing to do here to reduce the complexity I think would be to get rid of enum MirChange {
PhaseChange(MirPhase),
Pass(&dyn MirPass),
} Having the phase change be a part of the pass is I think weird anyway (it's not really a property of the pass). This would get rid of that, we can replace all the existing uses of the |
Given there's barely any comments in the code, I would not agree that it is being upfront about anything. ;) It is possible that I misunderstood the intent of the old and/or the new pass managed. Having more than a single line of comment for a function that is both important and subtle would probably help with that. :) |
…on, r=oli-obk Split phase change from `MirPass` The main goal here is to simplify the pass manager logic. `MirPass` no longer contains the `phase_change` method, and `run_passes` instead accepts an `Option<PhaseChange>`. The hope is that this addresses the comments (and maybe perf regression) from rust-lang#99102 . r? `@oli-obk` cc `@RalfJung`
Remove duplicated elaborate box derefs pass The pass runs earlier as a part of `run_runtime_lowering_passes`. The duplicate was added in rust-lang#99102.
…on, r=oli-obk Split phase change from `MirPass` The main goal here is to simplify the pass manager logic. `MirPass` no longer contains the `phase_change` method, and `run_passes` instead accepts an `Option<PhaseChange>`. The hope is that this addresses the comments (and maybe perf regression) from rust-lang#99102 . r? `@oli-obk` cc `@RalfJung`
Implements most of rust-lang/compiler-team#522 .
I tried my best to restrict this PR to the "core" parts of the MCP. In other words, this includes just enough changes to make the new definition of
MirPhase
make sense. That means there are a couple of FIXMEs lying around. Depending on what reviewers prefer, I can either fix them in this PR or send follow up PRs. There are also a couple other refactorings of therustc_mir_transform/src/lib.rs
file that I want to do in follow ups that I didn't leave explicit FIXMEs for.