@@ -718,8 +718,6 @@ pub enum ConstPropMode {
718
718
FullConstProp ,
719
719
/// The `Local` can only be propagated into and from its own block.
720
720
OnlyInsideOwnBlock ,
721
- /// The `Local` can be propagated into but reads cannot be propagated.
722
- OnlyPropagateInto ,
723
721
/// The `Local` cannot be part of propagation at all. Any statement
724
722
/// referencing it either for reading or writing will not get propagated.
725
723
NoPropagation ,
@@ -729,8 +727,6 @@ pub struct CanConstProp {
729
727
can_const_prop : IndexVec < Local , ConstPropMode > ,
730
728
// False at the beginning. Once set, no more assignments are allowed to that local.
731
729
found_assignment : BitSet < Local > ,
732
- // Cache of locals' information
733
- local_kinds : IndexVec < Local , LocalKind > ,
734
730
}
735
731
736
732
impl CanConstProp {
@@ -743,10 +739,6 @@ impl CanConstProp {
743
739
let mut cpv = CanConstProp {
744
740
can_const_prop : IndexVec :: from_elem ( ConstPropMode :: FullConstProp , & body. local_decls ) ,
745
741
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
- ) ,
750
742
} ;
751
743
for ( local, val) in cpv. can_const_prop . iter_enumerated_mut ( ) {
752
744
let ty = body. local_decls [ local] . ty ;
@@ -759,24 +751,10 @@ impl CanConstProp {
759
751
continue ;
760
752
}
761
753
}
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) ;
780
758
}
781
759
cpv. visit_body ( & body) ;
782
760
cpv. can_const_prop
@@ -806,7 +784,6 @@ impl Visitor<'_> for CanConstProp {
806
784
// states as applicable.
807
785
ConstPropMode :: OnlyInsideOwnBlock => { }
808
786
ConstPropMode :: NoPropagation => { }
809
- ConstPropMode :: OnlyPropagateInto => { }
810
787
other @ ConstPropMode :: FullConstProp => {
811
788
trace ! (
812
789
"local {:?} can't be propagated because of multiple assignments. Previous state: {:?}" ,
@@ -897,7 +874,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
897
874
place. local
898
875
) ;
899
876
}
900
- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
877
+ ConstPropMode :: NoPropagation => {
901
878
trace ! ( "can't propagate into {:?}" , place) ;
902
879
if place. local != RETURN_PLACE {
903
880
Self :: remove_const ( & mut self . ecx , place. local ) ;
@@ -933,7 +910,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
933
910
Self :: remove_const ( & mut self . ecx , place. local ) ;
934
911
}
935
912
}
936
- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
913
+ ConstPropMode :: NoPropagation => {
937
914
Self :: remove_const ( & mut self . ecx , place. local ) ;
938
915
}
939
916
}
0 commit comments