rustc_mir: use Local instead of Lvalue in Storage{Live,Dead}.
This commit is contained in:
parent
2f42cd8489
commit
e74f96e43f
13 changed files with 38 additions and 54 deletions
|
@ -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 {
|
||||
|
@ -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),
|
||||
|
@ -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),
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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(..) |
|
||||
|
|
|
@ -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| {
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue