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

Changed usages of mir in librustc::mir and librustc_mir to body #61506

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/librustc/mir/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ impl Cache {

pub fn predecessors(
&self,
mir: &Body<'_>
body: &Body<'_>
) -> MappedReadGuard<'_, IndexVec<BasicBlock, Vec<BasicBlock>>> {
if self.predecessors.borrow().is_none() {
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
*self.predecessors.borrow_mut() = Some(calculate_predecessors(body));
}

ReadGuard::map(self.predecessors.borrow(), |p| p.as_ref().unwrap())
}
}

fn calculate_predecessors(mir: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
for (bb, data) in mir.basic_blocks().iter_enumerated() {
fn calculate_predecessors(body: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
let mut result = IndexVec::from_elem(vec![], body.basic_blocks());
for (bb, data) in body.basic_blocks().iter_enumerated() {
if let Some(ref term) = data.terminator {
for &tgt in term.successors() {
result[tgt].push(bb);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2916,21 +2916,21 @@ impl Location {
}

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

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

while let Some(block) = queue.pop() {
// If we haven't visited this block before, then make sure we visit it's predecessors.
if visited.insert(block) {
queue.append(&mut mir.predecessors_for(block).clone());
queue.append(&mut body.predecessors_for(block).clone());
} else {
continue;
}
Expand Down
50 changes: 25 additions & 25 deletions src/librustc/mir/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ use super::*;
/// A preorder traversal of this graph is either `A B D C` or `A C D B`
#[derive(Clone)]
pub struct Preorder<'a, 'tcx: 'a> {
mir: &'a Body<'tcx>,
body: &'a Body<'tcx>,
visited: BitSet<BasicBlock>,
worklist: Vec<BasicBlock>,
root_is_start_block: bool,
}

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

Preorder {
mir,
visited: BitSet::new_empty(mir.basic_blocks().len()),
body,
visited: BitSet::new_empty(body.basic_blocks().len()),
worklist,
root_is_start_block: root == START_BLOCK,
}
}
}

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

impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
Expand All @@ -53,7 +53,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
continue;
}

let data = &self.mir[idx];
let data = &self.body[idx];

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

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

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

impl<'a, 'tcx> Postorder<'a, 'tcx> {
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
let mut po = Postorder {
mir,
visited: BitSet::new_empty(mir.basic_blocks().len()),
body,
visited: BitSet::new_empty(body.basic_blocks().len()),
visit_stack: Vec::new(),
root_is_start_block: root == START_BLOCK,
};


let data = &po.mir[root];
let data = &po.body[root];

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

if self.visited.insert(bb) {
if let Some(term) = &self.mir[bb].terminator {
if let Some(term) = &self.body[bb].terminator {
self.visit_stack.push((bb, term.successors()));
}
}
}
}
}

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

impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
Expand All @@ -207,12 +207,12 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
self.traverse_successor();
}

next.map(|(bb, _)| (bb, &self.mir[bb]))
next.map(|(bb, _)| (bb, &self.body[bb]))
}

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

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

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

let len = blocks.len();

ReversePostorder {
mir,
body,
blocks,
idx: len
}
Expand All @@ -276,8 +276,8 @@ impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
}


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

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

self.blocks.get(self.idx).map(|&bb| (bb, &self.mir[bb]))
self.blocks.get(self.idx).map(|&bb| (bb, &self.body[bb]))
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
36 changes: 18 additions & 18 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ macro_rules! make_mir_visitor {
// Override these, and call `self.super_xxx` to revert back to the
// default behavior.

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

fn visit_basic_block_data(&mut self,
Expand Down Expand Up @@ -253,41 +253,41 @@ macro_rules! make_mir_visitor {
// not meant to be overridden.

fn super_body(&mut self,
mir: & $($mutability)? Body<'tcx>) {
if let Some(yield_ty) = &$($mutability)? mir.yield_ty {
body: & $($mutability)? Body<'tcx>) {
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
span: mir.span,
span: body.span,
scope: OUTERMOST_SOURCE_SCOPE,
}));
}

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

for scope in &$($mutability)? mir.source_scopes {
for scope in &$($mutability)? body.source_scopes {
self.visit_source_scope_data(scope);
}

self.visit_ty(&$($mutability)? mir.return_ty(), TyContext::ReturnTy(SourceInfo {
span: mir.span,
self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
span: body.span,
scope: OUTERMOST_SOURCE_SCOPE,
}));

for local in mir.local_decls.indices() {
self.visit_local_decl(local, & $($mutability)? mir.local_decls[local]);
for local in body.local_decls.indices() {
self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
}

macro_rules! type_annotations {
(mut) => (mir.user_type_annotations.iter_enumerated_mut());
() => (mir.user_type_annotations.iter_enumerated());
(mut) => (body.user_type_annotations.iter_enumerated_mut());
() => (body.user_type_annotations.iter_enumerated());
};

for (index, annotation) in type_annotations!($($mutability)?) {
Expand All @@ -296,7 +296,7 @@ macro_rules! make_mir_visitor {
);
}

self.visit_span(&$($mutability)? mir.span);
self.visit_span(&$($mutability)? body.span);
}

fn super_basic_block_data(&mut self,
Expand Down Expand Up @@ -834,8 +834,8 @@ macro_rules! make_mir_visitor {

// Convenience methods

fn visit_location(&mut self, mir: & $($mutability)? Body<'tcx>, location: Location) {
let basic_block = & $($mutability)? mir[location.block];
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {
let basic_block = & $($mutability)? body[location.block];
if basic_block.statements.len() == location.statement_index {
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
self.visit_terminator(terminator, location)
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ crate enum LocalsStateAtExit {
impl LocalsStateAtExit {
fn build(
locals_are_invalidated_at_exit: bool,
mir: &Body<'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>
) -> Self {
struct HasStorageDead(BitSet<Local>);
Expand All @@ -106,8 +106,8 @@ impl LocalsStateAtExit {
if locals_are_invalidated_at_exit {
LocalsStateAtExit::AllAreInvalidated
} else {
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(mir.local_decls.len()));
has_storage_dead.visit_body(mir);
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
has_storage_dead.visit_body(body);
let mut has_storage_dead_or_moved = has_storage_dead.0;
for move_out in &move_data.moves {
if let Some(index) = move_data.base_local(move_out.path) {
Expand All @@ -123,24 +123,24 @@ impl LocalsStateAtExit {
impl<'tcx> BorrowSet<'tcx> {
pub fn build(
tcx: TyCtxt<'_, '_, 'tcx>,
mir: &Body<'tcx>,
body: &Body<'tcx>,
locals_are_invalidated_at_exit: bool,
move_data: &MoveData<'tcx>
) -> Self {

let mut visitor = GatherBorrows {
tcx,
mir,
body,
idx_vec: IndexVec::new(),
location_map: Default::default(),
activation_map: Default::default(),
local_map: Default::default(),
pending_activations: Default::default(),
locals_state_at_exit:
LocalsStateAtExit::build(locals_are_invalidated_at_exit, mir, move_data),
LocalsStateAtExit::build(locals_are_invalidated_at_exit, body, move_data),
};

for (block, block_data) in traversal::preorder(mir) {
for (block, block_data) in traversal::preorder(body) {
visitor.visit_basic_block_data(block, block_data);
}

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

struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
mir: &'a Body<'tcx>,
body: &'a Body<'tcx>,
idx_vec: IndexVec<BorrowIndex, BorrowData<'tcx>>,
location_map: FxHashMap<Location, BorrowIndex>,
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
) {
if let mir::Rvalue::Ref(region, kind, ref borrowed_place) = *rvalue {
if borrowed_place.ignore_borrow(
self.tcx, self.mir, &self.locals_state_at_exit) {
self.tcx, self.body, &self.locals_state_at_exit) {
return;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
if let TwoPhaseActivation::ActivatedAt(other_location) =
borrow_data.activation_location {
span_bug!(
self.mir.source_info(location).span,
self.body.source_info(location).span,
"found two uses for 2-phase borrow temporary {:?}: \
{:?} and {:?}",
temp,
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
temp
} else {
span_bug!(
self.mir.source_info(start_location).span,
self.body.source_info(start_location).span,
"expected 2-phase borrow to assign to a local, not `{:?}`",
assigned_place,
);
Expand All @@ -339,7 +339,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
// assignment.
let old_value = self.pending_activations.insert(temp, borrow_index);
if let Some(old_index) = old_value {
span_bug!(self.mir.source_info(start_location).span,
span_bug!(self.body.source_info(start_location).span,
"found already pending activation for temp: {:?} \
at borrow_index: {:?} with associated data {:?}",
temp, old_index, self.idx_vec[old_index]);
Expand Down
Loading