diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-07-03 17:58:19 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-08-16 15:53:27 +0200 |
| commit | cff060b960b53d6f8d869be9e3823c4920dadaee (patch) | |
| tree | f83597b7f951eed7ffefed724df19bce6ceb627d | |
| parent | 8e79fc72cb51246c397c2776fcede5401dcd3859 (diff) | |
| download | rust-cff060b960b53d6f8d869be9e3823c4920dadaee.tar.gz rust-cff060b960b53d6f8d869be9e3823c4920dadaee.zip | |
Refactor `trait BitDenotation` to take `Location` instead of `BasicBlock`/`usize` argument pairs.
| -rw-r--r-- | src/librustc_mir/dataflow/impls/mod.rs | 50 | ||||
| -rw-r--r-- | src/librustc_mir/dataflow/mod.rs | 15 | ||||
| -rw-r--r-- | src/librustc_mir/transform/rustc_peek.rs | 4 |
3 files changed, 29 insertions, 40 deletions
diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index 41019799e41..817abd8fadc 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -287,24 +287,22 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> { fn statement_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - idx: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: idx }, + location, |path, s| Self::update_bits(sets, path, s) ) } fn terminator_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - statements_len: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: statements_len }, + location, |path, s| Self::update_bits(sets, path, s) ) } @@ -344,24 +342,22 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> { fn statement_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - idx: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: idx }, + location, |path, s| Self::update_bits(sets, path, s) ) } fn terminator_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - statements_len: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: statements_len }, + location, |path, s| Self::update_bits(sets, path, s) ) } @@ -400,24 +396,22 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> { fn statement_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - idx: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: idx }, + location, |path, s| Self::update_bits(sets, path, s) ) } fn terminator_effect(&self, sets: &mut BlockSets<MovePathIndex>, - bb: mir::BasicBlock, - statements_len: usize) + location: Location) { drop_flag_effects_for_location( self.tcx, self.mir, self.mdpe, - Location { block: bb, statement_index: statements_len }, + location, |path, s| Self::update_bits(sets, path, s) ) } @@ -448,18 +442,16 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> { } fn statement_effect(&self, sets: &mut BlockSets<MoveOutIndex>, - bb: mir::BasicBlock, - idx: usize) { + location: Location) { let (tcx, mir, move_data) = (self.tcx, self.mir, self.move_data()); - let stmt = &mir[bb].statements[idx]; + let stmt = &mir[location.block].statements[location.statement_index]; let loc_map = &move_data.loc_map; let path_map = &move_data.path_map; let rev_lookup = &move_data.rev_lookup; - let loc = Location { block: bb, statement_index: idx }; debug!("stmt {:?} at loc {:?} moves out of move_indexes {:?}", - stmt, loc, &loc_map[loc]); - for move_index in &loc_map[loc] { + stmt, location, &loc_map[location]); + for move_index in &loc_map[location] { // Every path deinitialized by a *particular move* // has corresponding bit, "gen'ed" (i.e. set) // here, in dataflow vector @@ -506,17 +498,15 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> { fn terminator_effect(&self, sets: &mut BlockSets<MoveOutIndex>, - bb: mir::BasicBlock, - statements_len: usize) + location: Location) { let (mir, move_data) = (self.mir, self.move_data()); - let term = mir[bb].terminator(); + let term = mir[location.block].terminator(); let loc_map = &move_data.loc_map; - let loc = Location { block: bb, statement_index: statements_len }; debug!("terminator {:?} at loc {:?} moves out of move_indexes {:?}", - term, loc, &loc_map[loc]); + term, location, &loc_map[location]); let bits_per_block = self.bits_per_block(); - for move_index in &loc_map[loc] { + for move_index in &loc_map[location] { assert!(move_index.index() < bits_per_block); zero_to_one(sets.gen_set.words_mut(), *move_index); } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index ea855ee4d3e..731799256ab 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -15,7 +15,7 @@ use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::bitslice::{bitwise, BitwiseOperator}; use rustc::ty::{TyCtxt}; -use rustc::mir::{self, Mir}; +use rustc::mir::{self, Mir, Location}; use std::fmt::Debug; use std::io; @@ -98,12 +98,13 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> let sets = &mut self.flow_state.sets.for_block(bb.index()); for j_stmt in 0..statements.len() { - self.flow_state.operator.statement_effect(sets, bb, j_stmt); + let location = Location { block: bb, statement_index: j_stmt }; + self.flow_state.operator.statement_effect(sets, location); } if terminator.is_some() { - let stmts_len = statements.len(); - self.flow_state.operator.terminator_effect(sets, bb, stmts_len); + let location = Location { block: bb, statement_index: statements.len() }; + self.flow_state.operator.terminator_effect(sets, location); } } } @@ -341,8 +342,7 @@ pub trait BitDenotation { /// the MIR. fn statement_effect(&self, sets: &mut BlockSets<Self::Idx>, - bb: mir::BasicBlock, - idx_stmt: usize); + location: Location); /// Mutates the block-sets (the flow sets for the given /// basic block) according to the effects of evaluating @@ -356,8 +356,7 @@ pub trait BitDenotation { /// terminator took. fn terminator_effect(&self, sets: &mut BlockSets<Self::Idx>, - bb: mir::BasicBlock, - idx_term: usize); + location: Location); /// Mutates the block-sets according to the (flow-dependent) /// effect of a successful return from a Call terminator. diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 268e7a4c185..ceff52409b2 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -13,7 +13,7 @@ use syntax::ast; use syntax_pos::Span; use rustc::ty::{self, TyCtxt}; -use rustc::mir::{self, Mir}; +use rustc::mir::{self, Mir, Location}; use rustc::mir::transform::{MirPass, MirSource}; use rustc_data_structures::indexed_set::IdxSetBuf; use rustc_data_structures::indexed_vec::Idx; @@ -202,7 +202,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // reset GEN and KILL sets before emulating their effect. for e in sets.gen_set.words_mut() { *e = 0; } for e in sets.kill_set.words_mut() { *e = 0; } - results.0.operator.statement_effect(&mut sets, bb, j); + results.0.operator.statement_effect(&mut sets, Location { block: bb, statement_index: j }); sets.on_entry.union(sets.gen_set); sets.on_entry.subtract(sets.kill_set); } |
