Skip to content

Commit 54e79af

Browse files
authored
Rollup merge of rust-lang#99027 - tmiasko:basic-blocks, r=oli-obk
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.
2 parents af4cb05 + b48870b commit 54e79af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+131
-140
lines changed

compiler/rustc_borrowck/src/constraint_generation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn generate_constraints<'cx, 'tcx>(
3131
body,
3232
};
3333

34-
for (bb, data) in body.basic_blocks().iter_enumerated() {
34+
for (bb, data) in body.basic_blocks.iter_enumerated() {
3535
cg.visit_basic_block_data(bb, data);
3636
}
3737
}

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
143143
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
144144
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
145145
OutOfScopePrecomputer {
146-
visited: BitSet::new_empty(body.basic_blocks().len()),
146+
visited: BitSet::new_empty(body.basic_blocks.len()),
147147
visit_stack: vec![],
148148
body,
149149
regioncx,

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
459459
return outmost_back_edge;
460460
}
461461

462-
let block = &self.body.basic_blocks()[location.block];
462+
let block = &self.body.basic_blocks[location.block];
463463

464464
if location.statement_index < block.statements.len() {
465465
let successor = location.successor_within_block();
@@ -518,7 +518,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
518518
}
519519

520520
if loop_head.dominates(from, &self.dominators) {
521-
let block = &self.body.basic_blocks()[from.block];
521+
let block = &self.body.basic_blocks[from.block];
522522

523523
if from.statement_index < block.statements.len() {
524524
let successor = from.successor_within_block();
@@ -568,7 +568,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
568568
UseSpans::PatUse(span)
569569
| UseSpans::OtherUse(span)
570570
| UseSpans::FnSelfUse { var_span: span, .. } => {
571-
let block = &self.body.basic_blocks()[location.block];
571+
let block = &self.body.basic_blocks[location.block];
572572

573573
let kind = if let Some(&Statement {
574574
kind: StatementKind::FakeRead(box (FakeReadCause::ForLet(_), _)),

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8888
if let Some(StatementKind::Assign(box (
8989
place,
9090
Rvalue::Use(Operand::Move(move_from)),
91-
))) = self.body.basic_blocks()[location.block]
91+
))) = self.body.basic_blocks[location.block]
9292
.statements
9393
.get(location.statement_index)
9494
.map(|stmt| &stmt.kind)

compiler/rustc_borrowck/src/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl LocationTable {
3333
pub(crate) fn new(body: &Body<'_>) -> Self {
3434
let mut num_points = 0;
3535
let statements_before_block = body
36-
.basic_blocks()
36+
.basic_blocks
3737
.iter()
3838
.map(|block_data| {
3939
let v = num_points;

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl RegionValueElements {
2525
pub(crate) fn new(body: &Body<'_>) -> Self {
2626
let mut num_points = 0;
2727
let statements_before_block: IndexVec<BasicBlock, usize> = body
28-
.basic_blocks()
28+
.basic_blocks
2929
.iter()
3030
.map(|block_data| {
3131
let v = num_points;
@@ -37,7 +37,7 @@ impl RegionValueElements {
3737
debug!("RegionValueElements: num_points={:#?}", num_points);
3838

3939
let mut basic_blocks = IndexVec::with_capacity(num_points);
40-
for (bb, bb_data) in body.basic_blocks().iter_enumerated() {
40+
for (bb, bb_data) in body.basic_blocks.iter_enumerated() {
4141
basic_blocks.extend((0..=bb_data.statements.len()).map(|_| bb));
4242
}
4343

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26332633
self.check_local(&body, local, local_decl);
26342634
}
26352635

2636-
for (block, block_data) in body.basic_blocks().iter_enumerated() {
2636+
for (block, block_data) in body.basic_blocks.iter_enumerated() {
26372637
let mut location = Location { block, statement_index: 0 };
26382638
for stmt in &block_data.statements {
26392639
if !stmt.source_info.span.is_dummy() {

compiler/rustc_codegen_cranelift/src/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
2626
})
2727
.collect::<IndexVec<Local, SsaKind>>();
2828

29-
for bb in fx.mir.basic_blocks().iter() {
29+
for bb in fx.mir.basic_blocks.iter() {
3030
for stmt in bb.statements.iter() {
3131
match &stmt.kind {
3232
Assign(place_and_rval) => match &place_and_rval.1 {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(crate) fn codegen_fn<'tcx>(
7373
// Predefine blocks
7474
let start_block = bcx.create_block();
7575
let block_map: IndexVec<BasicBlock, Block> =
76-
(0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
76+
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();
7777

7878
// Make FunctionCx
7979
let target_config = module.target_config();
@@ -271,7 +271,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
271271
}
272272
fx.tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(fx, start_block));
273273

274-
for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
274+
for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() {
275275
let block = fx.get_block(bb);
276276
fx.bcx.switch_to_block(block);
277277

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
505505
return None;
506506
}
507507
let mut computed_const_val = None;
508-
for bb_data in fx.mir.basic_blocks() {
508+
for bb_data in fx.mir.basic_blocks.iter() {
509509
for stmt in &bb_data.statements {
510510
match &stmt.kind {
511511
StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => {

0 commit comments

Comments
 (0)