Skip to content

Commit fdf80bc

Browse files
committed
Removed type Bit and fn interpret items from trait BitDenotation.
Also got rid of the `trait HasMoveData`, since I am now just imposing the constraint that `BitDenotation<Ctxt=MoveData<'tcx>>` where necessary instead.
1 parent 0cf5f10 commit fdf80bc

File tree

5 files changed

+21
-62
lines changed

5 files changed

+21
-62
lines changed

src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn print_borrowck_graph_to<'a, 'tcx, BD, P>(
109109
path: &Path,
110110
render_idx: P)
111111
-> io::Result<()>
112-
where BD: BitDenotation<Ctxt=MoveData<'tcx>>, BD::Bit: Debug,
112+
where BD: BitDenotation<Ctxt=MoveData<'tcx>>,
113113
P: for <'b> Fn(&'b BD::Ctxt, BD::Idx) -> &'b Debug
114114
{
115115
let g = Graph { mbcx: mbcx, phantom: PhantomData, render_idx: render_idx };
@@ -131,7 +131,7 @@ fn outgoing(mir: &Mir, bb: BasicBlock) -> Vec<Edge> {
131131
}
132132

133133
impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
134-
where MWF: MirWithFlowState<'tcx>, <MWF::BD as BitDenotation>::Bit: Debug,
134+
where MWF: MirWithFlowState<'tcx>,
135135
P: for <'b> Fn(&'b <MWF::BD as BitDenotation>::Ctxt, <MWF::BD as BitDenotation>::Idx) -> &'b Debug,
136136
{
137137
type Node = Node;

src/librustc_borrowck/borrowck/mir/dataflow/impls.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::ty::TyCtxt;
1212
use rustc::mir::repr::{self, Mir};
1313

1414
use super::super::gather_moves::{Location};
15-
use super::super::gather_moves::{MoveData, MoveOut, MoveOutIndex, MovePath, MovePathIndex};
15+
use super::super::gather_moves::{MoveData, MoveOutIndex, MovePathIndex};
1616
use super::super::DropFlagState;
1717
use super::super::drop_flag_effects_for_function_entry;
1818
use super::super::drop_flag_effects_for_location;
@@ -226,15 +226,12 @@ impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
226226

227227
impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
228228
type Idx = MovePathIndex;
229-
type Bit = MovePath<'tcx>;
230229
type Ctxt = MoveData<'tcx>;
231230
fn name() -> &'static str { "maybe_init" }
232231
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
233232
ctxt.move_paths.len()
234233
}
235-
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
236-
&ctxt.move_paths[MovePathIndex::new(idx)]
237-
}
234+
238235
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>)
239236
{
240237
drop_flag_effects_for_function_entry(
@@ -288,15 +285,11 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
288285

289286
impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
290287
type Idx = MovePathIndex;
291-
type Bit = MovePath<'tcx>;
292288
type Ctxt = MoveData<'tcx>;
293289
fn name() -> &'static str { "maybe_uninit" }
294290
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
295291
ctxt.move_paths.len()
296292
}
297-
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
298-
&ctxt.move_paths[MovePathIndex::new(idx)]
299-
}
300293

301294
// sets on_entry bits for Arg lvalues
302295
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>) {
@@ -354,15 +347,11 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
354347

355348
impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
356349
type Idx = MovePathIndex;
357-
type Bit = MovePath<'tcx>;
358350
type Ctxt = MoveData<'tcx>;
359351
fn name() -> &'static str { "definite_init" }
360352
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
361353
ctxt.move_paths.len()
362354
}
363-
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
364-
&ctxt.move_paths[MovePathIndex::new(idx)]
365-
}
366355

367356
// sets on_entry bits for Arg lvalues
368357
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>) {
@@ -419,15 +408,12 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
419408

420409
impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
421410
type Idx = MoveOutIndex;
422-
type Bit = MoveOut;
423411
type Ctxt = MoveData<'tcx>;
424412
fn name() -> &'static str { "moving_out" }
425413
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
426414
ctxt.moves.len()
427415
}
428-
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
429-
&ctxt.moves[idx]
430-
}
416+
431417
fn start_block_effect(&self,_move_data: &Self::Ctxt, _sets: &mut BlockSets<MoveOutIndex>) {
432418
// no move-statements have been executed prior to function
433419
// execution, so this method has no effect on `_sets`.

src/librustc_borrowck/borrowck/mir/dataflow/mod.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ pub trait Dataflow<BD: BitDenotation> {
3636
}
3737

3838
impl<'a, 'tcx: 'a, BD> Dataflow<BD> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
39-
where BD: BitDenotation<Ctxt=MoveData<'tcx>> + DataflowOperator,
40-
BD::Bit: Debug,
39+
where BD: BitDenotation<Ctxt=MoveData<'tcx>> + DataflowOperator
4140
{
4241
fn dataflow<P>(&mut self, p: P) where P: Fn(&BD::Ctxt, BD::Idx) -> &Debug {
4342
self.flow_state.build_sets();
@@ -48,14 +47,14 @@ impl<'a, 'tcx: 'a, BD> Dataflow<BD> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
4847
}
4948

5049
struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O>
51-
where O: 'b + BitDenotation, O::Ctxt: 'a+HasMoveData<'tcx>
50+
where O: 'b + BitDenotation, O::Ctxt: 'a
5251
{
5352
builder: &'b mut DataflowAnalysis<'a, 'tcx, O>,
5453
changed: bool,
5554
}
5655

5756
impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
58-
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
57+
where BD: BitDenotation + DataflowOperator
5958
{
6059
fn propagate(&mut self) {
6160
let mut temp = OwnIdxSet::new_empty(self.flow_state.sets.bits_per_block);
@@ -102,7 +101,7 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
102101
}
103102

104103
impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD>
105-
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
104+
where BD: BitDenotation + DataflowOperator
106105
{
107106
fn reset(&mut self, bits: &mut IdxSet<BD::Idx>) {
108107
let e = if BD::bottom_value() {!0} else {0};
@@ -141,7 +140,7 @@ fn dataflow_path(context: &str, prepost: &str, path: &str) -> PathBuf {
141140
}
142141

143142
impl<'a, 'tcx: 'a, BD> MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
144-
where BD: BitDenotation<Ctxt=MoveData<'tcx>>, BD::Bit: Debug
143+
where BD: BitDenotation<Ctxt=MoveData<'tcx>>
145144
{
146145
fn pre_dataflow_instrumentation<P>(&self, p: P) -> io::Result<()>
147146
where P: Fn(&BD::Ctxt, BD::Idx) -> &Debug
@@ -182,27 +181,16 @@ impl<E:Idx> Bits<E> {
182181
}
183182
}
184183

185-
pub trait HasMoveData<'tcx> {
186-
fn move_data(&self) -> &MoveData<'tcx>;
187-
}
188-
189-
impl<'tcx> HasMoveData<'tcx> for MoveData<'tcx> {
190-
fn move_data(&self) -> &MoveData<'tcx> { self }
191-
}
192-
impl<'tcx, A, B> HasMoveData<'tcx> for (A, B, MoveData<'tcx>) {
193-
fn move_data(&self) -> &MoveData<'tcx> { &self.2 }
194-
}
195-
196184
pub struct DataflowAnalysis<'a, 'tcx: 'a, O>
197-
where O: BitDenotation, O::Ctxt: 'a+HasMoveData<'tcx>
185+
where O: BitDenotation, O::Ctxt: 'a
198186
{
199187
flow_state: DataflowState<O>,
200188
mir: &'a Mir<'tcx>,
201189
ctxt: &'a O::Ctxt,
202190
}
203191

204192
impl<'a, 'tcx: 'a, O> DataflowAnalysis<'a, 'tcx, O>
205-
where O: BitDenotation, O::Ctxt: HasMoveData<'tcx>
193+
where O: BitDenotation
206194
{
207195
pub fn results(self) -> DataflowResults<O> {
208196
DataflowResults(self.flow_state)
@@ -301,9 +289,6 @@ pub trait DataflowOperator: BitwiseOperator {
301289
}
302290

303291
pub trait BitDenotation {
304-
/// Specifies what is represented by each bit in the dataflow bitvector.
305-
type Bit;
306-
307292
/// Specifies what index type is used to access the bitvector.
308293
type Idx: Idx;
309294

@@ -322,10 +307,6 @@ pub trait BitDenotation {
322307
/// Size of each bitvector allocated for each block in the analysis.
323308
fn bits_per_block(&self, &Self::Ctxt) -> usize;
324309

325-
/// Provides the meaning of each entry in the dataflow bitvector.
326-
/// (Mostly intended for use for better debug instrumentation.)
327-
fn interpret<'a>(&self, &'a Self::Ctxt, idx: usize) -> &'a Self::Bit;
328-
329310
/// Mutates the block-sets (the flow sets for the given
330311
/// basic block) according to the effects that have been
331312
/// established *prior* to entering the start block.
@@ -396,8 +377,7 @@ pub trait BitDenotation {
396377
}
397378

398379
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
399-
where D: BitDenotation + DataflowOperator,
400-
D::Ctxt: HasMoveData<'tcx>
380+
where D: BitDenotation + DataflowOperator
401381
{
402382
pub fn new(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
403383
mir: &'a Mir<'tcx>,
@@ -439,8 +419,7 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
439419
}
440420

441421
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
442-
where D: BitDenotation + DataflowOperator,
443-
D::Ctxt: HasMoveData<'tcx>,
422+
where D: BitDenotation + DataflowOperator
444423
{
445424
/// Propagates the bits of `in_out` into all the successors of `bb`,
446425
/// using bitwise operator denoted by `self.operator`.

src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ use syntax::codemap::Span;
1515
use rustc::ty::{self, TyCtxt};
1616
use rustc::mir::repr::{self, Mir};
1717

18-
use super::super::gather_moves::{MovePath, MovePathIndex};
18+
use super::super::gather_moves::{MoveData, MovePathIndex};
1919
use super::BitDenotation;
2020
use super::DataflowResults;
21-
use super::HasMoveData;
2221

2322
/// This function scans `mir` for all calls to the intrinsic
2423
/// `rustc_peek` that have the expression form `rustc_peek(&expr)`.
@@ -42,7 +41,7 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4241
_attributes: &[ast::Attribute],
4342
flow_ctxt: &O::Ctxt,
4443
results: &DataflowResults<O>)
45-
where O: BitDenotation<Bit=MovePath<'tcx>, Idx=MovePathIndex>, O::Ctxt: HasMoveData<'tcx>
44+
where O: BitDenotation<Ctxt=MoveData<'tcx>, Idx=MovePathIndex>
4645
{
4746
debug!("sanity_check_via_rustc_peek id: {:?}", id);
4847
// FIXME: this is not DRY. Figure out way to abstract this and
@@ -57,10 +56,10 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5756

5857
fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5958
mir: &Mir<'tcx>,
60-
flow_ctxt: &O::Ctxt,
59+
move_data: &O::Ctxt,
6160
results: &DataflowResults<O>,
6261
bb: repr::BasicBlock) where
63-
O: BitDenotation<Bit=MovePath<'tcx>, Idx=MovePathIndex>, O::Ctxt: HasMoveData<'tcx>
62+
O: BitDenotation<Ctxt=MoveData<'tcx>, Idx=MovePathIndex>
6463
{
6564
let bb_data = mir.basic_block_data(bb);
6665
let &repr::BasicBlockData { ref statements,
@@ -88,8 +87,6 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
8887
let mut gen = results.0.sets.gen_set_for(bb.index()).to_owned();
8988
let mut kill = results.0.sets.kill_set_for(bb.index()).to_owned();
9089

91-
let move_data = flow_ctxt.move_data();
92-
9390
// Emulate effect of all statements in the block up to (but not
9491
// including) the borrow within `peek_arg_lval`. Do *not* include
9592
// call to `peek_arg_lval` itself (since we are peeking the state
@@ -138,7 +135,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
138135
// reset GEN and KILL sets before emulating their effect.
139136
for e in sets.gen_set.words_mut() { *e = 0; }
140137
for e in sets.kill_set.words_mut() { *e = 0; }
141-
results.0.operator.statement_effect(flow_ctxt, &mut sets, bb, j);
138+
results.0.operator.statement_effect(move_data, &mut sets, bb, j);
142139
sets.on_entry.union(sets.gen_set);
143140
sets.on_entry.subtract(sets.kill_set);
144141
}

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@ mod gather_moves;
3131
use self::dataflow::{BitDenotation};
3232
use self::dataflow::{DataflowOperator};
3333
use self::dataflow::{Dataflow, DataflowAnalysis, DataflowResults};
34-
use self::dataflow::{HasMoveData};
3534
use self::dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
3635
use self::dataflow::{DefinitelyInitializedLvals};
3736
use self::gather_moves::{MoveData, MovePathIndex, Location};
3837
use self::gather_moves::{MovePathContent};
3938

40-
use std::fmt::Debug;
41-
4239
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<P<MetaItem>> {
4340
for attr in attrs {
4441
if attr.check_name("rustc_mir") {
@@ -118,7 +115,7 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
118115
attributes: &[ast::Attribute],
119116
ctxt: &BD::Ctxt,
120117
bd: BD) -> DataflowResults<BD>
121-
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveData<'tcx>> + DataflowOperator, BD::Bit: Debug
118+
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveData<'tcx>> + DataflowOperator
122119
{
123120
use syntax::attr::AttrMetaMethods;
124121

@@ -154,7 +151,7 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
154151

155152

156153
pub struct MirBorrowckCtxtPreDataflow<'a, 'tcx: 'a, BD>
157-
where BD: BitDenotation, BD::Ctxt: 'a+HasMoveData<'tcx>
154+
where BD: BitDenotation, BD::Ctxt: 'a
158155
{
159156
node_id: ast::NodeId,
160157
flow_state: DataflowAnalysis<'a, 'tcx, BD>,

0 commit comments

Comments
 (0)