Skip to content

Commit a4c0d36

Browse files
committed
add docs
1 parent 7db3324 commit a4c0d36

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/librustc_mir/borrow_check/nll/liveness_map.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,41 @@
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;
1120
use rustc_data_structures::indexed_vec::IndexVec;
1221
use rustc::mir::{Mir, Local};
1322
use util::liveness::LiveVariableMap;
23+
1424
use 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.
1729
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.
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

2338
impl 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

3955
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.
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.
5877
newtype_index!(LocalWithRegion);

0 commit comments

Comments
 (0)