Skip to content

Commit 1b3e945

Browse files
committed
Rebase fallout
1 parent 61871d4 commit 1b3e945

File tree

10 files changed

+85
-81
lines changed

10 files changed

+85
-81
lines changed

src/librustc/mir/tcx.rs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a, 'gcx, 'tcx> LvalueTy<'tcx> {
8383
variant_index: index }
8484
}
8585
_ => {
86-
bug!("cannot downcast non-enum type: `{:?}` as `{:?}`", self, elem)
86+
bug!("cannot downcast non-enum type: `{:?}`", self)
8787
}
8888
},
8989
ProjectionElem::Field(_, fty) => LvalueTy::Ty { ty: fty }
@@ -113,26 +113,16 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
113113
}
114114
}
115115

116-
impl<'a, 'gcx, 'tcx> Mir<'tcx> {
117-
pub fn operand_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
118-
operand: &Operand<'tcx>)
119-
-> Ty<'tcx>
120-
{
121-
match *operand {
122-
Operand::Consume(ref l) => self.lvalue_ty(tcx, l).to_ty(tcx),
123-
Operand::Constant(ref c) => c.ty,
124-
}
125-
}
126-
127-
pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, lvalue: &Lvalue<'tcx>) -> LvalueTy<'tcx> {
128-
match *lvalue {
129-
Lvalue::Var(index) =>
130-
LvalueTy::Ty { ty: self.var_decls[index].ty },
131-
Lvalue::Temp(index) =>
132-
LvalueTy::Ty { ty: self.temp_decls[index].ty },
133-
Lvalue::Arg(index) =>
134-
LvalueTy::Ty { ty: self.arg_decls[index].ty },
135-
Lvalue::Static(def_id) =>
116+
impl<'tcx> Lvalue<'tcx> {
117+
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> {
118+
match self {
119+
&Lvalue::Var(index) =>
120+
LvalueTy::Ty { ty: mir.var_decls[index].ty },
121+
&Lvalue::Temp(index) =>
122+
LvalueTy::Ty { ty: mir.temp_decls[index].ty },
123+
&Lvalue::Arg(index) =>
124+
LvalueTy::Ty { ty: mir.arg_decls[index].ty },
125+
&Lvalue::Static(def_id) =>
136126
LvalueTy::Ty { ty: tcx.lookup_item_type(def_id).ty },
137127
&Lvalue::ReturnPointer =>
138128
LvalueTy::Ty { ty: mir.return_ty },
@@ -163,17 +153,17 @@ impl<'tcx> Rvalue<'tcx> {
163153
}
164154
))
165155
}
166-
Rvalue::Len(..) => Some(tcx.types.usize),
167-
Rvalue::Cast(_, _, ty) => Some(ty),
168-
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
169-
let lhs_ty = self.operand_ty(tcx, lhs);
170-
let rhs_ty = self.operand_ty(tcx, rhs);
171-
Some(binop_ty(tcx, op, lhs_ty, rhs_ty))
156+
&Rvalue::Len(..) => Some(tcx.types.usize),
157+
&Rvalue::Cast(_, _, ty) => Some(ty),
158+
&Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
159+
let lhs_ty = lhs.ty(mir, tcx);
160+
let rhs_ty = rhs.ty(mir, tcx);
161+
Some(op.ty(tcx, lhs_ty, rhs_ty))
172162
}
173-
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
174-
let lhs_ty = self.operand_ty(tcx, lhs);
175-
let rhs_ty = self.operand_ty(tcx, rhs);
176-
let ty = binop_ty(tcx, op, lhs_ty, rhs_ty);
163+
&Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
164+
let lhs_ty = lhs.ty(mir, tcx);
165+
let rhs_ty = rhs.ty(mir, tcx);
166+
let ty = op.ty(tcx, lhs_ty, rhs_ty);
177167
let ty = tcx.mk_tup(vec![ty, tcx.types.bool]);
178168
Some(ty)
179169
}

src/librustc_borrowck/borrowck/mir/gather_moves.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,14 @@ fn gather_moves<'a, 'tcx>(mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> MoveD
614614
Rvalue::InlineAsm { .. } => {}
615615
}
616616
}
617+
StatementKind::SetDiscriminant{ ref lvalue, .. } => {
618+
// not a move, is assignment like.
619+
bb_ctxt.builder.create_move_path(lvalue);
620+
let assigned_path = bb_ctxt.builder.move_path_for(lvalue);
621+
bb_ctxt.path_map.fill_to(assigned_path.index());
622+
}
617623
StatementKind::StorageLive(_) |
618624
StatementKind::StorageDead(_) => {}
619-
StatementKind::SetDiscriminant{ .. } => {
620-
span_bug!(stmt.source_info.span,
621-
"SetDiscriminant should not exist during borrowck");
622-
}
623625
}
624626
}
625627

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ fn drop_flag_effects_for_location<'a, 'tcx, F>(
369369
let block = &mir[loc.block];
370370
match block.statements.get(loc.index) {
371371
Some(stmt) => match stmt.kind {
372-
repr::StatementKind::SetDiscriminant{ .. } => {
373-
span_bug!(stmt.source_info.span, "SetDiscrimant should not exist during borrowck");
374-
}
372+
repr::StatementKind::SetDiscriminant{ ref lvalue, .. } |
375373
repr::StatementKind::Assign(ref lvalue, _) => {
376374
debug!("drop_flag_effects: assignment {:?}", stmt);
377375
on_all_children_bits(tcx, mir, move_data,

src/librustc_data_structures/bitvec.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ impl BitVector {
2323
BitVector { data: vec![0; num_words] }
2424
}
2525

26-
pub fn clear(&mut self) {
27-
for p in &mut self.data {
28-
*p = 0;
29-
}
30-
}
31-
3226
pub fn contains(&self, bit: usize) -> bool {
3327
let (word, mask) = word_mask(bit);
3428
(self.data.get(word).cloned().unwrap_or(0) & mask) != 0
@@ -419,6 +413,7 @@ fn matrix_iter() {
419413
assert!(iter.next().is_none());
420414
}
421415

416+
#[test]
422417
fn bitvec_pop() {
423418
let mut bitvec = BitVector::new(100);
424419
bitvec.insert(1);
@@ -430,7 +425,7 @@ fn bitvec_pop() {
430425
bitvec.insert(65);
431426
bitvec.insert(66);
432427
bitvec.insert(99);
433-
let idxs = vec![];
428+
let mut idxs = vec![];
434429
while let Some(idx) = bitvec.pop() { idxs.push(idx); }
435430
assert_eq!(idxs, [99, 66, 65, 64, 63, 62, 19, 10, 1]);
436431
}

src/librustc_mir/transform/const_propagate.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_data_structures::fnv::FnvHashMap;
3434
use rustc::middle::const_val::ConstVal;
3535
use rustc::hir::def_id::DefId;
3636
use rustc::mir::repr::*;
37-
use rustc::mir::tcx::binop_ty;
3837
use rustc::mir::transform::{Pass, MirPass, MirSource};
3938
use rustc::mir::visit::{MutVisitor};
4039
use rustc::ty::TyCtxt;
@@ -159,7 +158,17 @@ impl<'a, 'tcx> Transfer<'tcx> for ConstTransfer<'a, 'tcx> {
159158
fn stmt(&self, s: &Statement<'tcx>, mut lat: Self::Lattice)
160159
-> Self::Lattice
161160
{
162-
let StatementKind::Assign(ref lval, ref rval) = s.kind;
161+
let (lval, rval) = match s.kind {
162+
// Could be handled with some extra information, but there’s no point in doing that yet
163+
// because currently we would have no consumers of this data (no GetDiscriminant).
164+
StatementKind::SetDiscriminant { .. } => return lat,
165+
StatementKind::StorageDead(ref lval) => {
166+
lat.top(lval);
167+
return lat;
168+
}
169+
StatementKind::StorageLive(_) => return lat,
170+
StatementKind::Assign(ref lval, ref rval) => (lval, rval),
171+
};
163172
match *rval {
164173
Rvalue::Use(Operand::Consume(_)) => {
165174
lat.top(lval);
@@ -329,7 +338,11 @@ struct ConstEvalVisitor<'a, 'tcx: 'a>(TyCtxt<'a, 'tcx, 'tcx>);
329338
impl<'a, 'tcx> MutVisitor<'tcx> for ConstEvalVisitor<'a, 'tcx> {
330339
fn visit_statement(&mut self, _: BasicBlock, stmt: &mut Statement<'tcx>) {
331340
let span = stmt.source_info.span;
332-
let StatementKind::Assign(_, ref mut rval) = stmt.kind;
341+
let rval = if let StatementKind::Assign(_, ref mut rval) = stmt.kind {
342+
rval
343+
} else {
344+
return
345+
};
333346
let repl = match *rval {
334347
// FIXME: Rvalue::CheckedBinaryOp could be evaluated to Rvalue::Aggregate of 2-tuple
335348
// (or disaggregated version of it; needs replacement with arbitrary graphs)
@@ -338,7 +351,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ConstEvalVisitor<'a, 'tcx> {
338351
(&Literal::Value { value: ref value1 },
339352
&Literal::Value { value: ref value2 }) =>
340353
eval_const_binop(op.to_hir_binop(), &value1, &value2, span).ok().map(|v| {
341-
(v, binop_ty(self.0, *op, opr1.ty, opr2.ty))
354+
(v, op.ty(self.0, opr1.ty, opr2.ty))
342355
}),
343356
_ => None
344357
}

src/librustc_mir/transform/deadcode.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ impl DeadCodeLattice {
8181
_ => false
8282
};
8383
}
84+
85+
fn is_live<'a>(&self, lval: &Lvalue<'a>) -> bool {
86+
match *lval {
87+
Lvalue::Temp(t) => self.tmps.contains(t.index()),
88+
Lvalue::Var(v) => self.vars.contains(v.index()),
89+
Lvalue::Arg(a) => self.args.contains(a.index()),
90+
// All other stuff is *always* live.
91+
_ => true
92+
}
93+
}
8494
}
8595

8696
struct DeadCodeTransfer;
@@ -108,12 +118,11 @@ where T: Transfer<'tcx, Lattice=DeadCodeLattice>
108118
fn stmt(&self, s: &Statement<'tcx>, lat: &DeadCodeLattice)
109119
-> StatementChange<'tcx>
110120
{
111-
let StatementKind::Assign(ref lval, ref rval) = s.kind;
112-
let keep = !rval.is_pure() || match *lval {
113-
Lvalue::Temp(t) => lat.tmps.contains(t.index()),
114-
Lvalue::Var(v) => lat.vars.contains(v.index()),
115-
Lvalue::Arg(a) => lat.args.contains(a.index()),
116-
_ => true
121+
let keep = match s.kind {
122+
StatementKind::Assign(ref lval, ref rval) => !rval.is_pure() || lat.is_live(lval),
123+
StatementKind::SetDiscriminant { ref lvalue, .. } => lat.is_live(lvalue),
124+
StatementKind::StorageLive(_) => true,
125+
StatementKind::StorageDead(_) => true,
117126
};
118127
if keep {
119128
StatementChange::Statement(s.clone())
@@ -141,6 +150,11 @@ impl<'tcx> Visitor<'tcx> for DeadCodeVisitor {
141150
ref l@Lvalue::Arg(_) => self.0.set_lvalue_dead(l),
142151
_ => {}
143152
}
153+
} else if ctx == LvalueContext::StorageLive || ctx == LvalueContext::StorageDead {
154+
// Do not consider StorageDead as use of value, because that way we gonna never apply
155+
// any optimisation in this pass. StorageLive behaves in a similar way as an assignment
156+
// by having the value dead above the statement.
157+
self.0.set_lvalue_dead(lval);
144158
} else {
145159
self.0.set_lvalue_live(lval);
146160
}

src/librustc_trans/mir/analyze.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ struct DeclMarker {
317317

318318
impl<'tcx> Visitor<'tcx> for DeclMarker {
319319
fn visit_lvalue(&mut self, lval: &mir::Lvalue<'tcx>, ctx: LvalueContext) {
320+
if ctx == LvalueContext::StorageLive || ctx == LvalueContext::StorageDead {
321+
return; // ignore these altogether.
322+
}
320323
match *lval {
321324
mir::Lvalue::Var(ref v) => self.live_vars.insert(v.index()),
322325
mir::Lvalue::Temp(ref t) => self.live_temps.insert(t.index()),

src/librustc_trans/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_const_math::ConstMathErr;
1717
use rustc::hir::def_id::DefId;
1818
use rustc::infer::TransNormalize;
1919
use rustc::mir::repr as mir;
20-
use rustc::mir::tcx::{LvalueTy, binop_ty};
20+
use rustc::mir::tcx::LvalueTy;
2121
use rustc::traits;
2222
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
2323
use rustc::ty::cast::{CastTy, IntTy};

src/librustc_trans/mir/rvalue.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use llvm::{self, ValueRef};
1212
use rustc::ty::{self, Ty};
1313
use rustc::ty::cast::{CastTy, IntTy};
1414
use rustc::mir::repr as mir;
15-
use rustc::mir::tcx::binop_ty;
1615

1716
use asm;
1817
use base;

src/test/mir-opt/storage_ranges.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@ fn main() {
2020

2121
// END RUST SOURCE
2222
// START rustc.node4.PreTrans.after.mir
23-
// bb0: {
24-
// StorageLive(var0); // scope 0 at storage_ranges.rs:12:9: 12:10
25-
// var0 = const 0i32; // scope 0 at storage_ranges.rs:12:13: 12:14
26-
// StorageLive(var1); // scope 1 at storage_ranges.rs:14:13: 14:14
27-
// StorageLive(tmp1); // scope 1 at storage_ranges.rs:14:18: 14:25
28-
// StorageLive(tmp2); // scope 1 at storage_ranges.rs:14:23: 14:24
29-
// tmp2 = var0; // scope 1 at storage_ranges.rs:14:23: 14:24
30-
// tmp1 = std::option::Option<i32>::Some(tmp2,); // scope 1 at storage_ranges.rs:14:18: 14:25
31-
// var1 = &tmp1; // scope 1 at storage_ranges.rs:14:17: 14:25
32-
// StorageDead(tmp2); // scope 1 at storage_ranges.rs:14:23: 14:24
33-
// tmp0 = (); // scope 2 at storage_ranges.rs:13:5: 15:6
34-
// StorageDead(tmp1); // scope 1 at storage_ranges.rs:14:18: 14:25
35-
// StorageDead(var1); // scope 1 at storage_ranges.rs:14:13: 14:14
36-
// StorageLive(var2); // scope 1 at storage_ranges.rs:16:9: 16:10
37-
// var2 = const 1i32; // scope 1 at storage_ranges.rs:16:13: 16:14
38-
// return = (); // scope 3 at storage_ranges.rs:11:11: 17:2
39-
// StorageDead(var2); // scope 1 at storage_ranges.rs:16:9: 16:10
40-
// StorageDead(var0); // scope 0 at storage_ranges.rs:12:9: 12:10
41-
// goto -> bb1; // scope 0 at storage_ranges.rs:11:1: 17:2
42-
// }
43-
//
44-
// bb1: {
45-
// return; // scope 0 at storage_ranges.rs:11:1: 17:2
46-
// }
23+
// bb0: {
24+
// StorageLive(var0);
25+
// StorageLive(var1);
26+
// StorageLive(tmp1);
27+
// StorageLive(tmp2);
28+
// StorageDead(tmp2);
29+
// StorageDead(tmp1);
30+
// StorageDead(var1);
31+
// StorageLive(var2);
32+
// return = ();
33+
// StorageDead(var2);
34+
// StorageDead(var0);
35+
// goto -> bb1;
36+
// }
4737
// END rustc.node4.PreTrans.after.mir

0 commit comments

Comments
 (0)