Skip to content

Commit c183b4c

Browse files
committed
[ConstProp] Use a BitSet<Local> instead of IndexVec<Local, bool>
1 parent 52fa23a commit c183b4c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/librustc_mir/transform/const_prop.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::ast::Mutability;
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::HirId;
11+
use rustc_index::bit_set::BitSet;
1112
use rustc_index::vec::IndexVec;
1213
use rustc_middle::mir::interpret::{InterpResult, Scalar};
1314
use rustc_middle::mir::visit::{
@@ -754,15 +755,15 @@ enum ConstPropMode {
754755
struct CanConstProp {
755756
can_const_prop: IndexVec<Local, ConstPropMode>,
756757
// 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>,
758759
}
759760

760761
impl CanConstProp {
761762
/// returns true if `local` can be propagated
762763
fn check(body: ReadOnlyBodyAndCache<'_, '_>) -> IndexVec<Local, ConstPropMode> {
763764
let mut cpv = CanConstProp {
764765
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()),
766767
};
767768
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
768769
// cannot use args at all
@@ -790,11 +791,9 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
790791
// FIXME(oli-obk): we could be more powerful here, if the multiple writes
791792
// only occur in independent execution paths
792793
MutatingUse(MutatingUseContext::Store) => {
793-
if self.found_assignment[local] {
794+
if !self.found_assignment.insert(local) {
794795
trace!("local {:?} can't be propagated because of multiple assignments", local);
795796
self.can_const_prop[local] = ConstPropMode::NoPropagation;
796-
} else {
797-
self.found_assignment[local] = true
798797
}
799798
}
800799
// Reading constants is allowed an arbitrary number of times

0 commit comments

Comments
 (0)