Skip to content

Commit cbdb186

Browse files
committed
Add some comments
1 parent eea290d commit cbdb186

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/librustc_mir/util/liveness.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Liveness analysis.
12-
13-
// FIXME: Make sure this analysis uses proper MIR semantics. Also find out what
14-
// the MIR semantics are.
11+
//! Liveness analysis which computes liveness of MIR local variables at the boundary of basic blocks
1512
1613
use rustc::mir::*;
1714
use rustc::mir::visit::{LvalueContext, Visitor};
@@ -47,15 +44,31 @@ impl<'tcx> Visitor<'tcx> for BlockInfoVisitor {
4744
if let Lvalue::Local(local) = *lvalue {
4845
match context {
4946
LvalueContext::Store |
47+
48+
// We let Call defined the result in both the success and unwind cases.
49+
// This may not be right.
5050
LvalueContext::Call |
51+
52+
// Storage live and storage dead aren't proper defines, but we can ignore
53+
// values that come before them.
5154
LvalueContext::StorageLive |
5255
LvalueContext::StorageDead => {
5356
self.defs.add(&local);
5457
}
5558
LvalueContext::Projection(..) |
59+
60+
// Borrows only consider their local used at the point of the borrow.
61+
// This won't affect the results since we use this analysis for generators
62+
// and we only care about the result at suspension points. Borrows cannot
63+
// cross suspension points so this behavoir is unproblematic.
5664
LvalueContext::Borrow { .. } |
65+
5766
LvalueContext::Inspect |
5867
LvalueContext::Consume |
68+
69+
// We consider drops to always be uses of locals.
70+
// Drop eloboration should be run before this analysis otherwise
71+
// the results might be too pessimistic.
5972
LvalueContext::Drop => {
6073
// Ignore uses which are already defined in this block
6174
if !self.pre_defs.contains(&local) {
@@ -90,6 +103,7 @@ fn block<'tcx>(b: &BasicBlockData<'tcx>, locals: usize) -> BlockInfo {
90103
}
91104
}
92105

106+
// This gives the result of the liveness analysis at the boundary of basic blocks
93107
pub struct LivenessResult {
94108
pub ins: IndexVec<BasicBlock, LocalSet>,
95109
pub outs: IndexVec<BasicBlock, LocalSet>,

0 commit comments

Comments
 (0)