@@ -8,6 +8,7 @@ use rustc_ast::ast::Mutability;
8
8
use rustc_data_structures:: fx:: FxHashMap ;
9
9
use rustc_hir:: def:: DefKind ;
10
10
use rustc_hir:: HirId ;
11
+ use rustc_index:: bit_set:: BitSet ;
11
12
use rustc_index:: vec:: IndexVec ;
12
13
use rustc_middle:: mir:: interpret:: { InterpResult , Scalar } ;
13
14
use rustc_middle:: mir:: visit:: {
@@ -754,15 +755,15 @@ enum ConstPropMode {
754
755
struct CanConstProp {
755
756
can_const_prop : IndexVec < Local , ConstPropMode > ,
756
757
// false at the beginning, once set, there are not allowed to be any more assignments
757
- found_assignment : IndexVec < Local , bool > ,
758
+ found_assignment : BitSet < Local > ,
758
759
}
759
760
760
761
impl CanConstProp {
761
762
/// returns true if `local` can be propagated
762
763
fn check ( body : ReadOnlyBodyAndCache < ' _ , ' _ > ) -> IndexVec < Local , ConstPropMode > {
763
764
let mut cpv = CanConstProp {
764
765
can_const_prop : IndexVec :: from_elem ( ConstPropMode :: FullConstProp , & body. local_decls ) ,
765
- found_assignment : IndexVec :: from_elem ( false , & body. local_decls ) ,
766
+ found_assignment : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
766
767
} ;
767
768
for ( local, val) in cpv. can_const_prop . iter_enumerated_mut ( ) {
768
769
// cannot use args at all
@@ -790,11 +791,9 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
790
791
// FIXME(oli-obk): we could be more powerful here, if the multiple writes
791
792
// only occur in independent execution paths
792
793
MutatingUse ( MutatingUseContext :: Store ) => {
793
- if self . found_assignment [ local] {
794
+ if ! self . found_assignment . insert ( local) {
794
795
trace ! ( "local {:?} can't be propagated because of multiple assignments" , local) ;
795
796
self . can_const_prop [ local] = ConstPropMode :: NoPropagation ;
796
- } else {
797
- self . found_assignment [ local] = true
798
797
}
799
798
}
800
799
// Reading constants is allowed an arbitrary number of times
0 commit comments