diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness.rs index e70c87e8401c..972e92de77e5 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness.rs @@ -22,7 +22,7 @@ use rustc::ty::{Ty, TypeFoldable}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::Idx; use std::rc::Rc; -use util::liveness::LivenessResults; +use util::liveness::{LivenessResults, LiveVariableMap}; use super::TypeChecker; @@ -34,10 +34,10 @@ use super::TypeChecker; /// /// NB. This computation requires normalization; therefore, it must be /// performed before -pub(super) fn generate<'gcx, 'tcx>( +pub(super) fn generate<'gcx, 'tcx, V: LiveVariableMap>( cx: &mut TypeChecker<'_, 'gcx, 'tcx>, mir: &Mir<'tcx>, - liveness: &LivenessResults, + liveness: &LivenessResults, flow_inits: &mut FlowAtLocation>, move_data: &MoveData<'tcx>, ) { @@ -55,16 +55,17 @@ pub(super) fn generate<'gcx, 'tcx>( } } -struct TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx> +struct TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx, V: LiveVariableMap> where 'typeck: 'gen, 'flow: 'gen, 'tcx: 'typeck + 'flow, 'gcx: 'tcx, + V: 'gen, { cx: &'gen mut TypeChecker<'typeck, 'gcx, 'tcx>, mir: &'gen Mir<'tcx>, - liveness: &'gen LivenessResults, + liveness: &'gen LivenessResults, flow_inits: &'gen mut FlowAtLocation>, move_data: &'gen MoveData<'tcx>, drop_data: FxHashMap, DropData<'tcx>>, @@ -75,7 +76,7 @@ struct DropData<'tcx> { region_constraint_data: Option>>>, } -impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx> { +impl<'gen, 'typeck, 'flow, 'gcx, 'tcx, V:LiveVariableMap> TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx, V> { /// Liveness constraints: /// /// > If a variable V is live at point P, then all regions R in the type of V @@ -92,7 +93,7 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo } }); - let mut all_live_locals: Vec<(Location, Vec)> = vec![]; + let mut all_live_locals: Vec<(Location, Vec)> = vec![]; self.liveness .drop .simulate_block(self.mir, bb, |location, live_locals| { diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 811e0e559093..5bd81f332e6b 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -48,21 +48,21 @@ use rustc::ty::TyCtxt; use std::io::{self, Write}; use transform::MirSource; -pub type LocalSet = IdxSetBuf; +pub type LocalSet = IdxSetBuf; /// This gives the result of the liveness analysis at the boundary of /// basic blocks. You can use `simulate_block` to obtain the /// intra-block results. -pub struct LivenessResult { +pub struct LivenessResult { /// Liveness mode in use when these results were computed. pub mode: LivenessMode, /// Live variables on exit to each basic block. This is equal to /// the union of the `ins` for each successor. - pub outs: IndexVec>, + pub outs: IndexVec>, } -trait LiveVariableMap { +pub(crate) trait LiveVariableMap { type LiveVar; fn from_local(&self, local: Local) -> Option; @@ -103,18 +103,18 @@ pub struct LivenessMode { } /// A combination of liveness results, used in NLL. -pub struct LivenessResults { +pub struct LivenessResults { /// Liveness results where a regular use makes a variable X live, /// but not a drop. - pub regular: LivenessResult, + pub regular: LivenessResult, /// Liveness results where a drop makes a variable X live, /// but not a regular use. - pub drop: LivenessResult, + pub drop: LivenessResult, } -impl LivenessResults { - pub fn compute<'tcx>(mir: &Mir<'tcx>, map: &dyn LiveVariableMap) -> LivenessResults { +impl LivenessResults { + pub fn compute<'tcx>(mir: &Mir<'tcx>, map: &dyn LiveVariableMap) -> LivenessResults { LivenessResults { regular: liveness_of_locals( &mir, @@ -138,7 +138,7 @@ impl LivenessResults { /// Compute which local variables are live within the given function /// `mir`. The liveness mode `mode` determines what sorts of uses are /// considered to make a variable live (e.g., do drops count?). -pub fn liveness_of_locals<'tcx, V: Idx>(mir: &Mir<'tcx>, mode: LivenessMode) -> LivenessResult { +pub fn liveness_of_locals<'tcx, V: LiveVariableMap>(mir: &Mir<'tcx>, mode: LivenessMode) -> LivenessResult { let locals = mir.local_decls.len(); let def_use: IndexVec<_, _> = mir.basic_blocks() .iter() @@ -179,8 +179,7 @@ pub fn liveness_of_locals<'tcx, V: Idx>(mir: &Mir<'tcx>, mode: LivenessMode) -> LivenessResult { mode, outs } } -impl LivenessResult -where V:Idx +impl LivenessResult { /// Walks backwards through the statements/terminator in the given /// basic block `block`. At each point within `block`, invokes @@ -422,12 +421,13 @@ fn block<'tcx, 'lv>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize) visitor.defs_uses } -pub fn dump_mir<'a, 'tcx, V: Idx>( +pub fn dump_mir<'a, 'tcx, V: LiveVariableMap>( tcx: TyCtxt<'a, 'tcx, 'tcx>, pass_name: &str, source: MirSource, mir: &Mir<'tcx>, result: &LivenessResult, + map: &impl LiveVariableMap ) { if !dump_enabled(tcx, pass_name, source) { return; @@ -439,13 +439,13 @@ pub fn dump_mir<'a, 'tcx, V: Idx>( dump_matched_mir_node(tcx, pass_name, &node_path, source, mir, result); } -fn dump_matched_mir_node<'a, 'tcx, V: Idx>( +fn dump_matched_mir_node<'a, 'tcx, V: LiveVariableMap>( tcx: TyCtxt<'a, 'tcx, 'tcx>, pass_name: &str, node_path: &str, source: MirSource, mir: &Mir<'tcx>, - result: &LivenessResult, + result: &LivenessResult, ) { let mut file_path = PathBuf::new(); file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir)); @@ -462,16 +462,16 @@ fn dump_matched_mir_node<'a, 'tcx, V: Idx>( }); } -pub fn write_mir_fn<'a, 'tcx, V :Idx>( +pub fn write_mir_fn<'a, 'tcx, V: LiveVariableMap>( tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir<'tcx>, w: &mut dyn Write, - result: &LivenessResult, + result: &LivenessResult, ) -> io::Result<()> { write_mir_intro(tcx, src, mir, w)?; for block in mir.basic_blocks().indices() { - let print = |w: &mut dyn Write, prefix, result: &IndexVec>| { + let print = |w: &mut dyn Write, prefix, result: &IndexVec>| { let live: Vec = mir.local_decls .indices() .filter(|i| result[block].contains(i))