Skip to content

Commit

Permalink
Evaluate hair::ExprKind::Use in into
Browse files Browse the repository at this point in the history
This avoids some unnecessary moves
  • Loading branch information
matthewjasper committed Apr 24, 2019
1 parent ff4d4b2 commit e9c687b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
}
ExprKind::Use { source } => {
let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Use(source))
}
ExprKind::Pointer { cast, source } => {
let source = unpack!(block = this.as_operand(block, scope, source));
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
Expand Down Expand Up @@ -363,6 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
| ExprKind::Match { .. }
| ExprKind::If { .. }
| ExprKind::NeverToAny { .. }
| ExprKind::Use { .. }
| ExprKind::Loop { .. }
| ExprKind::LogicalOp { .. }
| ExprKind::Call { .. }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl Category {
| ExprKind::If { .. }
| ExprKind::Match { .. }
| ExprKind::NeverToAny { .. }
| ExprKind::Use { .. }
| ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)),

ExprKind::Array { .. }
Expand All @@ -58,7 +59,6 @@ impl Category {
| ExprKind::Binary { .. }
| ExprKind::Box { .. }
| ExprKind::Cast { .. }
| ExprKind::Use { .. }
| ExprKind::Pointer { .. }
| ExprKind::Repeat { .. }
| ExprKind::Borrow { .. }
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
success.unit()
}
}
ExprKind::Use { source } => {
this.into(destination, block, source)
}

// These cases don't actually need a destination
ExprKind::Assign { .. }
Expand Down Expand Up @@ -379,7 +382,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
| ExprKind::Binary { .. }
| ExprKind::Box { .. }
| ExprKind::Cast { .. }
| ExprKind::Use { .. }
| ExprKind::Pointer { .. }
| ExprKind::Repeat { .. }
| ExprKind::Borrow { .. }
Expand Down
21 changes: 10 additions & 11 deletions src/test/mir-opt/array-index-is-temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@ fn main() {
// START rustc.main.EraseRegions.after.mir
// bb0: {
// ...
// _6 = &mut _2;
// _5 = &mut (*_6);
// _4 = move _5 as *mut usize (Misc);
// _3 = move _4;
// _5 = &mut _2;
// _4 = &mut (*_5);
// _3 = move _4 as *mut usize (Misc);
// ...
// _8 = _3;
// _7 = const foo(move _8) -> bb1;
// _7 = _3;
// _6 = const foo(move _7) -> bb1;
// }
//
// bb1: {
// ...
// _9 = _2;
// _10 = Len(_1);
// _11 = Lt(_9, _10);
// assert(move _11, "index out of bounds: the len is move _10 but the index is _9") -> bb2;
// _8 = _2;
// _9 = Len(_1);
// _10 = Lt(_8, _9);
// assert(move _10, "index out of bounds: the len is move _9 but the index is _8") -> bb2;
// }
//
// bb2: {
// _1[_9] = move _7;
// _1[_8] = move _6;
// ...
// return;
// }
Expand Down
14 changes: 7 additions & 7 deletions src/test/mir-opt/retag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ fn main() {
// _10 = move _8;
// Retag(_10);
// ...
// _15 = &mut (*_10);
// Retag(_15);
// _14 = move _15 as *mut i32 (Misc);
// Retag([raw] _14);
// _13 = &mut (*_10);
// Retag(_13);
// _12 = move _13 as *mut i32 (Misc);
// Retag([raw] _12);
// ...
// _18 = move _19(move _20) -> bb2;
// _16 = move _17(move _18) -> bb2;
// }
//
// bb2: {
// Retag(_18);
// Retag(_16);
// ...
// _22 = const Test::foo_shr(move _23, move _25) -> bb3;
// _20 = const Test::foo_shr(move _21, move _23) -> bb3;
// }
//
// bb3: {
Expand Down

0 comments on commit e9c687b

Please sign in to comment.