Skip to content

Commit cff060b

Browse files
committed
Refactor trait BitDenotation to take Location instead of BasicBlock/usize argument pairs.
1 parent 8e79fc7 commit cff060b

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,22 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
287287

288288
fn statement_effect(&self,
289289
sets: &mut BlockSets<MovePathIndex>,
290-
bb: mir::BasicBlock,
291-
idx: usize)
290+
location: Location)
292291
{
293292
drop_flag_effects_for_location(
294293
self.tcx, self.mir, self.mdpe,
295-
Location { block: bb, statement_index: idx },
294+
location,
296295
|path, s| Self::update_bits(sets, path, s)
297296
)
298297
}
299298

300299
fn terminator_effect(&self,
301300
sets: &mut BlockSets<MovePathIndex>,
302-
bb: mir::BasicBlock,
303-
statements_len: usize)
301+
location: Location)
304302
{
305303
drop_flag_effects_for_location(
306304
self.tcx, self.mir, self.mdpe,
307-
Location { block: bb, statement_index: statements_len },
305+
location,
308306
|path, s| Self::update_bits(sets, path, s)
309307
)
310308
}
@@ -344,24 +342,22 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
344342

345343
fn statement_effect(&self,
346344
sets: &mut BlockSets<MovePathIndex>,
347-
bb: mir::BasicBlock,
348-
idx: usize)
345+
location: Location)
349346
{
350347
drop_flag_effects_for_location(
351348
self.tcx, self.mir, self.mdpe,
352-
Location { block: bb, statement_index: idx },
349+
location,
353350
|path, s| Self::update_bits(sets, path, s)
354351
)
355352
}
356353

357354
fn terminator_effect(&self,
358355
sets: &mut BlockSets<MovePathIndex>,
359-
bb: mir::BasicBlock,
360-
statements_len: usize)
356+
location: Location)
361357
{
362358
drop_flag_effects_for_location(
363359
self.tcx, self.mir, self.mdpe,
364-
Location { block: bb, statement_index: statements_len },
360+
location,
365361
|path, s| Self::update_bits(sets, path, s)
366362
)
367363
}
@@ -400,24 +396,22 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
400396

401397
fn statement_effect(&self,
402398
sets: &mut BlockSets<MovePathIndex>,
403-
bb: mir::BasicBlock,
404-
idx: usize)
399+
location: Location)
405400
{
406401
drop_flag_effects_for_location(
407402
self.tcx, self.mir, self.mdpe,
408-
Location { block: bb, statement_index: idx },
403+
location,
409404
|path, s| Self::update_bits(sets, path, s)
410405
)
411406
}
412407

413408
fn terminator_effect(&self,
414409
sets: &mut BlockSets<MovePathIndex>,
415-
bb: mir::BasicBlock,
416-
statements_len: usize)
410+
location: Location)
417411
{
418412
drop_flag_effects_for_location(
419413
self.tcx, self.mir, self.mdpe,
420-
Location { block: bb, statement_index: statements_len },
414+
location,
421415
|path, s| Self::update_bits(sets, path, s)
422416
)
423417
}
@@ -448,18 +442,16 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
448442
}
449443
fn statement_effect(&self,
450444
sets: &mut BlockSets<MoveOutIndex>,
451-
bb: mir::BasicBlock,
452-
idx: usize) {
445+
location: Location) {
453446
let (tcx, mir, move_data) = (self.tcx, self.mir, self.move_data());
454-
let stmt = &mir[bb].statements[idx];
447+
let stmt = &mir[location.block].statements[location.statement_index];
455448
let loc_map = &move_data.loc_map;
456449
let path_map = &move_data.path_map;
457450
let rev_lookup = &move_data.rev_lookup;
458451

459-
let loc = Location { block: bb, statement_index: idx };
460452
debug!("stmt {:?} at loc {:?} moves out of move_indexes {:?}",
461-
stmt, loc, &loc_map[loc]);
462-
for move_index in &loc_map[loc] {
453+
stmt, location, &loc_map[location]);
454+
for move_index in &loc_map[location] {
463455
// Every path deinitialized by a *particular move*
464456
// has corresponding bit, "gen'ed" (i.e. set)
465457
// here, in dataflow vector
@@ -506,17 +498,15 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
506498

507499
fn terminator_effect(&self,
508500
sets: &mut BlockSets<MoveOutIndex>,
509-
bb: mir::BasicBlock,
510-
statements_len: usize)
501+
location: Location)
511502
{
512503
let (mir, move_data) = (self.mir, self.move_data());
513-
let term = mir[bb].terminator();
504+
let term = mir[location.block].terminator();
514505
let loc_map = &move_data.loc_map;
515-
let loc = Location { block: bb, statement_index: statements_len };
516506
debug!("terminator {:?} at loc {:?} moves out of move_indexes {:?}",
517-
term, loc, &loc_map[loc]);
507+
term, location, &loc_map[location]);
518508
let bits_per_block = self.bits_per_block();
519-
for move_index in &loc_map[loc] {
509+
for move_index in &loc_map[location] {
520510
assert!(move_index.index() < bits_per_block);
521511
zero_to_one(sets.gen_set.words_mut(), *move_index);
522512
}

src/librustc_mir/dataflow/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::indexed_vec::Idx;
1515
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator};
1616

1717
use rustc::ty::{TyCtxt};
18-
use rustc::mir::{self, Mir};
18+
use rustc::mir::{self, Mir, Location};
1919

2020
use std::fmt::Debug;
2121
use std::io;
@@ -98,12 +98,13 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
9898

9999
let sets = &mut self.flow_state.sets.for_block(bb.index());
100100
for j_stmt in 0..statements.len() {
101-
self.flow_state.operator.statement_effect(sets, bb, j_stmt);
101+
let location = Location { block: bb, statement_index: j_stmt };
102+
self.flow_state.operator.statement_effect(sets, location);
102103
}
103104

104105
if terminator.is_some() {
105-
let stmts_len = statements.len();
106-
self.flow_state.operator.terminator_effect(sets, bb, stmts_len);
106+
let location = Location { block: bb, statement_index: statements.len() };
107+
self.flow_state.operator.terminator_effect(sets, location);
107108
}
108109
}
109110
}
@@ -341,8 +342,7 @@ pub trait BitDenotation {
341342
/// the MIR.
342343
fn statement_effect(&self,
343344
sets: &mut BlockSets<Self::Idx>,
344-
bb: mir::BasicBlock,
345-
idx_stmt: usize);
345+
location: Location);
346346

347347
/// Mutates the block-sets (the flow sets for the given
348348
/// basic block) according to the effects of evaluating
@@ -356,8 +356,7 @@ pub trait BitDenotation {
356356
/// terminator took.
357357
fn terminator_effect(&self,
358358
sets: &mut BlockSets<Self::Idx>,
359-
bb: mir::BasicBlock,
360-
idx_term: usize);
359+
location: Location);
361360

362361
/// Mutates the block-sets according to the (flow-dependent)
363362
/// effect of a successful return from a Call terminator.

src/librustc_mir/transform/rustc_peek.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use syntax::ast;
1313
use syntax_pos::Span;
1414

1515
use rustc::ty::{self, TyCtxt};
16-
use rustc::mir::{self, Mir};
16+
use rustc::mir::{self, Mir, Location};
1717
use rustc::mir::transform::{MirPass, MirSource};
1818
use rustc_data_structures::indexed_set::IdxSetBuf;
1919
use rustc_data_structures::indexed_vec::Idx;
@@ -202,7 +202,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
202202
// reset GEN and KILL sets before emulating their effect.
203203
for e in sets.gen_set.words_mut() { *e = 0; }
204204
for e in sets.kill_set.words_mut() { *e = 0; }
205-
results.0.operator.statement_effect(&mut sets, bb, j);
205+
results.0.operator.statement_effect(&mut sets, Location { block: bb, statement_index: j });
206206
sets.on_entry.union(sets.gen_set);
207207
sets.on_entry.subtract(sets.kill_set);
208208
}

0 commit comments

Comments
 (0)