Skip to content

Commit 1cbd8a4

Browse files
committed
Auto merge of #61506 - imbrem:mir_body_renaming, r=eddyb
Changed usages of `mir` in librustc::mir and librustc_mir to `body` Work on part 2 of #60229
2 parents 5d4aef6 + 80ff07f commit 1cbd8a4

Some content is hidden

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

82 files changed

+1323
-1319
lines changed

src/librustc/mir/cache.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ impl Cache {
4747

4848
pub fn predecessors(
4949
&self,
50-
mir: &Body<'_>
50+
body: &Body<'_>
5151
) -> MappedReadGuard<'_, IndexVec<BasicBlock, Vec<BasicBlock>>> {
5252
if self.predecessors.borrow().is_none() {
53-
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
53+
*self.predecessors.borrow_mut() = Some(calculate_predecessors(body));
5454
}
5555

5656
ReadGuard::map(self.predecessors.borrow(), |p| p.as_ref().unwrap())
5757
}
5858
}
5959

60-
fn calculate_predecessors(mir: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
61-
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
62-
for (bb, data) in mir.basic_blocks().iter_enumerated() {
60+
fn calculate_predecessors(body: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
61+
let mut result = IndexVec::from_elem(vec![], body.basic_blocks());
62+
for (bb, data) in body.basic_blocks().iter_enumerated() {
6363
if let Some(ref term) = data.terminator {
6464
for &tgt in term.successors() {
6565
result[tgt].push(bb);

src/librustc/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2916,21 +2916,21 @@ impl Location {
29162916
}
29172917

29182918
/// Returns `true` if `other` is earlier in the control flow graph than `self`.
2919-
pub fn is_predecessor_of<'tcx>(&self, other: Location, mir: &Body<'tcx>) -> bool {
2919+
pub fn is_predecessor_of<'tcx>(&self, other: Location, body: &Body<'tcx>) -> bool {
29202920
// If we are in the same block as the other location and are an earlier statement
29212921
// then we are a predecessor of `other`.
29222922
if self.block == other.block && self.statement_index < other.statement_index {
29232923
return true;
29242924
}
29252925

29262926
// If we're in another block, then we want to check that block is a predecessor of `other`.
2927-
let mut queue: Vec<BasicBlock> = mir.predecessors_for(other.block).clone();
2927+
let mut queue: Vec<BasicBlock> = body.predecessors_for(other.block).clone();
29282928
let mut visited = FxHashSet::default();
29292929

29302930
while let Some(block) = queue.pop() {
29312931
// If we haven't visited this block before, then make sure we visit it's predecessors.
29322932
if visited.insert(block) {
2933-
queue.append(&mut mir.predecessors_for(block).clone());
2933+
queue.append(&mut body.predecessors_for(block).clone());
29342934
} else {
29352935
continue;
29362936
}

src/librustc/mir/traversal.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ use super::*;
2121
/// A preorder traversal of this graph is either `A B D C` or `A C D B`
2222
#[derive(Clone)]
2323
pub struct Preorder<'a, 'tcx: 'a> {
24-
mir: &'a Body<'tcx>,
24+
body: &'a Body<'tcx>,
2525
visited: BitSet<BasicBlock>,
2626
worklist: Vec<BasicBlock>,
2727
root_is_start_block: bool,
2828
}
2929

3030
impl<'a, 'tcx> Preorder<'a, 'tcx> {
31-
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
31+
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
3232
let worklist = vec![root];
3333

3434
Preorder {
35-
mir,
36-
visited: BitSet::new_empty(mir.basic_blocks().len()),
35+
body,
36+
visited: BitSet::new_empty(body.basic_blocks().len()),
3737
worklist,
3838
root_is_start_block: root == START_BLOCK,
3939
}
4040
}
4141
}
4242

43-
pub fn preorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Preorder<'a, 'tcx> {
44-
Preorder::new(mir, START_BLOCK)
43+
pub fn preorder<'a, 'tcx>(body: &'a Body<'tcx>) -> Preorder<'a, 'tcx> {
44+
Preorder::new(body, START_BLOCK)
4545
}
4646

4747
impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
@@ -53,7 +53,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
5353
continue;
5454
}
5555

56-
let data = &self.mir[idx];
56+
let data = &self.body[idx];
5757

5858
if let Some(ref term) = data.terminator {
5959
self.worklist.extend(term.successors());
@@ -67,7 +67,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
6767

6868
fn size_hint(&self) -> (usize, Option<usize>) {
6969
// All the blocks, minus the number of blocks we've visited.
70-
let upper = self.mir.basic_blocks().len() - self.visited.count();
70+
let upper = self.body.basic_blocks().len() - self.visited.count();
7171

7272
let lower = if self.root_is_start_block {
7373
// We will visit all remaining blocks exactly once.
@@ -99,23 +99,23 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
9999
///
100100
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
101101
pub struct Postorder<'a, 'tcx: 'a> {
102-
mir: &'a Body<'tcx>,
102+
body: &'a Body<'tcx>,
103103
visited: BitSet<BasicBlock>,
104104
visit_stack: Vec<(BasicBlock, Successors<'a>)>,
105105
root_is_start_block: bool,
106106
}
107107

108108
impl<'a, 'tcx> Postorder<'a, 'tcx> {
109-
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
109+
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
110110
let mut po = Postorder {
111-
mir,
112-
visited: BitSet::new_empty(mir.basic_blocks().len()),
111+
body,
112+
visited: BitSet::new_empty(body.basic_blocks().len()),
113113
visit_stack: Vec::new(),
114114
root_is_start_block: root == START_BLOCK,
115115
};
116116

117117

118-
let data = &po.mir[root];
118+
let data = &po.body[root];
119119

120120
if let Some(ref term) = data.terminator {
121121
po.visited.insert(root);
@@ -186,16 +186,16 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
186186
};
187187

188188
if self.visited.insert(bb) {
189-
if let Some(term) = &self.mir[bb].terminator {
189+
if let Some(term) = &self.body[bb].terminator {
190190
self.visit_stack.push((bb, term.successors()));
191191
}
192192
}
193193
}
194194
}
195195
}
196196

197-
pub fn postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Postorder<'a, 'tcx> {
198-
Postorder::new(mir, START_BLOCK)
197+
pub fn postorder<'a, 'tcx>(body: &'a Body<'tcx>) -> Postorder<'a, 'tcx> {
198+
Postorder::new(body, START_BLOCK)
199199
}
200200

201201
impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
@@ -207,12 +207,12 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
207207
self.traverse_successor();
208208
}
209209

210-
next.map(|(bb, _)| (bb, &self.mir[bb]))
210+
next.map(|(bb, _)| (bb, &self.body[bb]))
211211
}
212212

213213
fn size_hint(&self) -> (usize, Option<usize>) {
214214
// All the blocks, minus the number of blocks we've visited.
215-
let upper = self.mir.basic_blocks().len() - self.visited.count();
215+
let upper = self.body.basic_blocks().len() - self.visited.count();
216216

217217
let lower = if self.root_is_start_block {
218218
// We will visit all remaining blocks exactly once.
@@ -252,19 +252,19 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
252252
/// to re-use the traversal
253253
#[derive(Clone)]
254254
pub struct ReversePostorder<'a, 'tcx: 'a> {
255-
mir: &'a Body<'tcx>,
255+
body: &'a Body<'tcx>,
256256
blocks: Vec<BasicBlock>,
257257
idx: usize
258258
}
259259

260260
impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
261-
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> {
262-
let blocks : Vec<_> = Postorder::new(mir, root).map(|(bb, _)| bb).collect();
261+
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> {
262+
let blocks : Vec<_> = Postorder::new(body, root).map(|(bb, _)| bb).collect();
263263

264264
let len = blocks.len();
265265

266266
ReversePostorder {
267-
mir,
267+
body,
268268
blocks,
269269
idx: len
270270
}
@@ -276,8 +276,8 @@ impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
276276
}
277277

278278

279-
pub fn reverse_postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> ReversePostorder<'a, 'tcx> {
280-
ReversePostorder::new(mir, START_BLOCK)
279+
pub fn reverse_postorder<'a, 'tcx>(body: &'a Body<'tcx>) -> ReversePostorder<'a, 'tcx> {
280+
ReversePostorder::new(body, START_BLOCK)
281281
}
282282

283283
impl<'a, 'tcx> Iterator for ReversePostorder<'a, 'tcx> {
@@ -287,7 +287,7 @@ impl<'a, 'tcx> Iterator for ReversePostorder<'a, 'tcx> {
287287
if self.idx == 0 { return None; }
288288
self.idx -= 1;
289289

290-
self.blocks.get(self.idx).map(|&bb| (bb, &self.mir[bb]))
290+
self.blocks.get(self.idx).map(|&bb| (bb, &self.body[bb]))
291291
}
292292

293293
fn size_hint(&self) -> (usize, Option<usize>) {

src/librustc/mir/visit.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ macro_rules! make_mir_visitor {
7171
// Override these, and call `self.super_xxx` to revert back to the
7272
// default behavior.
7373

74-
fn visit_body(&mut self, mir: & $($mutability)? Body<'tcx>) {
75-
self.super_body(mir);
74+
fn visit_body(&mut self, body: & $($mutability)? Body<'tcx>) {
75+
self.super_body(body);
7676
}
7777

7878
fn visit_basic_block_data(&mut self,
@@ -253,41 +253,41 @@ macro_rules! make_mir_visitor {
253253
// not meant to be overridden.
254254

255255
fn super_body(&mut self,
256-
mir: & $($mutability)? Body<'tcx>) {
257-
if let Some(yield_ty) = &$($mutability)? mir.yield_ty {
256+
body: & $($mutability)? Body<'tcx>) {
257+
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
258258
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
259-
span: mir.span,
259+
span: body.span,
260260
scope: OUTERMOST_SOURCE_SCOPE,
261261
}));
262262
}
263263

264264
// for best performance, we want to use an iterator rather
265-
// than a for-loop, to avoid calling `mir::Body::invalidate` for
265+
// than a for-loop, to avoid calling `body::Body::invalidate` for
266266
// each basic block.
267267
macro_rules! basic_blocks {
268-
(mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
269-
() => (mir.basic_blocks().iter_enumerated());
268+
(mut) => (body.basic_blocks_mut().iter_enumerated_mut());
269+
() => (body.basic_blocks().iter_enumerated());
270270
};
271271
for (bb, data) in basic_blocks!($($mutability)?) {
272272
self.visit_basic_block_data(bb, data);
273273
}
274274

275-
for scope in &$($mutability)? mir.source_scopes {
275+
for scope in &$($mutability)? body.source_scopes {
276276
self.visit_source_scope_data(scope);
277277
}
278278

279-
self.visit_ty(&$($mutability)? mir.return_ty(), TyContext::ReturnTy(SourceInfo {
280-
span: mir.span,
279+
self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
280+
span: body.span,
281281
scope: OUTERMOST_SOURCE_SCOPE,
282282
}));
283283

284-
for local in mir.local_decls.indices() {
285-
self.visit_local_decl(local, & $($mutability)? mir.local_decls[local]);
284+
for local in body.local_decls.indices() {
285+
self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
286286
}
287287

288288
macro_rules! type_annotations {
289-
(mut) => (mir.user_type_annotations.iter_enumerated_mut());
290-
() => (mir.user_type_annotations.iter_enumerated());
289+
(mut) => (body.user_type_annotations.iter_enumerated_mut());
290+
() => (body.user_type_annotations.iter_enumerated());
291291
};
292292

293293
for (index, annotation) in type_annotations!($($mutability)?) {
@@ -296,7 +296,7 @@ macro_rules! make_mir_visitor {
296296
);
297297
}
298298

299-
self.visit_span(&$($mutability)? mir.span);
299+
self.visit_span(&$($mutability)? body.span);
300300
}
301301

302302
fn super_basic_block_data(&mut self,
@@ -834,8 +834,8 @@ macro_rules! make_mir_visitor {
834834

835835
// Convenience methods
836836

837-
fn visit_location(&mut self, mir: & $($mutability)? Body<'tcx>, location: Location) {
838-
let basic_block = & $($mutability)? mir[location.block];
837+
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {
838+
let basic_block = & $($mutability)? body[location.block];
839839
if basic_block.statements.len() == location.statement_index {
840840
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
841841
self.visit_terminator(terminator, location)

src/librustc_mir/borrow_check/borrow_set.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ crate enum LocalsStateAtExit {
9090
impl LocalsStateAtExit {
9191
fn build(
9292
locals_are_invalidated_at_exit: bool,
93-
mir: &Body<'tcx>,
93+
body: &Body<'tcx>,
9494
move_data: &MoveData<'tcx>
9595
) -> Self {
9696
struct HasStorageDead(BitSet<Local>);
@@ -106,8 +106,8 @@ impl LocalsStateAtExit {
106106
if locals_are_invalidated_at_exit {
107107
LocalsStateAtExit::AllAreInvalidated
108108
} else {
109-
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(mir.local_decls.len()));
110-
has_storage_dead.visit_body(mir);
109+
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
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) {
@@ -123,24 +123,24 @@ impl LocalsStateAtExit {
123123
impl<'tcx> BorrowSet<'tcx> {
124124
pub fn build(
125125
tcx: TyCtxt<'_, '_, 'tcx>,
126-
mir: &Body<'tcx>,
126+
body: &Body<'tcx>,
127127
locals_are_invalidated_at_exit: bool,
128128
move_data: &MoveData<'tcx>
129129
) -> Self {
130130

131131
let mut visitor = GatherBorrows {
132132
tcx,
133-
mir,
133+
body,
134134
idx_vec: IndexVec::new(),
135135
location_map: Default::default(),
136136
activation_map: Default::default(),
137137
local_map: Default::default(),
138138
pending_activations: Default::default(),
139139
locals_state_at_exit:
140-
LocalsStateAtExit::build(locals_are_invalidated_at_exit, mir, move_data),
140+
LocalsStateAtExit::build(locals_are_invalidated_at_exit, body, move_data),
141141
};
142142

143-
for (block, block_data) in traversal::preorder(mir) {
143+
for (block, block_data) in traversal::preorder(body) {
144144
visitor.visit_basic_block_data(block, block_data);
145145
}
146146

@@ -163,7 +163,7 @@ impl<'tcx> BorrowSet<'tcx> {
163163

164164
struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
165165
tcx: TyCtxt<'a, 'gcx, 'tcx>,
166-
mir: &'a Body<'tcx>,
166+
body: &'a Body<'tcx>,
167167
idx_vec: IndexVec<BorrowIndex, BorrowData<'tcx>>,
168168
location_map: FxHashMap<Location, BorrowIndex>,
169169
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
@@ -191,7 +191,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
191191
) {
192192
if let mir::Rvalue::Ref(region, kind, ref borrowed_place) = *rvalue {
193193
if borrowed_place.ignore_borrow(
194-
self.tcx, self.mir, &self.locals_state_at_exit) {
194+
self.tcx, self.body, &self.locals_state_at_exit) {
195195
return;
196196
}
197197

@@ -246,7 +246,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
246246
if let TwoPhaseActivation::ActivatedAt(other_location) =
247247
borrow_data.activation_location {
248248
span_bug!(
249-
self.mir.source_info(location).span,
249+
self.body.source_info(location).span,
250250
"found two uses for 2-phase borrow temporary {:?}: \
251251
{:?} and {:?}",
252252
temp,
@@ -320,7 +320,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
320320
temp
321321
} else {
322322
span_bug!(
323-
self.mir.source_info(start_location).span,
323+
self.body.source_info(start_location).span,
324324
"expected 2-phase borrow to assign to a local, not `{:?}`",
325325
assigned_place,
326326
);
@@ -339,7 +339,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
339339
// assignment.
340340
let old_value = self.pending_activations.insert(temp, borrow_index);
341341
if let Some(old_index) = old_value {
342-
span_bug!(self.mir.source_info(start_location).span,
342+
span_bug!(self.body.source_info(start_location).span,
343343
"found already pending activation for temp: {:?} \
344344
at borrow_index: {:?} with associated data {:?}",
345345
temp, old_index, self.idx_vec[old_index]);

0 commit comments

Comments
 (0)