8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ //! For the NLL computation, we need to compute liveness, but only for those
12
+ //! local variables whose types contain regions. The others are not of interest
13
+ //! to us. This file defines a new index type (LocalWithRegion) that indexes into
14
+ //! a list of "variables whose type contain regions". It also defines a map from
15
+ //! Local to LocalWithRegion and vice versa -- this map can be given to the
16
+ //! liveness code so that it only operates over variables with regions in their
17
+ //! types, instead of all variables.
18
+
19
+ use rustc:: ty:: TypeFoldable ;
11
20
use rustc_data_structures:: indexed_vec:: IndexVec ;
12
21
use rustc:: mir:: { Mir , Local } ;
13
22
use util:: liveness:: LiveVariableMap ;
23
+
14
24
use rustc_data_structures:: indexed_vec:: Idx ;
15
- use rustc:: ty:: TypeFoldable ;
16
25
26
+ /// Map between Local and LocalWithRegion indices: this map is supplied to the
27
+ /// liveness code so that it will only analyze those variables whose types
28
+ /// contain regions.
17
29
crate struct NllLivenessMap {
30
+ /// For each local variable, contains either None (if the type has no regions)
31
+ /// or Some(i) with a suitable index.
18
32
pub from_local : IndexVec < Local , Option < LocalWithRegion > > ,
33
+ /// For each LocalWithRegion, maps back to the original Local index.
19
34
pub to_local : IndexVec < LocalWithRegion , Local > ,
20
35
21
36
}
22
37
23
38
impl LiveVariableMap for NllLivenessMap {
24
- type LiveVar = LocalWithRegion ;
25
39
26
40
fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > {
27
41
self . from_local [ local]
28
42
}
29
43
44
+ type LiveVar = LocalWithRegion ;
45
+
30
46
fn from_live_var ( & self , local : Self :: LiveVar ) -> Local {
31
47
self . to_local [ local]
32
48
}
@@ -37,6 +53,8 @@ impl LiveVariableMap for NllLivenessMap {
37
53
}
38
54
39
55
impl NllLivenessMap {
56
+ /// Iterates over the variables in Mir and assigns each Local whose type contains
57
+ /// regions a LocalWithRegion index. Returns a map for converting back and forth.
40
58
pub fn compute ( mir : & Mir ) -> Self {
41
59
let mut to_local = IndexVec :: default ( ) ;
42
60
let from_local: IndexVec < Local , Option < _ > > = mir
@@ -55,4 +73,5 @@ impl NllLivenessMap {
55
73
}
56
74
}
57
75
76
+ /// Index given to each local variable whose type contains a region.
58
77
newtype_index ! ( LocalWithRegion ) ;
0 commit comments