Skip to content

Commit 25e0be7

Browse files
committed
Clean up fragile checks of optimized away constants
1 parent f925a03 commit 25e0be7

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/librustc_mir/transform/simplify.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_index::bit_set::BitSet;
3232
use rustc_index::vec::{Idx, IndexVec};
3333
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
3434
use rustc_middle::mir::*;
35-
use rustc_middle::ty::{self, TyCtxt};
35+
use rustc_middle::ty::TyCtxt;
3636
use std::borrow::Cow;
3737

3838
pub struct SimplifyCfg {
@@ -400,33 +400,18 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
400400
if location.statement_index != block.statements.len() {
401401
let stmt = &block.statements[location.statement_index];
402402

403-
fn can_skip_constant(c: &ty::Const<'tcx>) -> bool {
404-
// Keep assignments from unevaluated constants around, since the
405-
// evaluation may report errors, even if the use of the constant
406-
// is dead code.
407-
!matches!(c.val, ty::ConstKind::Unevaluated(..))
408-
}
409-
410-
fn can_skip_operand(o: &Operand<'_>) -> bool {
411-
match o {
412-
Operand::Copy(_) | Operand::Move(_) => true,
413-
Operand::Constant(c) => can_skip_constant(c.literal),
414-
}
415-
}
416-
417403
if let StatementKind::Assign(box (dest, rvalue)) = &stmt.kind {
418404
if !dest.is_indirect() && dest.local == *local {
419405
let can_skip = match rvalue {
420-
Rvalue::Use(op) => can_skip_operand(op),
421-
Rvalue::Discriminant(_) => true,
422-
Rvalue::BinaryOp(_, l, r) | Rvalue::CheckedBinaryOp(_, l, r) => {
423-
can_skip_operand(l) && can_skip_operand(r)
424-
}
425-
Rvalue::Repeat(op, c) => can_skip_operand(op) && can_skip_constant(c),
426-
Rvalue::AddressOf(_, _) => true,
427-
Rvalue::Len(_) => true,
428-
Rvalue::UnaryOp(_, op) => can_skip_operand(op),
429-
Rvalue::Aggregate(_, operands) => operands.iter().all(can_skip_operand),
406+
Rvalue::Use(_)
407+
| Rvalue::Discriminant(_)
408+
| Rvalue::BinaryOp(_, _, _)
409+
| Rvalue::CheckedBinaryOp(_, _, _)
410+
| Rvalue::Repeat(_, _)
411+
| Rvalue::AddressOf(_, _)
412+
| Rvalue::Len(_)
413+
| Rvalue::UnaryOp(_, _)
414+
| Rvalue::Aggregate(_, _) => true,
430415

431416
_ => false,
432417
};

0 commit comments

Comments
 (0)