Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jul 28, 2017
1 parent eea290d commit cbdb186
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Liveness analysis.
// FIXME: Make sure this analysis uses proper MIR semantics. Also find out what
// the MIR semantics are.
//! Liveness analysis which computes liveness of MIR local variables at the boundary of basic blocks
use rustc::mir::*;
use rustc::mir::visit::{LvalueContext, Visitor};
Expand Down Expand Up @@ -47,15 +44,31 @@ impl<'tcx> Visitor<'tcx> for BlockInfoVisitor {
if let Lvalue::Local(local) = *lvalue {
match context {
LvalueContext::Store |

// We let Call defined the result in both the success and unwind cases.
// This may not be right.
LvalueContext::Call |

// Storage live and storage dead aren't proper defines, but we can ignore
// values that come before them.
LvalueContext::StorageLive |
LvalueContext::StorageDead => {
self.defs.add(&local);
}
LvalueContext::Projection(..) |

// Borrows only consider their local used at the point of the borrow.
// This won't affect the results since we use this analysis for generators
// and we only care about the result at suspension points. Borrows cannot
// cross suspension points so this behavoir is unproblematic.
LvalueContext::Borrow { .. } |

LvalueContext::Inspect |
LvalueContext::Consume |

// We consider drops to always be uses of locals.
// Drop eloboration should be run before this analysis otherwise
// the results might be too pessimistic.
LvalueContext::Drop => {
// Ignore uses which are already defined in this block
if !self.pre_defs.contains(&local) {
Expand Down Expand Up @@ -90,6 +103,7 @@ fn block<'tcx>(b: &BasicBlockData<'tcx>, locals: usize) -> BlockInfo {
}
}

// This gives the result of the liveness analysis at the boundary of basic blocks
pub struct LivenessResult {
pub ins: IndexVec<BasicBlock, LocalSet>,
pub outs: IndexVec<BasicBlock, LocalSet>,
Expand Down

0 comments on commit cbdb186

Please sign in to comment.