Skip to content

Clean up MIR drop generation - #61872

Merged
bors merged 6 commits into
rust-lang:masterfrom
matthewjasper:refactor-mir-drop-gen
Jun 26, 2019
Merged

Clean up MIR drop generation#61872
bors merged 6 commits into
rust-lang:masterfrom
matthewjasper:refactor-mir-drop-gen

Conversation

@matthewjasper

@matthewjaspermatthewjasper commented Jun 15, 2019

Copy link
Copy Markdown
Contributor
  • Don't assign twice to the destination of a while loop containing a break expression
  • Use as_temp to evaluate statement expression
  • Avoid consecutive StorageLives 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 Places that are always Locals in MIR drop generation

Closes#42371
Closes#61579
Closes#61731
Closes#61834
Closes#61910
Closes#62115

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 15, 2019
@matthewjaspermatthewjasper changed the title Refactor MIR drop generationClean up MIR drop generationJun 15, 2019
Comment threadsrc/librustc_mir/build/expr/into.rs Outdated

Copy link
Copy Markdown
Contributor

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...?

@matthewjaspermatthewjasperJun 15, 2019

Copy link
Copy Markdown
ContributorAuthor

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.

fnwhile_loop(c:bool){whileget_bool(c){ifget_bool(c){break;}}}// What the above should probably expand tofnexp_while_loop(c:bool){loop{matchget_bool(c){true => {{ifget_bool(c){break;}}continue;}
_ => {}}break;}}

Copy link
Copy Markdown
Contributor

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{matchDropTemps($cond){true => $block,
_ => break,}}

(is there a particular reason you are using continue; and an empty block?)

@matthewjaspermatthewjasperJun 15, 2019

Copy link
Copy Markdown
ContributorAuthor

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.

Copy link
Copy Markdown
Contributor

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.

@bors

bors commented Jun 16, 2019

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Jun 18, 2019

Copy link
Copy Markdown
Collaborator

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

@eddyb

Copy link
Copy Markdown
Contributor

r? @pnkfelix

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/librustc_mir/build/expr/stmt.rs Outdated
Comment threadsrc/librustc_mir/build/matches/mod.rs Outdated
Comment threadsrc/librustc_mir/build/expr/stmt.rs Outdated
Comment threadsrc/test/mir-opt/while-storage.rs Outdated
Comment threadsrc/librustc_mir/build/expr/as_rvalue.rs Outdated
@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jun 25, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 07e5297faf2966a77c466b0b5ad936c0deb828ac has been approved by nikomatsakis

@borsbors 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 Jun 25, 2019
@bors

bors commented Jun 25, 2019

Copy link
Copy Markdown
Collaborator

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

@cramertj

Copy link
Copy Markdown
Member

@bors r=nikomatsakis

@bors

bors commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 3131427 has been approved by nikomatsakis

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 26, 2019
@bors

bors commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 3131427 with merge d3e2cec...

bors added a commit that referenced this pull request Jun 26, 2019
…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#42371Closes#61579Closes#61731Closes#61834Closes#61910Closes#62115
@bors

bors commented Jun 26, 2019

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-travis, status-appveyor
Approved by: nikomatsakis
Pushing d3e2cec to master...

@mati865

Copy link
Copy Markdown
Member

@matthewjasper
matthewjasper deleted the refactor-mir-drop-gen branch July 7, 2019 09:48
@matthewjasper

Copy link
Copy Markdown
ContributorAuthor

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 unicode_normalization, since the generated MIR is unchanged for the large functions and constants.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 12, 2022
…_mention, r=compiler-errors
Fixup method doc that mentions removed param
The param was removed in rust-lang#61872 (101a2f5)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

9 participants

@matthewjasper@rust-highfive@bors@eddyb@nikomatsakis@cramertj@mati865@pnkfelix@Centril