Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustc_mir: use Local instead of Lvalue in Storage{Live,Dead}.
  • Loading branch information
eddyb committed Sep 4, 2017
1 parent 2f42cd8 commit e74f96e
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 54 deletions.
14 changes: 7 additions & 7 deletions src/librustc/mir/mod.rs
Expand Up @@ -901,10 +901,10 @@ pub enum StatementKind<'tcx> {
SetDiscriminant { lvalue: Lvalue<'tcx>, variant_index: usize },

/// Start a live range for the storage of the local.
StorageLive(Lvalue<'tcx>),
StorageLive(Local),

/// End the current live range for the storage of the local.
StorageDead(Lvalue<'tcx>),
StorageDead(Local),

/// Execute a piece of inline Assembly.
InlineAsm {
Expand Down Expand Up @@ -1701,8 +1701,8 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
lvalue: lvalue.fold_with(folder),
variant_index,
},
StorageLive(ref lval) => StorageLive(lval.fold_with(folder)),
StorageDead(ref lval) => StorageDead(lval.fold_with(folder)),
StorageLive(ref local) => StorageLive(local.fold_with(folder)),
StorageDead(ref local) => StorageDead(local.fold_with(folder)),
InlineAsm { ref asm, ref outputs, ref inputs } => InlineAsm {
asm: asm.clone(),
outputs: outputs.fold_with(folder),
Expand Down Expand Up @@ -1732,9 +1732,9 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {

match self.kind {
Assign(ref lval, ref rval) => { lval.visit_with(visitor) || rval.visit_with(visitor) }
SetDiscriminant { ref lvalue, .. } |
StorageLive(ref lvalue) |
StorageDead(ref lvalue) => lvalue.visit_with(visitor),
SetDiscriminant { ref lvalue, .. } => lvalue.visit_with(visitor),
StorageLive(ref local) |
StorageDead(ref local) => local.visit_with(visitor),
InlineAsm { ref outputs, ref inputs, .. } =>
outputs.visit_with(visitor) || inputs.visit_with(visitor),

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/mir/visit.rs
Expand Up @@ -360,11 +360,11 @@ macro_rules! make_mir_visitor {
StatementKind::SetDiscriminant{ ref $($mutability)* lvalue, .. } => {
self.visit_lvalue(lvalue, LvalueContext::Store, location);
}
StatementKind::StorageLive(ref $($mutability)* lvalue) => {
self.visit_lvalue(lvalue, LvalueContext::StorageLive, location);
StatementKind::StorageLive(ref $($mutability)* local) => {
self.visit_local(local, LvalueContext::StorageLive, location);
}
StatementKind::StorageDead(ref $($mutability)* lvalue) => {
self.visit_lvalue(lvalue, LvalueContext::StorageDead, location);
StatementKind::StorageDead(ref $($mutability)* local) => {
self.visit_local(local, LvalueContext::StorageDead, location);
}
StatementKind::InlineAsm { ref $($mutability)* outputs,
ref $($mutability)* inputs,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check.rs
Expand Up @@ -212,11 +212,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> DataflowResultsConsumer<'b, 'gcx>
// ignored by borrowck
}

StatementKind::StorageDead(ref lvalue) => {
StatementKind::StorageDead(local) => {
// causes non-drop values to be dropped.
self.consume_lvalue(ContextKind::StorageDead.new(location),
ConsumeKind::Consume,
(lvalue, span),
(&Lvalue::Local(local), span),
flow_state)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/build/expr/as_rvalue.rs
Expand Up @@ -96,23 +96,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
}
ExprKind::Box { value } => {
let value = this.hir.mirror(value);
let result = this.temp(expr.ty, expr_span);
let result = this.local_decls.push(LocalDecl::new_temp(expr.ty, expr_span));
this.cfg.push(block, Statement {
source_info,
kind: StatementKind::StorageLive(result.clone())
kind: StatementKind::StorageLive(result)
});
if let Some(scope) = scope {
// schedule a shallow free of that memory, lest we unwind:
this.schedule_drop(expr_span, scope, &result, value.ty);
this.schedule_drop(expr_span, scope, &Lvalue::Local(result), value.ty);
}

// malloc some memory of suitable type (thus far, uninitialized):
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
this.cfg.push_assign(block, source_info, &result, box_);
this.cfg.push_assign(block, source_info, &Lvalue::Local(result), box_);

// initialize the box contents:
unpack!(block = this.into(&result.clone().deref(), block, value));
block.and(Rvalue::Use(Operand::Consume(result)))
unpack!(block = this.into(&Lvalue::Local(result).deref(), block, value));
block.and(Rvalue::Use(Operand::Consume(Lvalue::Local(result))))
}
ExprKind::Cast { source } => {
let source = this.hir.mirror(source);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_temp.rs
Expand Up @@ -53,7 +53,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
if !expr_ty.is_never() {
this.cfg.push(block, Statement {
source_info,
kind: StatementKind::StorageLive(Lvalue::Local(temp))
kind: StatementKind::StorageLive(temp)
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/mod.rs
Expand Up @@ -194,7 +194,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let source_info = self.source_info(span);
self.cfg.push(block, Statement {
source_info,
kind: StatementKind::StorageLive(Lvalue::Local(local_id))
kind: StatementKind::StorageLive(local_id)
});
Lvalue::Local(local_id)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/scope.rs
Expand Up @@ -822,7 +822,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
Lvalue::Local(index) if index.index() > arg_count => {
cfg.push(block, Statement {
source_info,
kind: StatementKind::StorageDead(drop_data.location.clone())
kind: StatementKind::StorageDead(index)
});
}
_ => continue
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_mir/transform/generator.rs
Expand Up @@ -213,12 +213,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
// Remove StorageLive and StorageDead statements for remapped locals
data.retain_statements(|s| {
match s.kind {
StatementKind::StorageLive(ref l) | StatementKind::StorageDead(ref l) => {
if let Lvalue::Local(l) = *l {
!self.remap.contains_key(&l)
} else {
true
}
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
!self.remap.contains_key(&l)
}
_ => true
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/promote_consts.rs
Expand Up @@ -406,8 +406,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
block.statements.retain(|statement| {
match statement.kind {
StatementKind::Assign(Lvalue::Local(index), _) |
StatementKind::StorageLive(Lvalue::Local(index)) |
StatementKind::StorageDead(Lvalue::Local(index)) => {
StatementKind::StorageLive(index) |
StatementKind::StorageDead(index) => {
!promoted(index)
}
_ => true
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -1108,7 +1108,7 @@ impl MirPass for QualifyAndPromoteConstants {
for block in mir.basic_blocks_mut() {
block.statements.retain(|statement| {
match statement.kind {
StatementKind::StorageDead(Lvalue::Local(index)) => {
StatementKind::StorageDead(index) => {
!promoted_temps.contains(&index)
}
_ => true
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_mir/transform/simplify.rs
Expand Up @@ -369,11 +369,8 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater {
// Remove unnecessary StorageLive and StorageDead annotations.
data.statements.retain(|stmt| {
match stmt.kind {
StatementKind::StorageLive(ref lval) | StatementKind::StorageDead(ref lval) => {
match *lval {
Lvalue::Local(l) => self.map[l.index()] != !0,
_ => true
}
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
self.map[l.index()] != !0
}
_ => true
}
Expand Down
11 changes: 2 additions & 9 deletions src/librustc_mir/transform/type_check.rs
Expand Up @@ -420,15 +420,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
variant_index);
};
}
StatementKind::StorageLive(ref lv) |
StatementKind::StorageDead(ref lv) => {
match *lv {
Lvalue::Local(_) => {}
_ => {
span_mirbug!(self, stmt, "bad lvalue: expected local");
}
}
}
StatementKind::StorageLive(_) |
StatementKind::StorageDead(_) |
StatementKind::InlineAsm { .. } |
StatementKind::EndRegion(_) |
StatementKind::Validate(..) |
Expand Down
16 changes: 7 additions & 9 deletions src/librustc_trans/mir/statement.rs
Expand Up @@ -67,11 +67,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
variant_index as u64);
bcx
}
mir::StatementKind::StorageLive(ref lvalue) => {
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::Start)
mir::StatementKind::StorageLive(local) => {
self.trans_storage_liveness(bcx, local, base::Lifetime::Start)
}
mir::StatementKind::StorageDead(ref lvalue) => {
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End)
mir::StatementKind::StorageDead(local) => {
self.trans_storage_liveness(bcx, local, base::Lifetime::End)
}
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
let outputs = outputs.iter().map(|output| {
Expand All @@ -94,13 +94,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {

fn trans_storage_liveness(&self,
bcx: Builder<'a, 'tcx>,
lvalue: &mir::Lvalue<'tcx>,
index: mir::Local,
intrinsic: base::Lifetime)
-> Builder<'a, 'tcx> {
if let mir::Lvalue::Local(index) = *lvalue {
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
intrinsic.call(&bcx, tr_lval.llval);
}
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
intrinsic.call(&bcx, tr_lval.llval);
}
bcx
}
Expand Down

0 comments on commit e74f96e

Please sign in to comment.