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

Make MIR basic blocks field public #98930

Merged
merged 5 commits into from
Jul 7, 2022
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Jul 5, 2022

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like basic_blocks_local_decls_mut_and_var_debug_info.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct BasicBlocks wraps together basic blocks
and control flow graph caches.

The BasicBlocks dereferences to IndexVec<BasicBlock, BasicBlockData>.
On the other hand a mutable access requires explicit as_mut() call.

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 5, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2022
compiler/rustc_middle/src/mir/mod.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor

oli-obk commented Jul 5, 2022

r? @oli-obk

this is neat, definitely a massive improvement over the explosion of iteration methods ^^

@JakobDegen
Copy link
Contributor

Yeah, agreed, this is a much better solution than what I did

@oli-obk
Copy link
Contributor

oli-obk commented Jul 6, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 6, 2022

📌 Commit 802cb1c has been approved by oli-obk

@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 Jul 6, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 7, 2022
Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
@Dylan-DPC
Copy link
Member

failed in rollup ci

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 7, 2022
This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
@oli-obk
Copy link
Contributor

oli-obk commented Jul 7, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 7, 2022

📌 Commit 17adfeb has been approved by oli-obk

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 7, 2022
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 7, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 7, 2022
Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
@eddyb
Copy link
Member

eddyb commented Jul 7, 2022

Neat! I guess the focus on basic_blocks: IndexVec<...> had obscured the deeper connection, before.


As a random aside, I believe some IRs would describe this subset of information as "the CFG" (though they might vary in whether that includes the BB contents, or just the terminators).

The only reason I bring this up is because body.cfg[bb] is quite compact and reads nicely IMO, but of course these are just subjective aesthetics - feel free to ignore this drive-by bikeshed comment.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 7, 2022
Rollup of 8 pull requests

Successful merges:

 - rust-lang#96856 (Fix ProjectionElem validation)
 - rust-lang#97711 (Improve soundness of rustc_arena)
 - rust-lang#98507 (Finishing touches for `#[expect]` (RFC 2383))
 - rust-lang#98692 (rustdoc: Cleanup more FIXMEs)
 - rust-lang#98901 (incr: cache dwarf objects in work products)
 - rust-lang#98930 (Make MIR basic blocks field public)
 - rust-lang#98973 (Remove (unused) inherent impl anchors)
 - rust-lang#98981 ( Edit `rustc_mir_dataflow::framework` documentation )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 71b3fbd into rust-lang:master Jul 7, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 7, 2022
@tmiasko tmiasko deleted the pub-basic-blocks branch July 7, 2022 19:37
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 18, 2022
Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 28, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 28, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 29, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Oct 23, 2022
Replace `Body::basic_blocks()` with field access

Since the refactoring in rust-lang#98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants