Skip to content

Commit 0afdf43

Browse files
committed
Auto merge of #70449 - ecstatic-morse:visit-body, r=oli-obk
Make `Visitor::visit_body` take a plain `&Body` `ReadOnlyBodyAndCache` has replaced `&Body` in many parts of the code base that don't care about basic block predecessors. This includes the MIR `Visitor` trait, which I suspect resulted in many unnecessary changes in #64736. This reverts part of that PR to reduce the number of places where we need to pass a `ReadOnlyBodyAndCache`. In the long term, we should either give `ReadOnlyBodyAndCache` more ergonomic name and replace all uses of `&mir::Body` with it at the cost of carrying an extra pointer everywhere, or use it only in places that actually need access to the predecessor cache. Perhaps there is an even nicer alternative. r? @Nashenas88
2 parents 4911572 + 538cdef commit 0afdf43

File tree

21 files changed

+33
-34
lines changed

21 files changed

+33
-34
lines changed

src/librustc/mir/visit.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ use rustc_span::Span;
6565
// variant argument) that does not require visiting, as in
6666
// `is_cleanup` above.
6767

68-
macro_rules! body_cache_type {
69-
(mut $a:lifetime, $tcx:lifetime) => {
68+
macro_rules! body_type {
69+
(mut $tcx:lifetime) => {
7070
&mut BodyAndCache<$tcx>
7171
};
72-
($a:lifetime, $tcx:lifetime) => {
73-
ReadOnlyBodyAndCache<$a, $tcx>
72+
($tcx:lifetime) => {
73+
&Body<$tcx>
7474
};
7575
}
7676

@@ -82,7 +82,7 @@ macro_rules! make_mir_visitor {
8282

8383
fn visit_body(
8484
&mut self,
85-
body: body_cache_type!($($mutability)? '_, 'tcx)
85+
body: body_type!($($mutability)? 'tcx)
8686
) {
8787
self.super_body(body);
8888
}
@@ -254,7 +254,7 @@ macro_rules! make_mir_visitor {
254254

255255
fn super_body(
256256
&mut self,
257-
$($mutability)? body: body_cache_type!($($mutability)? '_, 'tcx)
257+
$($mutability)? body: body_type!($($mutability)? 'tcx)
258258
) {
259259
let span = body.span;
260260
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
@@ -819,7 +819,7 @@ macro_rules! make_mir_visitor {
819819

820820
fn visit_location(
821821
&mut self,
822-
body: body_cache_type!($($mutability)? '_, 'tcx),
822+
body: body_type!($($mutability)? 'tcx),
823823
location: Location
824824
) {
825825
let basic_block = & $($mutability)? body[location.block];

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2020
let mir = fx.mir;
2121
let mut analyzer = LocalAnalyzer::new(fx);
2222

23-
analyzer.visit_body(mir);
23+
analyzer.visit_body(&mir);
2424

2525
for (local, decl) in mir.local_decls.iter_enumerated() {
2626
let ty = fx.monomorphize(&decl.ty);

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl LocalsStateAtExit {
107107
LocalsStateAtExit::AllAreInvalidated
108108
} else {
109109
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
110-
has_storage_dead.visit_body(body);
110+
has_storage_dead.visit_body(&body);
111111
let mut has_storage_dead_or_moved = has_storage_dead.0;
112112
for move_out in &move_data.moves {
113113
if let Some(index) = move_data.base_local(move_out.path) {

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15591559
}
15601560
}
15611561
let mut visitor = FakeReadCauseFinder { place, cause: None };
1562-
visitor.visit_body(self.body);
1562+
visitor.visit_body(&self.body);
15631563
match visitor.cause {
15641564
Some(FakeReadCause::ForMatchGuard) => Some("match guard"),
15651565
Some(FakeReadCause::ForIndex) => Some("indexing expression"),

src/librustc_mir/borrow_check/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn generate_invalidates<'tcx>(
3737
body: &body,
3838
dominators,
3939
};
40-
ig.visit_body(body);
40+
ig.visit_body(&body);
4141
}
4242
}
4343

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ fn do_mir_borrowck<'a, 'tcx>(
299299
}
300300

301301
dataflow::visit_results(
302-
&*body,
303-
traversal::reverse_postorder(&*body).map(|(bb, _)| bb),
302+
&body,
303+
traversal::reverse_postorder(&body).map(|(bb, _)| bb),
304304
&results,
305305
&mut mbcx,
306306
);

src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl LocalUseMap {
8181
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
8282

8383
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
84-
.visit_body(body);
84+
.visit_body(&body);
8585

8686
local_use_map
8787
}

src/librustc_mir/borrow_check/type_check/liveness/polonius.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(super) fn populate_access_facts(
101101
location_table,
102102
move_data,
103103
};
104-
extractor.visit_body(body);
104+
extractor.visit_body(&body);
105105

106106
facts.var_dropped_at.extend(
107107
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn type_check_internal<'a, 'tcx, R>(
210210
);
211211
let errors_reported = {
212212
let mut verifier = TypeVerifier::new(&mut checker, *body, promoted);
213-
verifier.visit_body(body);
213+
verifier.visit_body(&body);
214214
verifier.errors_reported
215215
};
216216

@@ -435,7 +435,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
435435
}
436436
}
437437

438-
fn visit_body(&mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>) {
438+
fn visit_body(&mut self, body: &Body<'tcx>) {
439439
self.sanitize_type(&"return type", body.return_ty());
440440
for local_decl in &body.local_decls {
441441
self.sanitize_type(local_decl, local_decl.ty);
@@ -563,7 +563,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
563563

564564
swap_constraints(self);
565565

566-
self.visit_body(promoted_body);
566+
self.visit_body(&promoted_body);
567567

568568
if !self.errors_reported {
569569
// if verifier failed, don't do further checks to avoid ICEs

src/librustc_mir/borrow_check/used_muts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
3232
never_initialized_mut_locals: &mut never_initialized_mut_locals,
3333
mbcx: self,
3434
};
35-
visitor.visit_body(visitor.mbcx.body);
35+
visitor.visit_body(&visitor.mbcx.body);
3636
}
3737

3838
// Take the union of the existed `used_mut` set with those variables we've found were

0 commit comments

Comments
 (0)