Skip to content

Commit 938d024

Browse files
Rename mir::BasicBlock to mir::Block.
This introduces no functional changes, but is in preparation for adding extended basic blocks to MIR.
1 parent 49c67bd commit 938d024

Some content is hidden

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

44 files changed

+343
-332
lines changed

src/librustc/mir/cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
use std::cell::{Ref, RefCell};
1212
use rustc_data_structures::indexed_vec::IndexVec;
1313

14-
use mir::{Mir, BasicBlock};
14+
use mir::{Mir, Block};
1515

1616
use rustc_serialize as serialize;
1717

1818
#[derive(Clone, Debug)]
1919
pub struct Cache {
20-
predecessors: RefCell<Option<IndexVec<BasicBlock, Vec<BasicBlock>>>>
20+
predecessors: RefCell<Option<IndexVec<Block, Vec<Block>>>>
2121
}
2222

2323

@@ -46,7 +46,7 @@ impl Cache {
4646
*self.predecessors.borrow_mut() = None;
4747
}
4848

49-
pub fn predecessors(&self, mir: &Mir) -> Ref<IndexVec<BasicBlock, Vec<BasicBlock>>> {
49+
pub fn predecessors(&self, mir: &Mir) -> Ref<IndexVec<Block, Vec<Block>>> {
5050
if self.predecessors.borrow().is_none() {
5151
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
5252
}
@@ -55,7 +55,7 @@ impl Cache {
5555
}
5656
}
5757

58-
fn calculate_predecessors(mir: &Mir) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
58+
fn calculate_predecessors(mir: &Mir) -> IndexVec<Block, Vec<Block>> {
5959
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
6060
for (bb, data) in mir.basic_blocks().iter_enumerated() {
6161
if let Some(ref term) = data.terminator {

src/librustc/mir/mod.rs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ macro_rules! newtype_index {
6666
/// Lowered representation of a single function.
6767
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
6868
pub struct Mir<'tcx> {
69-
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
69+
/// List of basic blocks. References to basic block use a newtyped index type `Block`
7070
/// that indexes into this vector.
71-
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
71+
basic_blocks: IndexVec<Block, BlockData<'tcx>>,
7272

7373
/// List of visibility (lexical) scopes; these are referenced by statements
7474
/// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`.
@@ -115,10 +115,10 @@ pub struct Mir<'tcx> {
115115
}
116116

117117
/// where execution begins
118-
pub const START_BLOCK: BasicBlock = BasicBlock(0);
118+
pub const START_BLOCK: Block = Block(0);
119119

120120
impl<'tcx> Mir<'tcx> {
121-
pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
121+
pub fn new(basic_blocks: IndexVec<Block, BlockData<'tcx>>,
122122
visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
123123
promoted: IndexVec<Promoted, Mir<'tcx>>,
124124
return_ty: Ty<'tcx>,
@@ -147,28 +147,28 @@ impl<'tcx> Mir<'tcx> {
147147
}
148148

149149
#[inline]
150-
pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
150+
pub fn basic_blocks(&self) -> &IndexVec<Block, BlockData<'tcx>> {
151151
&self.basic_blocks
152152
}
153153

154154
#[inline]
155-
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
155+
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<Block, BlockData<'tcx>> {
156156
self.cache.invalidate();
157157
&mut self.basic_blocks
158158
}
159159

160160
#[inline]
161-
pub fn predecessors(&self) -> Ref<IndexVec<BasicBlock, Vec<BasicBlock>>> {
161+
pub fn predecessors(&self) -> Ref<IndexVec<Block, Vec<Block>>> {
162162
self.cache.predecessors(self)
163163
}
164164

165165
#[inline]
166-
pub fn predecessors_for(&self, bb: BasicBlock) -> Ref<Vec<BasicBlock>> {
166+
pub fn predecessors_for(&self, bb: Block) -> Ref<Vec<Block>> {
167167
Ref::map(self.predecessors(), |p| &p[bb])
168168
}
169169

170170
#[inline]
171-
pub fn dominators(&self) -> Dominators<BasicBlock> {
171+
pub fn dominators(&self) -> Dominators<Block> {
172172
dominators(self)
173173
}
174174

@@ -243,18 +243,18 @@ impl<'tcx> Mir<'tcx> {
243243
}
244244
}
245245

246-
impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
247-
type Output = BasicBlockData<'tcx>;
246+
impl<'tcx> Index<Block> for Mir<'tcx> {
247+
type Output = BlockData<'tcx>;
248248

249249
#[inline]
250-
fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
250+
fn index(&self, index: Block) -> &BlockData<'tcx> {
251251
&self.basic_blocks()[index]
252252
}
253253
}
254254

255-
impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
255+
impl<'tcx> IndexMut<Block> for Mir<'tcx> {
256256
#[inline]
257-
fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
257+
fn index_mut(&mut self, index: Block) -> &mut BlockData<'tcx> {
258258
&mut self.basic_blocks_mut()[index]
259259
}
260260
}
@@ -411,15 +411,15 @@ pub struct UpvarDecl {
411411
}
412412

413413
///////////////////////////////////////////////////////////////////////////
414-
// BasicBlock
414+
// Block
415415

416-
newtype_index!(BasicBlock, "bb");
416+
newtype_index!(Block, "bb");
417417

418418
///////////////////////////////////////////////////////////////////////////
419-
// BasicBlockData and Terminator
419+
// BlockData and Terminator
420420

421421
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
422-
pub struct BasicBlockData<'tcx> {
422+
pub struct BlockData<'tcx> {
423423
/// List of statements in this block.
424424
pub statements: Vec<Statement<'tcx>>,
425425

@@ -450,7 +450,7 @@ pub struct Terminator<'tcx> {
450450
pub enum TerminatorKind<'tcx> {
451451
/// block should have one successor in the graph; we jump there
452452
Goto {
453-
target: BasicBlock,
453+
target: Block,
454454
},
455455

456456
/// operand evaluates to an integer; jump depending on its value
@@ -472,12 +472,12 @@ pub enum TerminatorKind<'tcx> {
472472
// This invariant is quite non-obvious and also could be improved.
473473
// One way to make this invariant is to have something like this instead:
474474
//
475-
// branches: Vec<(ConstInt, BasicBlock)>,
476-
// otherwise: Option<BasicBlock> // exhaustive if None
475+
// branches: Vec<(ConstInt, Block)>,
476+
// otherwise: Option<Block> // exhaustive if None
477477
//
478478
// However we’ve decided to keep this as-is until we figure a case
479479
// where some other approach seems to be strictly better than other.
480-
targets: Vec<BasicBlock>,
480+
targets: Vec<Block>,
481481
},
482482

483483
/// Indicates that the landing pad is finished and unwinding should
@@ -494,16 +494,16 @@ pub enum TerminatorKind<'tcx> {
494494
/// Drop the Lvalue
495495
Drop {
496496
location: Lvalue<'tcx>,
497-
target: BasicBlock,
498-
unwind: Option<BasicBlock>
497+
target: Block,
498+
unwind: Option<Block>
499499
},
500500

501501
/// Drop the Lvalue and assign the new value over it
502502
DropAndReplace {
503503
location: Lvalue<'tcx>,
504504
value: Operand<'tcx>,
505-
target: BasicBlock,
506-
unwind: Option<BasicBlock>,
505+
target: Block,
506+
unwind: Option<Block>,
507507
},
508508

509509
/// Block ends with a call of a converging function
@@ -513,9 +513,9 @@ pub enum TerminatorKind<'tcx> {
513513
/// Arguments the function is called with
514514
args: Vec<Operand<'tcx>>,
515515
/// Destination for the return value. If some, the call is converging.
516-
destination: Option<(Lvalue<'tcx>, BasicBlock)>,
516+
destination: Option<(Lvalue<'tcx>, Block)>,
517517
/// Cleanups to be done if the call unwinds.
518-
cleanup: Option<BasicBlock>
518+
cleanup: Option<Block>
519519
},
520520

521521
/// Jump to the target if the condition has the expected value,
@@ -524,24 +524,24 @@ pub enum TerminatorKind<'tcx> {
524524
cond: Operand<'tcx>,
525525
expected: bool,
526526
msg: AssertMessage<'tcx>,
527-
target: BasicBlock,
528-
cleanup: Option<BasicBlock>
527+
target: Block,
528+
cleanup: Option<Block>
529529
}
530530
}
531531

532532
impl<'tcx> Terminator<'tcx> {
533-
pub fn successors(&self) -> Cow<[BasicBlock]> {
533+
pub fn successors(&self) -> Cow<[Block]> {
534534
self.kind.successors()
535535
}
536536

537-
pub fn successors_mut(&mut self) -> Vec<&mut BasicBlock> {
537+
pub fn successors_mut(&mut self) -> Vec<&mut Block> {
538538
self.kind.successors_mut()
539539
}
540540
}
541541

542542
impl<'tcx> TerminatorKind<'tcx> {
543543
pub fn if_<'a, 'gcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>, cond: Operand<'tcx>,
544-
t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
544+
t: Block, f: Block) -> TerminatorKind<'tcx> {
545545
static BOOL_SWITCH_FALSE: &'static [ConstInt] = &[ConstInt::U8(0)];
546546
TerminatorKind::SwitchInt {
547547
discr: cond,
@@ -551,7 +551,7 @@ impl<'tcx> TerminatorKind<'tcx> {
551551
}
552552
}
553553

554-
pub fn successors(&self) -> Cow<[BasicBlock]> {
554+
pub fn successors(&self) -> Cow<[Block]> {
555555
use self::TerminatorKind::*;
556556
match *self {
557557
Goto { target: ref b } => slice::ref_slice(b).into_cow(),
@@ -577,9 +577,9 @@ impl<'tcx> TerminatorKind<'tcx> {
577577
}
578578
}
579579

580-
// FIXME: no mootable cow. I’m honestly not sure what a “cow” between `&mut [BasicBlock]` and
581-
// `Vec<&mut BasicBlock>` would look like in the first place.
582-
pub fn successors_mut(&mut self) -> Vec<&mut BasicBlock> {
580+
// FIXME: no mootable cow. I’m honestly not sure what a “cow” between `&mut [Block]` and
581+
// `Vec<&mut Block>` would look like in the first place.
582+
pub fn successors_mut(&mut self) -> Vec<&mut Block> {
583583
use self::TerminatorKind::*;
584584
match *self {
585585
Goto { target: ref mut b } => vec![b],
@@ -603,9 +603,9 @@ impl<'tcx> TerminatorKind<'tcx> {
603603
}
604604
}
605605

606-
impl<'tcx> BasicBlockData<'tcx> {
607-
pub fn new(terminator: Option<Terminator<'tcx>>) -> BasicBlockData<'tcx> {
608-
BasicBlockData {
606+
impl<'tcx> BlockData<'tcx> {
607+
pub fn new(terminator: Option<Terminator<'tcx>>) -> BlockData<'tcx> {
608+
BlockData {
609609
statements: vec![],
610610
terminator: terminator,
611611
is_cleanup: false,
@@ -1296,7 +1296,7 @@ fn item_path_str(def_id: DefId) -> String {
12961296

12971297
impl<'tcx> ControlFlowGraph for Mir<'tcx> {
12981298

1299-
type Node = BasicBlock;
1299+
type Node = Block;
13001300

13011301
fn num_nodes(&self) -> usize { self.basic_blocks.len() }
13021302

@@ -1315,19 +1315,19 @@ impl<'tcx> ControlFlowGraph for Mir<'tcx> {
13151315
}
13161316

13171317
impl<'a, 'b> GraphPredecessors<'b> for Mir<'a> {
1318-
type Item = BasicBlock;
1319-
type Iter = IntoIter<BasicBlock>;
1318+
type Item = Block;
1319+
type Iter = IntoIter<Block>;
13201320
}
13211321

13221322
impl<'a, 'b> GraphSuccessors<'b> for Mir<'a> {
1323-
type Item = BasicBlock;
1324-
type Iter = IntoIter<BasicBlock>;
1323+
type Item = Block;
1324+
type Iter = IntoIter<Block>;
13251325
}
13261326

13271327
#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
13281328
pub struct Location {
13291329
/// the location is within this block
1330-
pub block: BasicBlock,
1330+
pub block: Block,
13311331

13321332
/// the location is the start of the this statement; or, if `statement_index`
13331333
/// == num-statements, then the start of the terminator.
@@ -1341,7 +1341,7 @@ impl fmt::Debug for Location {
13411341
}
13421342

13431343
impl Location {
1344-
pub fn dominates(&self, other: &Location, dominators: &Dominators<BasicBlock>) -> bool {
1344+
pub fn dominates(&self, other: &Location, dominators: &Dominators<Block>) -> bool {
13451345
if self.block == other.block {
13461346
self.statement_index <= other.statement_index
13471347
} else {
@@ -1392,9 +1392,9 @@ impl<'tcx> TypeFoldable<'tcx> for LocalDecl<'tcx> {
13921392
}
13931393
}
13941394

1395-
impl<'tcx> TypeFoldable<'tcx> for BasicBlockData<'tcx> {
1395+
impl<'tcx> TypeFoldable<'tcx> for BlockData<'tcx> {
13961396
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1397-
BasicBlockData {
1397+
BlockData {
13981398
statements: self.statements.fold_with(folder),
13991399
terminator: self.terminator.fold_with(folder),
14001400
is_cleanup: self.is_cleanup

src/librustc/mir/traversal.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ use super::*;
3636
pub struct Preorder<'a, 'tcx: 'a> {
3737
mir: &'a Mir<'tcx>,
3838
visited: BitVector,
39-
worklist: Vec<BasicBlock>,
39+
worklist: Vec<Block>,
4040
}
4141

4242
impl<'a, 'tcx> Preorder<'a, 'tcx> {
43-
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
43+
pub fn new(mir: &'a Mir<'tcx>, root: Block) -> Preorder<'a, 'tcx> {
4444
let worklist = vec![root];
4545

4646
Preorder {
@@ -56,9 +56,9 @@ pub fn preorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Preorder<'a, 'tcx> {
5656
}
5757

5858
impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
59-
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
59+
type Item = (Block, &'a BlockData<'tcx>);
6060

61-
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
61+
fn next(&mut self) -> Option<(Block, &'a BlockData<'tcx>)> {
6262
while let Some(idx) = self.worklist.pop() {
6363
if !self.visited.insert(idx.index()) {
6464
continue;
@@ -100,11 +100,11 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
100100
pub struct Postorder<'a, 'tcx: 'a> {
101101
mir: &'a Mir<'tcx>,
102102
visited: BitVector,
103-
visit_stack: Vec<(BasicBlock, vec::IntoIter<BasicBlock>)>
103+
visit_stack: Vec<(Block, vec::IntoIter<Block>)>
104104
}
105105

106106
impl<'a, 'tcx> Postorder<'a, 'tcx> {
107-
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
107+
pub fn new(mir: &'a Mir<'tcx>, root: Block) -> Postorder<'a, 'tcx> {
108108
let mut po = Postorder {
109109
mir: mir,
110110
visited: BitVector::new(mir.basic_blocks().len()),
@@ -200,9 +200,9 @@ pub fn postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Postorder<'a, 'tcx> {
200200
}
201201

202202
impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
203-
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
203+
type Item = (Block, &'a BlockData<'tcx>);
204204

205-
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
205+
fn next(&mut self) -> Option<(Block, &'a BlockData<'tcx>)> {
206206
let next = self.visit_stack.pop();
207207
if next.is_some() {
208208
self.traverse_successor();
@@ -240,12 +240,12 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
240240
#[derive(Clone)]
241241
pub struct ReversePostorder<'a, 'tcx: 'a> {
242242
mir: &'a Mir<'tcx>,
243-
blocks: Vec<BasicBlock>,
243+
blocks: Vec<Block>,
244244
idx: usize
245245
}
246246

247247
impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
248-
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> {
248+
pub fn new(mir: &'a Mir<'tcx>, root: Block) -> ReversePostorder<'a, 'tcx> {
249249
let blocks : Vec<_> = Postorder::new(mir, root).map(|(bb, _)| bb).collect();
250250

251251
let len = blocks.len();
@@ -268,9 +268,9 @@ pub fn reverse_postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> ReversePostorder<'a, '
268268
}
269269

270270
impl<'a, 'tcx> Iterator for ReversePostorder<'a, 'tcx> {
271-
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
271+
type Item = (Block, &'a BlockData<'tcx>);
272272

273-
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
273+
fn next(&mut self) -> Option<(Block, &'a BlockData<'tcx>)> {
274274
if self.idx == 0 { return None; }
275275
self.idx -= 1;
276276

0 commit comments

Comments
 (0)