@@ -48,21 +48,21 @@ use rustc::ty::TyCtxt;
48
48
use std:: io:: { self , Write } ;
49
49
use transform:: MirSource ;
50
50
51
- pub type LocalSet < V : Idx > = IdxSetBuf < V > ;
51
+ pub type LocalSet < V : LiveVariableMap > = IdxSetBuf < V :: LiveVar > ;
52
52
53
53
/// This gives the result of the liveness analysis at the boundary of
54
54
/// basic blocks. You can use `simulate_block` to obtain the
55
55
/// intra-block results.
56
- pub struct LivenessResult < V : Idx > {
56
+ pub struct LivenessResult < V : LiveVariableMap > {
57
57
/// Liveness mode in use when these results were computed.
58
58
pub mode : LivenessMode ,
59
59
60
60
/// Live variables on exit to each basic block. This is equal to
61
61
/// the union of the `ins` for each successor.
62
- pub outs : IndexVec < BasicBlock , LocalSet < V > > ,
62
+ pub outs : IndexVec < BasicBlock , LocalSet < V :: LiveVar > > ,
63
63
}
64
64
65
- trait LiveVariableMap {
65
+ pub ( crate ) trait LiveVariableMap {
66
66
type LiveVar ;
67
67
68
68
fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > ;
@@ -103,18 +103,18 @@ pub struct LivenessMode {
103
103
}
104
104
105
105
/// A combination of liveness results, used in NLL.
106
- pub struct LivenessResults < V : Idx > {
106
+ pub struct LivenessResults < V : LiveVariableMap > {
107
107
/// Liveness results where a regular use makes a variable X live,
108
108
/// but not a drop.
109
- pub regular : LivenessResult < V > ,
109
+ pub regular : LivenessResult < V :: LiveVar > ,
110
110
111
111
/// Liveness results where a drop makes a variable X live,
112
112
/// but not a regular use.
113
- pub drop : LivenessResult < V > ,
113
+ pub drop : LivenessResult < V :: LiveVar > ,
114
114
}
115
115
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 > {
118
118
LivenessResults {
119
119
regular : liveness_of_locals (
120
120
& mir,
@@ -138,7 +138,7 @@ impl<V: Idx> LivenessResults<V> {
138
138
/// Compute which local variables are live within the given function
139
139
/// `mir`. The liveness mode `mode` determines what sorts of uses are
140
140
/// 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 > {
142
142
let locals = mir. local_decls . len ( ) ;
143
143
let def_use: IndexVec < _ , _ > = mir. basic_blocks ( )
144
144
. iter ( )
@@ -179,8 +179,7 @@ pub fn liveness_of_locals<'tcx, V: Idx>(mir: &Mir<'tcx>, mode: LivenessMode) ->
179
179
LivenessResult { mode, outs }
180
180
}
181
181
182
- impl < V > LivenessResult < V >
183
- where V : Idx
182
+ impl < V : LiveVariableMap > LivenessResult < V >
184
183
{
185
184
/// Walks backwards through the statements/terminator in the given
186
185
/// basic block `block`. At each point within `block`, invokes
@@ -422,12 +421,13 @@ fn block<'tcx, 'lv>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize)
422
421
visitor. defs_uses
423
422
}
424
423
425
- pub fn dump_mir < ' a , ' tcx , V : Idx > (
424
+ pub fn dump_mir < ' a , ' tcx , V : LiveVariableMap > (
426
425
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
427
426
pass_name : & str ,
428
427
source : MirSource ,
429
428
mir : & Mir < ' tcx > ,
430
429
result : & LivenessResult < Local > ,
430
+ map : & impl LiveVariableMap < LiveVar = V >
431
431
) {
432
432
if !dump_enabled ( tcx, pass_name, source) {
433
433
return ;
@@ -439,13 +439,13 @@ pub fn dump_mir<'a, 'tcx, V: Idx>(
439
439
dump_matched_mir_node ( tcx, pass_name, & node_path, source, mir, result) ;
440
440
}
441
441
442
- fn dump_matched_mir_node < ' a , ' tcx , V : Idx > (
442
+ fn dump_matched_mir_node < ' a , ' tcx , V : LiveVariableMap > (
443
443
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
444
444
pass_name : & str ,
445
445
node_path : & str ,
446
446
source : MirSource ,
447
447
mir : & Mir < ' tcx > ,
448
- result : & LivenessResult < V > ,
448
+ result : & LivenessResult < V :: LiveVar > ,
449
449
) {
450
450
let mut file_path = PathBuf :: new ( ) ;
451
451
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>(
462
462
} ) ;
463
463
}
464
464
465
- pub fn write_mir_fn < ' a , ' tcx , V : Idx > (
465
+ pub fn write_mir_fn < ' a , ' tcx , V : LiveVariableMap > (
466
466
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
467
467
src : MirSource ,
468
468
mir : & Mir < ' tcx > ,
469
469
w : & mut dyn Write ,
470
- result : & LivenessResult < V > ,
470
+ result : & LivenessResult < V :: LiveVar > ,
471
471
) -> io:: Result < ( ) > {
472
472
write_mir_intro ( tcx, src, mir, w) ?;
473
473
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 > > | {
475
475
let live: Vec < String > = mir. local_decls
476
476
. indices ( )
477
477
. filter ( |i| result[ block] . contains ( i) )
0 commit comments