Skip to content

Commit

Permalink
Stop using HybridBitSet in clippy.
Browse files Browse the repository at this point in the history
The compiler uses `BitSet<Local>`, because the number of locals doesn't
get that high, so clippy should do likewise.
  • Loading branch information
nnethercote committed Nov 29, 2024
1 parent 0df6a01 commit 688f28d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/tools/clippy/clippy_utils/src/mir/possible_borrower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::possible_origin::PossibleOriginVisitor;
use super::transitive_relation::TransitiveRelation;
use crate::ty::is_copy;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::bit_set::{BitSet, HybridBitSet};
use rustc_index::bit_set::BitSet;
use rustc_lint::LateContext;
use rustc_middle::mir::visit::Visitor as _;
use rustc_middle::mir::{self, Mutability};
Expand All @@ -21,14 +21,14 @@ struct PossibleBorrowerVisitor<'a, 'b, 'tcx> {
possible_borrower: TransitiveRelation,
body: &'b mir::Body<'tcx>,
cx: &'a LateContext<'tcx>,
possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
possible_origin: FxHashMap<mir::Local, BitSet<mir::Local>>,
}

impl<'a, 'b, 'tcx> PossibleBorrowerVisitor<'a, 'b, 'tcx> {
fn new(
cx: &'a LateContext<'tcx>,
body: &'b mir::Body<'tcx>,
possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
possible_origin: FxHashMap<mir::Local, BitSet<mir::Local>>,
) -> Self {
Self {
possible_borrower: TransitiveRelation::default(),
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'_, '_, 'tcx> {
let mut mutable_variables: Vec<mir::Local> = mutable_borrowers
.iter()
.filter_map(|r| self.possible_origin.get(r))
.flat_map(HybridBitSet::iter)
.flat_map(BitSet::iter)
.collect();

if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() {
Expand Down Expand Up @@ -171,7 +171,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
#[allow(clippy::module_name_repetitions)]
pub struct PossibleBorrowerMap<'b, 'tcx> {
/// Mapping `Local -> its possible borrowers`
pub map: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
pub map: FxHashMap<mir::Local, BitSet<mir::Local>>,
maybe_live: ResultsCursor<'b, 'tcx, MaybeStorageLive<'tcx>>,
// Caches to avoid allocation of `BitSet` on every query
pub bitset: (BitSet<mir::Local>, BitSet<mir::Local>),
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_utils/src/mir/possible_origin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::transitive_relation::TransitiveRelation;
use crate::ty::is_copy;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::bit_set::HybridBitSet;
use rustc_index::bit_set::BitSet;
use rustc_lint::LateContext;
use rustc_middle::mir;

Expand All @@ -22,7 +22,7 @@ impl<'a, 'tcx> PossibleOriginVisitor<'a, 'tcx> {
}
}

pub fn into_map(self, cx: &LateContext<'tcx>) -> FxHashMap<mir::Local, HybridBitSet<mir::Local>> {
pub fn into_map(self, cx: &LateContext<'tcx>) -> FxHashMap<mir::Local, BitSet<mir::Local>> {
let mut map = FxHashMap::default();
for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) {
if is_copy(cx, self.body.local_decls[row].ty) {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_utils/src/mir/transitive_relation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_index::bit_set::HybridBitSet;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir;

#[derive(Default)]
Expand All @@ -12,8 +12,8 @@ impl TransitiveRelation {
self.relations.entry(a).or_default().push(b);
}

pub fn reachable_from(&self, a: mir::Local, domain_size: usize) -> HybridBitSet<mir::Local> {
let mut seen = HybridBitSet::new_empty(domain_size);
pub fn reachable_from(&self, a: mir::Local, domain_size: usize) -> BitSet<mir::Local> {
let mut seen = BitSet::new_empty(domain_size);
let mut stack = vec![a];
while let Some(u) = stack.pop() {
if let Some(edges) = self.relations.get(&u) {
Expand Down

0 comments on commit 688f28d

Please sign in to comment.