-
Couldn't load subscription status.
- Fork 13.9k
Clean up MIR drop generation #61872
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
Clean up MIR drop generation #61872
Conversation
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_mir/build/expr/into.rs
Outdated
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.
N.B. As part of implementing while a && let b = c { ... } I'll make a PR to remove hir::ExprKind::While and then hair::ExprKind::Loop will presumably need to drop it's condition field and so the else branch would be floated out and the if branch would be removed... I hope the changes here do not cause problems for this...?
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 should be fine, this is only a problem because while loops are special cased. For any sensible HIR lowering this won't be a problem. The temporary will probably end up storage-live for the whole loop body, but that isn't observable. The following two functions generate almost identical optimized MIR after this PR, for example.
fn while_loop(c: bool) {
while get_bool(c) {
if get_bool(c) {
break;
}
}
}
// What the above should probably expand to
fn exp_while_loop(c: bool) {
loop {
match get_bool(c) {
true => {
{if get_bool(c) {
break;
}}
continue;
}
_ => {}
}
break;
}
}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.
Cool.
For any sensible HIR lowering this won't be a problem.
Specifically, the HIR lowering should likely be:
'label: while $cond $block==>
'label: loop {
match DropTemps($cond) {
true => $block,
_ => break,
}
}(is there a particular reason you are using continue; and an empty block?)
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.
It's slightly closer to what the RFC specified. What you're suggesting is probably better.
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.
This should be unnecessary now with #61988.
|
☔ The latest upstream changes (presumably #60730) made this pull request unmergeable. Please resolve the merge conflicts. |
5ae55a3 to
2c93002
Compare
2c93002 to
13218c2
Compare
|
☔ The latest upstream changes (presumably #61915) made this pull request unmergeable. Please resolve the merge conflicts. |
|
r? @pnkfelix |
Should be able to roll forward when rust-lang/rust#61872 is in a nightly.
13218c2 to
07e5297
Compare
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.
This looks very good. I left a few questions.
|
@bors r+ |
|
📌 Commit 07e5297faf2966a77c466b0b5ad936c0deb828ac has been approved by |
|
☔ The latest upstream changes (presumably #62119) made this pull request unmergeable. Please resolve the merge conflicts. |
07e5297 to
3131427
Compare
|
@bors r=nikomatsakis |
|
📌 Commit 3131427 has been approved by |
…sakis Clean up MIR drop generation * Don't assign twice to the destination of a `while` loop containing a `break` expression * Use `as_temp` to evaluate statement expression * Avoid consecutive `StorageLive`s for the condition of a `while` loop * Unify `return`, `break` and `continue` handling, and move it to `scopes.rs` * Make some of the `scopes.rs` internals private * Don't use `Place`s that are always `Local`s in MIR drop generation Closes #42371 Closes #61579 Closes #61731 Closes #61834 Closes #61910 Closes #62115
|
☀️ Test successful - checks-travis, status-appveyor |
|
Was this performance regression expected? |
|
The ctfe-stress benchmark is now generating more MIR, so I'm not surprised that it's slower. I can't really work out what's going on with |
…_mention, r=compiler-errors Fixup method doc that mentions removed param The param was removed in rust-lang#61872 (101a2f5)
whileloop containing abreakexpressionas_tempto evaluate statement expressionStorageLives for the condition of awhileloopreturn,breakandcontinuehandling, and move it toscopes.rsscopes.rsinternals privatePlaces that are alwaysLocals in MIR drop generationCloses #42371
Closes #61579
Closes #61731
Closes #61834
Closes #61910
Closes #62115