@@ -48,21 +48,21 @@ use rustc::ty::TyCtxt;
4848use std:: io:: { self , Write } ;
4949use transform:: MirSource ;
5050
51- pub type LocalSet < V : Idx > = IdxSetBuf < V > ;
51+ pub type LocalSet < V : LiveVariableMap > = IdxSetBuf < V :: LiveVar > ;
5252
5353/// This gives the result of the liveness analysis at the boundary of
5454/// basic blocks. You can use `simulate_block` to obtain the
5555/// intra-block results.
56- pub struct LivenessResult < V : Idx > {
56+ pub struct LivenessResult < V : LiveVariableMap > {
5757 /// Liveness mode in use when these results were computed.
5858 pub mode : LivenessMode ,
5959
6060 /// Live variables on exit to each basic block. This is equal to
6161 /// the union of the `ins` for each successor.
62- pub outs : IndexVec < BasicBlock , LocalSet < V > > ,
62+ pub outs : IndexVec < BasicBlock , LocalSet < V :: LiveVar > > ,
6363}
6464
65- trait LiveVariableMap {
65+ pub ( crate ) trait LiveVariableMap {
6666 type LiveVar ;
6767
6868 fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > ;
@@ -103,18 +103,18 @@ pub struct LivenessMode {
103103}
104104
105105/// A combination of liveness results, used in NLL.
106- pub struct LivenessResults < V : Idx > {
106+ pub struct LivenessResults < V : LiveVariableMap > {
107107 /// Liveness results where a regular use makes a variable X live,
108108 /// but not a drop.
109- pub regular : LivenessResult < V > ,
109+ pub regular : LivenessResult < V :: LiveVar > ,
110110
111111 /// Liveness results where a drop makes a variable X live,
112112 /// but not a regular use.
113- pub drop : LivenessResult < V > ,
113+ pub drop : LivenessResult < V :: LiveVar > ,
114114}
115115
116- impl < V : Idx > LivenessResults < V > {
117- pub fn compute < ' tcx > ( mir : & Mir < ' tcx > , map : & dyn LiveVariableMap < LiveVar = V > ) -> LivenessResults < V > {
116+ impl < V : LiveVariableMap > LivenessResults < V > {
117+ pub fn compute < ' tcx > ( mir : & Mir < ' tcx > , map : & dyn LiveVariableMap < LiveVar = V > ) -> LivenessResults < V :: LiveVar > {
118118 LivenessResults {
119119 regular : liveness_of_locals (
120120 & mir,
@@ -138,7 +138,7 @@ impl<V: Idx> LivenessResults<V> {
138138/// Compute which local variables are live within the given function
139139/// `mir`. The liveness mode `mode` determines what sorts of uses are
140140/// considered to make a variable live (e.g., do drops count?).
141- pub fn liveness_of_locals < ' tcx , V : Idx > ( mir : & Mir < ' tcx > , mode : LivenessMode ) -> LivenessResult < V > {
141+ pub fn liveness_of_locals < ' tcx , V : LiveVariableMap > ( mir : & Mir < ' tcx > , mode : LivenessMode ) -> LivenessResult < V :: LiveVar > {
142142 let locals = mir. local_decls . len ( ) ;
143143 let def_use: IndexVec < _ , _ > = mir. basic_blocks ( )
144144 . iter ( )
@@ -179,8 +179,7 @@ pub fn liveness_of_locals<'tcx, V: Idx>(mir: &Mir<'tcx>, mode: LivenessMode) ->
179179 LivenessResult { mode, outs }
180180}
181181
182- impl < V > LivenessResult < V >
183- where V : Idx
182+ impl < V : LiveVariableMap > LivenessResult < V >
184183{
185184 /// Walks backwards through the statements/terminator in the given
186185 /// basic block `block`. At each point within `block`, invokes
@@ -422,12 +421,13 @@ fn block<'tcx, 'lv>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize)
422421 visitor. defs_uses
423422}
424423
425- pub fn dump_mir < ' a , ' tcx , V : Idx > (
424+ pub fn dump_mir < ' a , ' tcx , V : LiveVariableMap > (
426425 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
427426 pass_name : & str ,
428427 source : MirSource ,
429428 mir : & Mir < ' tcx > ,
430429 result : & LivenessResult < Local > ,
430+ map : & impl LiveVariableMap < LiveVar = V >
431431) {
432432 if !dump_enabled ( tcx, pass_name, source) {
433433 return ;
@@ -439,13 +439,13 @@ pub fn dump_mir<'a, 'tcx, V: Idx>(
439439 dump_matched_mir_node ( tcx, pass_name, & node_path, source, mir, result) ;
440440}
441441
442- fn dump_matched_mir_node < ' a , ' tcx , V : Idx > (
442+ fn dump_matched_mir_node < ' a , ' tcx , V : LiveVariableMap > (
443443 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
444444 pass_name : & str ,
445445 node_path : & str ,
446446 source : MirSource ,
447447 mir : & Mir < ' tcx > ,
448- result : & LivenessResult < V > ,
448+ result : & LivenessResult < V :: LiveVar > ,
449449) {
450450 let mut file_path = PathBuf :: new ( ) ;
451451 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>(
462462 } ) ;
463463}
464464
465- pub fn write_mir_fn < ' a , ' tcx , V : Idx > (
465+ pub fn write_mir_fn < ' a , ' tcx , V : LiveVariableMap > (
466466 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
467467 src : MirSource ,
468468 mir : & Mir < ' tcx > ,
469469 w : & mut dyn Write ,
470- result : & LivenessResult < V > ,
470+ result : & LivenessResult < V :: LiveVar > ,
471471) -> io:: Result < ( ) > {
472472 write_mir_intro ( tcx, src, mir, w) ?;
473473 for block in mir. basic_blocks ( ) . indices ( ) {
474- let print = |w : & mut dyn Write , prefix, result : & IndexVec < BasicBlock , LocalSet < V > > | {
474+ let print = |w : & mut dyn Write , prefix, result : & IndexVec < BasicBlock , LocalSet < Local > > | {
475475 let live: Vec < String > = mir. local_decls
476476 . indices ( )
477477 . filter ( |i| result[ block] . contains ( i) )
0 commit comments