make the basic_blocks field private
This commit is contained in:
parent
bc1eb67721
commit
e3af9fa490
24 changed files with 203 additions and 200 deletions
|
|
@ -55,7 +55,7 @@ macro_rules! newtype_index {
|
|||
pub struct Mir<'tcx> {
|
||||
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
|
||||
/// that indexes into this vector.
|
||||
pub basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
|
||||
/// List of visibility (lexical) scopes; these are referenced by statements
|
||||
/// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`.
|
||||
|
|
@ -94,18 +94,37 @@ pub struct Mir<'tcx> {
|
|||
pub const START_BLOCK: BasicBlock = BasicBlock(0);
|
||||
|
||||
impl<'tcx> Mir<'tcx> {
|
||||
pub fn all_basic_blocks(&self) -> Vec<BasicBlock> {
|
||||
(0..self.basic_blocks.len())
|
||||
.map(|i| BasicBlock::new(i))
|
||||
.collect()
|
||||
pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
|
||||
promoted: IndexVec<Promoted, Mir<'tcx>>,
|
||||
return_ty: FnOutput<'tcx>,
|
||||
var_decls: IndexVec<Var, VarDecl<'tcx>>,
|
||||
arg_decls: IndexVec<Arg, ArgDecl<'tcx>>,
|
||||
temp_decls: IndexVec<Temp, TempDecl<'tcx>>,
|
||||
upvar_decls: Vec<UpvarDecl>,
|
||||
span: Span) -> Self
|
||||
{
|
||||
Mir {
|
||||
basic_blocks: basic_blocks,
|
||||
visibility_scopes: visibility_scopes,
|
||||
promoted: promoted,
|
||||
return_ty: return_ty,
|
||||
var_decls: var_decls,
|
||||
arg_decls: arg_decls,
|
||||
temp_decls: temp_decls,
|
||||
upvar_decls: upvar_decls,
|
||||
span: span
|
||||
}
|
||||
}
|
||||
|
||||
pub fn basic_block_data(&self, bb: BasicBlock) -> &BasicBlockData<'tcx> {
|
||||
&self.basic_blocks[bb]
|
||||
#[inline]
|
||||
pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
|
||||
&self.basic_blocks
|
||||
}
|
||||
|
||||
pub fn basic_block_data_mut(&mut self, bb: BasicBlock) -> &mut BasicBlockData<'tcx> {
|
||||
&mut self.basic_blocks[bb]
|
||||
#[inline]
|
||||
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
|
||||
&mut self.basic_blocks
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,14 +133,14 @@ impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
|
|||
|
||||
#[inline]
|
||||
fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
|
||||
self.basic_block_data(index)
|
||||
&self.basic_blocks()[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
|
||||
self.basic_block_data_mut(index)
|
||||
&mut self.basic_blocks_mut()[index]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
|
|||
|
||||
Preorder {
|
||||
mir: mir,
|
||||
visited: BitVector::new(mir.basic_blocks.len()),
|
||||
visited: BitVector::new(mir.basic_blocks().len()),
|
||||
worklist: worklist
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let data = self.mir.basic_block_data(idx);
|
||||
let data = &self.mir[idx];
|
||||
|
||||
if let Some(ref term) = data.terminator {
|
||||
for &succ in term.successors().iter() {
|
||||
|
|
@ -107,12 +107,12 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
|
|||
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
|
||||
let mut po = Postorder {
|
||||
mir: mir,
|
||||
visited: BitVector::new(mir.basic_blocks.len()),
|
||||
visited: BitVector::new(mir.basic_blocks().len()),
|
||||
visit_stack: Vec::new()
|
||||
};
|
||||
|
||||
|
||||
let data = po.mir.basic_block_data(root);
|
||||
let data = &po.mir[root];
|
||||
|
||||
if let Some(ref term) = data.terminator {
|
||||
po.visited.insert(root.index());
|
||||
|
|
@ -186,9 +186,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
|
|||
};
|
||||
|
||||
if self.visited.insert(bb.index()) {
|
||||
let data = self.mir.basic_block_data(bb);
|
||||
|
||||
if let Some(ref term) = data.terminator {
|
||||
if let Some(ref term) = self.mir[bb].terminator {
|
||||
let succs = term.successors().into_owned().into_iter();
|
||||
self.visit_stack.push((bb, succs));
|
||||
}
|
||||
|
|
@ -210,10 +208,7 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
|
|||
self.traverse_successor();
|
||||
}
|
||||
|
||||
next.map(|(bb, _)| {
|
||||
let data = self.mir.basic_block_data(bb);
|
||||
(bb, data)
|
||||
})
|
||||
next.map(|(bb, _)| (bb, &self.mir[bb]))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,9 +274,6 @@ impl<'a, 'tcx> Iterator for ReversePostorder<'a, 'tcx> {
|
|||
if self.idx == 0 { return None; }
|
||||
self.idx -= 1;
|
||||
|
||||
self.blocks.get(self.idx).map(|&bb| {
|
||||
let data = self.mir.basic_block_data(bb);
|
||||
(bb, data)
|
||||
})
|
||||
self.blocks.get(self.idx).map(|&bb| (bb, &self.mir[bb]))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,42 +252,30 @@ macro_rules! make_mir_visitor {
|
|||
|
||||
fn super_mir(&mut self,
|
||||
mir: & $($mutability)* Mir<'tcx>) {
|
||||
let Mir {
|
||||
ref $($mutability)* basic_blocks,
|
||||
ref $($mutability)* visibility_scopes,
|
||||
promoted: _, // Visited by passes separately.
|
||||
ref $($mutability)* return_ty,
|
||||
ref $($mutability)* var_decls,
|
||||
ref $($mutability)* arg_decls,
|
||||
ref $($mutability)* temp_decls,
|
||||
upvar_decls: _,
|
||||
ref $($mutability)* span,
|
||||
} = *mir;
|
||||
|
||||
for (index, data) in basic_blocks.into_iter().enumerate() {
|
||||
for index in 0..mir.basic_blocks().len() {
|
||||
let block = BasicBlock::new(index);
|
||||
self.visit_basic_block_data(block, data);
|
||||
self.visit_basic_block_data(block, &$($mutability)* mir[block]);
|
||||
}
|
||||
|
||||
for scope in visibility_scopes {
|
||||
for scope in &$($mutability)* mir.visibility_scopes {
|
||||
self.visit_visibility_scope_data(scope);
|
||||
}
|
||||
|
||||
self.visit_fn_output(return_ty);
|
||||
self.visit_fn_output(&$($mutability)* mir.return_ty);
|
||||
|
||||
for var_decl in var_decls {
|
||||
for var_decl in &$($mutability)* mir.var_decls {
|
||||
self.visit_var_decl(var_decl);
|
||||
}
|
||||
|
||||
for arg_decl in arg_decls {
|
||||
for arg_decl in &$($mutability)* mir.arg_decls {
|
||||
self.visit_arg_decl(arg_decl);
|
||||
}
|
||||
|
||||
for temp_decl in temp_decls {
|
||||
for temp_decl in &$($mutability)* mir.temp_decls {
|
||||
self.visit_temp_decl(temp_decl);
|
||||
}
|
||||
|
||||
self.visit_span(span);
|
||||
self.visit_span(&$($mutability)* mir.span);
|
||||
}
|
||||
|
||||
fn super_basic_block_data(&mut self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue