Skip to content

Commit e74f96e

Browse files
committed
rustc_mir: use Local instead of Lvalue in Storage{Live,Dead}.
1 parent 2f42cd8 commit e74f96e

File tree

13 files changed

+38
-54
lines changed

13 files changed

+38
-54
lines changed

src/librustc/mir/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,10 @@ pub enum StatementKind<'tcx> {
901901
SetDiscriminant { lvalue: Lvalue<'tcx>, variant_index: usize },
902902

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

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

909909
/// Execute a piece of inline Assembly.
910910
InlineAsm {
@@ -1701,8 +1701,8 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
17011701
lvalue: lvalue.fold_with(folder),
17021702
variant_index,
17031703
},
1704-
StorageLive(ref lval) => StorageLive(lval.fold_with(folder)),
1705-
StorageDead(ref lval) => StorageDead(lval.fold_with(folder)),
1704+
StorageLive(ref local) => StorageLive(local.fold_with(folder)),
1705+
StorageDead(ref local) => StorageDead(local.fold_with(folder)),
17061706
InlineAsm { ref asm, ref outputs, ref inputs } => InlineAsm {
17071707
asm: asm.clone(),
17081708
outputs: outputs.fold_with(folder),
@@ -1732,9 +1732,9 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
17321732

17331733
match self.kind {
17341734
Assign(ref lval, ref rval) => { lval.visit_with(visitor) || rval.visit_with(visitor) }
1735-
SetDiscriminant { ref lvalue, .. } |
1736-
StorageLive(ref lvalue) |
1737-
StorageDead(ref lvalue) => lvalue.visit_with(visitor),
1735+
SetDiscriminant { ref lvalue, .. } => lvalue.visit_with(visitor),
1736+
StorageLive(ref local) |
1737+
StorageDead(ref local) => local.visit_with(visitor),
17381738
InlineAsm { ref outputs, ref inputs, .. } =>
17391739
outputs.visit_with(visitor) || inputs.visit_with(visitor),
17401740

src/librustc/mir/visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ macro_rules! make_mir_visitor {
360360
StatementKind::SetDiscriminant{ ref $($mutability)* lvalue, .. } => {
361361
self.visit_lvalue(lvalue, LvalueContext::Store, location);
362362
}
363-
StatementKind::StorageLive(ref $($mutability)* lvalue) => {
364-
self.visit_lvalue(lvalue, LvalueContext::StorageLive, location);
363+
StatementKind::StorageLive(ref $($mutability)* local) => {
364+
self.visit_local(local, LvalueContext::StorageLive, location);
365365
}
366-
StatementKind::StorageDead(ref $($mutability)* lvalue) => {
367-
self.visit_lvalue(lvalue, LvalueContext::StorageDead, location);
366+
StatementKind::StorageDead(ref $($mutability)* local) => {
367+
self.visit_local(local, LvalueContext::StorageDead, location);
368368
}
369369
StatementKind::InlineAsm { ref $($mutability)* outputs,
370370
ref $($mutability)* inputs,

src/librustc_mir/borrow_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> DataflowResultsConsumer<'b, 'gcx>
212212
// ignored by borrowck
213213
}
214214

215-
StatementKind::StorageDead(ref lvalue) => {
215+
StatementKind::StorageDead(local) => {
216216
// causes non-drop values to be dropped.
217217
self.consume_lvalue(ContextKind::StorageDead.new(location),
218218
ConsumeKind::Consume,
219-
(lvalue, span),
219+
(&Lvalue::Local(local), span),
220220
flow_state)
221221
}
222222
}

src/librustc_mir/build/expr/as_rvalue.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
9696
}
9797
ExprKind::Box { value } => {
9898
let value = this.hir.mirror(value);
99-
let result = this.temp(expr.ty, expr_span);
99+
let result = this.local_decls.push(LocalDecl::new_temp(expr.ty, expr_span));
100100
this.cfg.push(block, Statement {
101101
source_info,
102-
kind: StatementKind::StorageLive(result.clone())
102+
kind: StatementKind::StorageLive(result)
103103
});
104104
if let Some(scope) = scope {
105105
// schedule a shallow free of that memory, lest we unwind:
106-
this.schedule_drop(expr_span, scope, &result, value.ty);
106+
this.schedule_drop(expr_span, scope, &Lvalue::Local(result), value.ty);
107107
}
108108

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

113113
// initialize the box contents:
114-
unpack!(block = this.into(&result.clone().deref(), block, value));
115-
block.and(Rvalue::Use(Operand::Consume(result)))
114+
unpack!(block = this.into(&Lvalue::Local(result).deref(), block, value));
115+
block.and(Rvalue::Use(Operand::Consume(Lvalue::Local(result))))
116116
}
117117
ExprKind::Cast { source } => {
118118
let source = this.hir.mirror(source);

src/librustc_mir/build/expr/as_temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5353
if !expr_ty.is_never() {
5454
this.cfg.push(block, Statement {
5555
source_info,
56-
kind: StatementKind::StorageLive(Lvalue::Local(temp))
56+
kind: StatementKind::StorageLive(temp)
5757
});
5858
}
5959

src/librustc_mir/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
194194
let source_info = self.source_info(span);
195195
self.cfg.push(block, Statement {
196196
source_info,
197-
kind: StatementKind::StorageLive(Lvalue::Local(local_id))
197+
kind: StatementKind::StorageLive(local_id)
198198
});
199199
Lvalue::Local(local_id)
200200
}

src/librustc_mir/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
822822
Lvalue::Local(index) if index.index() > arg_count => {
823823
cfg.push(block, Statement {
824824
source_info,
825-
kind: StatementKind::StorageDead(drop_data.location.clone())
825+
kind: StatementKind::StorageDead(index)
826826
});
827827
}
828828
_ => continue

src/librustc_mir/transform/generator.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
213213
// Remove StorageLive and StorageDead statements for remapped locals
214214
data.retain_statements(|s| {
215215
match s.kind {
216-
StatementKind::StorageLive(ref l) | StatementKind::StorageDead(ref l) => {
217-
if let Lvalue::Local(l) = *l {
218-
!self.remap.contains_key(&l)
219-
} else {
220-
true
221-
}
216+
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
217+
!self.remap.contains_key(&l)
222218
}
223219
_ => true
224220
}

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
406406
block.statements.retain(|statement| {
407407
match statement.kind {
408408
StatementKind::Assign(Lvalue::Local(index), _) |
409-
StatementKind::StorageLive(Lvalue::Local(index)) |
410-
StatementKind::StorageDead(Lvalue::Local(index)) => {
409+
StatementKind::StorageLive(index) |
410+
StatementKind::StorageDead(index) => {
411411
!promoted(index)
412412
}
413413
_ => true

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ impl MirPass for QualifyAndPromoteConstants {
11081108
for block in mir.basic_blocks_mut() {
11091109
block.statements.retain(|statement| {
11101110
match statement.kind {
1111-
StatementKind::StorageDead(Lvalue::Local(index)) => {
1111+
StatementKind::StorageDead(index) => {
11121112
!promoted_temps.contains(&index)
11131113
}
11141114
_ => true

src/librustc_mir/transform/simplify.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,8 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater {
369369
// Remove unnecessary StorageLive and StorageDead annotations.
370370
data.statements.retain(|stmt| {
371371
match stmt.kind {
372-
StatementKind::StorageLive(ref lval) | StatementKind::StorageDead(ref lval) => {
373-
match *lval {
374-
Lvalue::Local(l) => self.map[l.index()] != !0,
375-
_ => true
376-
}
372+
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
373+
self.map[l.index()] != !0
377374
}
378375
_ => true
379376
}

src/librustc_mir/transform/type_check.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
420420
variant_index);
421421
};
422422
}
423-
StatementKind::StorageLive(ref lv) |
424-
StatementKind::StorageDead(ref lv) => {
425-
match *lv {
426-
Lvalue::Local(_) => {}
427-
_ => {
428-
span_mirbug!(self, stmt, "bad lvalue: expected local");
429-
}
430-
}
431-
}
423+
StatementKind::StorageLive(_) |
424+
StatementKind::StorageDead(_) |
432425
StatementKind::InlineAsm { .. } |
433426
StatementKind::EndRegion(_) |
434427
StatementKind::Validate(..) |

src/librustc_trans/mir/statement.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
6767
variant_index as u64);
6868
bcx
6969
}
70-
mir::StatementKind::StorageLive(ref lvalue) => {
71-
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::Start)
70+
mir::StatementKind::StorageLive(local) => {
71+
self.trans_storage_liveness(bcx, local, base::Lifetime::Start)
7272
}
73-
mir::StatementKind::StorageDead(ref lvalue) => {
74-
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End)
73+
mir::StatementKind::StorageDead(local) => {
74+
self.trans_storage_liveness(bcx, local, base::Lifetime::End)
7575
}
7676
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
7777
let outputs = outputs.iter().map(|output| {
@@ -94,13 +94,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
9494

9595
fn trans_storage_liveness(&self,
9696
bcx: Builder<'a, 'tcx>,
97-
lvalue: &mir::Lvalue<'tcx>,
97+
index: mir::Local,
9898
intrinsic: base::Lifetime)
9999
-> Builder<'a, 'tcx> {
100-
if let mir::Lvalue::Local(index) = *lvalue {
101-
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
102-
intrinsic.call(&bcx, tr_lval.llval);
103-
}
100+
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
101+
intrinsic.call(&bcx, tr_lval.llval);
104102
}
105103
bcx
106104
}

0 commit comments

Comments
 (0)