Skip to content

Commit 9928d0e

Browse files
committed
Remove OnlyPropagateInto.
1 parent 24dbf9c commit 9928d0e

File tree

3 files changed

+13
-34
lines changed

3 files changed

+13
-34
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,6 @@ pub enum ConstPropMode {
718718
FullConstProp,
719719
/// The `Local` can only be propagated into and from its own block.
720720
OnlyInsideOwnBlock,
721-
/// The `Local` can be propagated into but reads cannot be propagated.
722-
OnlyPropagateInto,
723721
/// The `Local` cannot be part of propagation at all. Any statement
724722
/// referencing it either for reading or writing will not get propagated.
725723
NoPropagation,
@@ -729,8 +727,6 @@ pub struct CanConstProp {
729727
can_const_prop: IndexVec<Local, ConstPropMode>,
730728
// False at the beginning. Once set, no more assignments are allowed to that local.
731729
found_assignment: BitSet<Local>,
732-
// Cache of locals' information
733-
local_kinds: IndexVec<Local, LocalKind>,
734730
}
735731

736732
impl CanConstProp {
@@ -743,10 +739,6 @@ impl CanConstProp {
743739
let mut cpv = CanConstProp {
744740
can_const_prop: IndexVec::from_elem(ConstPropMode::FullConstProp, &body.local_decls),
745741
found_assignment: BitSet::new_empty(body.local_decls.len()),
746-
local_kinds: IndexVec::from_fn_n(
747-
|local| body.local_kind(local),
748-
body.local_decls.len(),
749-
),
750742
};
751743
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
752744
let ty = body.local_decls[local].ty;
@@ -759,24 +751,10 @@ impl CanConstProp {
759751
continue;
760752
}
761753
}
762-
// Cannot use args at all
763-
// Cannot use locals because if x < y { y - x } else { x - y } would
764-
// lint for x != y
765-
// FIXME(oli-obk): lint variables until they are used in a condition
766-
// FIXME(oli-obk): lint if return value is constant
767-
if cpv.local_kinds[local] == LocalKind::Arg {
768-
*val = ConstPropMode::OnlyPropagateInto;
769-
trace!(
770-
"local {:?} can't be const propagated because it's a function argument",
771-
local
772-
);
773-
} else if cpv.local_kinds[local] == LocalKind::Var {
774-
*val = ConstPropMode::OnlyInsideOwnBlock;
775-
trace!(
776-
"local {:?} will only be propagated inside its block, because it's a user variable",
777-
local
778-
);
779-
}
754+
}
755+
// Consider that arguments are assigned on entry.
756+
for arg in body.args_iter() {
757+
cpv.found_assignment.insert(arg);
780758
}
781759
cpv.visit_body(&body);
782760
cpv.can_const_prop
@@ -806,7 +784,6 @@ impl Visitor<'_> for CanConstProp {
806784
// states as applicable.
807785
ConstPropMode::OnlyInsideOwnBlock => {}
808786
ConstPropMode::NoPropagation => {}
809-
ConstPropMode::OnlyPropagateInto => {}
810787
other @ ConstPropMode::FullConstProp => {
811788
trace!(
812789
"local {:?} can't be propagated because of multiple assignments. Previous state: {:?}",
@@ -897,7 +874,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
897874
place.local
898875
);
899876
}
900-
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
877+
ConstPropMode::NoPropagation => {
901878
trace!("can't propagate into {:?}", place);
902879
if place.local != RETURN_PLACE {
903880
Self::remove_const(&mut self.ecx, place.local);
@@ -933,7 +910,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
933910
Self::remove_const(&mut self.ecx, place.local);
934911
}
935912
}
936-
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
913+
ConstPropMode::NoPropagation => {
937914
Self::remove_const(&mut self.ecx, place.local);
938915
}
939916
}

compiler/rustc_mir_transform/src/const_prop_lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
530530
place.local
531531
);
532532
}
533-
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
533+
ConstPropMode::NoPropagation => {
534534
trace!("can't propagate into {:?}", place);
535535
if place.local != RETURN_PLACE {
536536
Self::remove_const(&mut self.ecx, place.local);
@@ -567,7 +567,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
567567
Self::remove_const(&mut self.ecx, place.local);
568568
}
569569
}
570-
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
570+
ConstPropMode::NoPropagation => {
571571
Self::remove_const(&mut self.ecx, place.local);
572572
}
573573
}

tests/mir-opt/const_prop/bad_op_mod_by_zero.main.ConstProp.diff

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@
2727
}
2828

2929
bb1: {
30-
_5 = Eq(_1, const -1_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
30+
- _5 = Eq(_1, const -1_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3131
- _6 = Eq(const 1_i32, const i32::MIN); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3232
- _7 = BitAnd(move _5, move _6); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3333
- assert(!move _7, "attempt to compute the remainder of `{} % {}`, which would overflow", const 1_i32, _1) -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
34+
+ _5 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3435
+ _6 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3536
+ _7 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
36-
+ assert(!const false, "attempt to compute the remainder of `{} % {}`, which would overflow", const 1_i32, _1) -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
37+
+ assert(!const false, "attempt to compute the remainder of `{} % {}`, which would overflow", const 1_i32, const 0_i32) -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
3738
}
3839

3940
bb2: {
40-
_2 = Rem(const 1_i32, _1); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
41+
- _2 = Rem(const 1_i32, _1); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
42+
+ _2 = Rem(const 1_i32, const 0_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+2:14: +2:19
4143
StorageDead(_2); // scope 1 at $DIR/bad_op_mod_by_zero.rs:+3:1: +3:2
4244
return; // scope 0 at $DIR/bad_op_mod_by_zero.rs:+3:2: +3:2
4345
}

0 commit comments

Comments
 (0)