Skip to content

Commit

Permalink
migrate clippy to the DenseBitSet name
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Jan 7, 2025
1 parent fd502f5 commit ba411dd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{Body, Expr, ExprKind, Mutability, Path, QPath};
use rustc_index::bit_set::BitSet;
use rustc_index::bit_set::DenseBitSet;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::{Rvalue, StatementKind};
Expand Down Expand Up @@ -390,7 +390,7 @@ fn replace_types<'tcx>(
projection_predicates: &[ProjectionPredicate<'tcx>],
args: &mut [GenericArg<'tcx>],
) -> bool {
let mut replaced = BitSet::new_empty(args.len());
let mut replaced = DenseBitSet::new_empty(args.len());

let mut deque = VecDeque::with_capacity(args.len());
deque.push_back((param_ty, new_ty));
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hir::{Expr, HirId};
use rustc_index::bit_set::BitSet;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{
BasicBlock, Body, InlineAsmOperand, Local, Location, Place, START_BLOCK, StatementKind, TerminatorKind, traversal,
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<'tcx> Visitor<'tcx> for V<'_> {

/// Checks if the block is part of a cycle
pub fn block_in_cycle(body: &Body<'_>, block: BasicBlock) -> bool {
let mut seen = BitSet::new_empty(body.basic_blocks.len());
let mut seen = DenseBitSet::new_empty(body.basic_blocks.len());
let mut to_visit = Vec::with_capacity(body.basic_blocks.len() / 2);

seen.insert(block);
Expand Down
18 changes: 9 additions & 9 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;
use rustc_index::bit_set::DenseBitSet;
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, BitSet<mir::Local>>,
possible_origin: FxHashMap<mir::Local, DenseBitSet<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, BitSet<mir::Local>>,
possible_origin: FxHashMap<mir::Local, DenseBitSet<mir::Local>>,
) -> Self {
Self {
possible_borrower: TransitiveRelation::default(),
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<'a, 'b, 'tcx> PossibleBorrowerVisitor<'a, 'b, 'tcx> {
}
}

let bs = BitSet::new_empty(self.body.local_decls.len());
let bs = DenseBitSet::new_empty(self.body.local_decls.len());
PossibleBorrowerMap {
map,
maybe_live,
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(BitSet::iter)
.flat_map(DenseBitSet::iter)
.collect();

if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() {
Expand Down Expand Up @@ -171,10 +171,10 @@ 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, BitSet<mir::Local>>,
pub map: FxHashMap<mir::Local, DenseBitSet<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>),
// Caches to avoid allocation of `DenseBitSet` on every query
pub bitset: (DenseBitSet<mir::Local>, DenseBitSet<mir::Local>),
}

impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
Expand All @@ -184,7 +184,7 @@ impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
vis.visit_body(mir);
vis.into_map(cx)
};
let maybe_storage_live_result = MaybeStorageLive::new(Cow::Owned(BitSet::new_empty(mir.local_decls.len())))
let maybe_storage_live_result = MaybeStorageLive::new(Cow::Owned(DenseBitSet::new_empty(mir.local_decls.len())))
.iterate_to_fixpoint(cx.tcx, mir, Some("redundant_clone"))
.into_results_cursor(mir);
let mut vis = PossibleBorrowerVisitor::new(cx, mir, possible_origin);
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::BitSet;
use rustc_index::bit_set::DenseBitSet;
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, BitSet<mir::Local>> {
pub fn into_map(self, cx: &LateContext<'tcx>) -> FxHashMap<mir::Local, DenseBitSet<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::BitSet;
use rustc_index::bit_set::DenseBitSet;
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) -> BitSet<mir::Local> {
let mut seen = BitSet::new_empty(domain_size);
pub fn reachable_from(&self, a: mir::Local, domain_size: usize) -> DenseBitSet<mir::Local> {
let mut seen = DenseBitSet::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 ba411dd

Please sign in to comment.