88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
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 ;
1120use rustc_data_structures:: indexed_vec:: IndexVec ;
1221use rustc:: mir:: { Mir , Local } ;
1322use util:: liveness:: LiveVariableMap ;
23+
1424use rustc_data_structures:: indexed_vec:: Idx ;
15- use rustc:: ty:: TypeFoldable ;
1625
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.
1729crate struct NllLivenessMap {
30+ /// For each local variable, contains either None (if the type has no regions)
31+ /// or Some(i) with a suitable index.
1832 pub from_local : IndexVec < Local , Option < LocalWithRegion > > ,
33+ /// For each LocalWithRegion, maps back to the original Local index.
1934 pub to_local : IndexVec < LocalWithRegion , Local > ,
2035
2136}
2237
2338impl LiveVariableMap for NllLivenessMap {
24- type LiveVar = LocalWithRegion ;
2539
2640 fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > {
2741 self . from_local [ local]
2842 }
2943
44+ type LiveVar = LocalWithRegion ;
45+
3046 fn from_live_var ( & self , local : Self :: LiveVar ) -> Local {
3147 self . to_local [ local]
3248 }
@@ -37,6 +53,8 @@ impl LiveVariableMap for NllLivenessMap {
3753}
3854
3955impl 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.
4058 pub fn compute ( mir : & Mir ) -> Self {
4159 let mut to_local = IndexVec :: default ( ) ;
4260 let from_local: IndexVec < Local , Option < _ > > = mir
@@ -55,4 +73,5 @@ impl NllLivenessMap {
5573 }
5674}
5775
76+ /// Index given to each local variable whose type contains a region.
5877newtype_index ! ( LocalWithRegion ) ;
0 commit comments