Skip to content

Commit 8af87b1

Browse files
committed
Auto merge of #71312 - wesleywiser:const_prop_bitset, r=Mark-Simulacrum
[ConstProp] Use a `BitSet<Local>` instead of `IndexVec<Local, bool>`
2 parents fc145e1 + c183b4c commit 8af87b1

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::{
@@ -775,15 +776,15 @@ enum ConstPropMode {
775776
struct CanConstProp {
776777
can_const_prop: IndexVec<Local, ConstPropMode>,
777778
// false at the beginning, once set, there are not allowed to be any more assignments
778-
found_assignment: IndexVec<Local, bool>,
779+
found_assignment: BitSet<Local>,
779780
}
780781

781782
impl CanConstProp {
782783
/// returns true if `local` can be propagated
783784
fn check(body: &Body<'_>) -> IndexVec<Local, ConstPropMode> {
784785
let mut cpv = CanConstProp {
785786
can_const_prop: IndexVec::from_elem(ConstPropMode::FullConstProp, &body.local_decls),
786-
found_assignment: IndexVec::from_elem(false, &body.local_decls),
787+
found_assignment: BitSet::new_empty(body.local_decls.len()),
787788
};
788789
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
789790
// cannot use args at all
@@ -811,11 +812,9 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
811812
// FIXME(oli-obk): we could be more powerful here, if the multiple writes
812813
// only occur in independent execution paths
813814
MutatingUse(MutatingUseContext::Store) => {
814-
if self.found_assignment[local] {
815+
if !self.found_assignment.insert(local) {
815816
trace!("local {:?} can't be propagated because of multiple assignments", local);
816817
self.can_const_prop[local] = ConstPropMode::NoPropagation;
817-
} else {
818-
self.found_assignment[local] = true
819818
}
820819
}
821820
// Reading constants is allowed an arbitrary number of times

0 commit comments

Comments
 (0)