Skip to content

Commit

Permalink
Use HybridBitSets in possible_borrower
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jan 2, 2023
1 parent a85e480 commit 6d033a9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
42 changes: 38 additions & 4 deletions clippy_utils/src/mir/possible_borrower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,46 @@ struct PossibleBorrowerAnalysis<'b, 'tcx> {
possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug)]
struct PossibleBorrowerState {
map: FxIndexMap<Local, BitSet<Local>>,
map: FxIndexMap<Local, HybridBitSet<Local>>,
domain_size: usize,
}

// `PossibleBorrowerState`'s `PartialEq` implementation doesn't seem to be used currently.
impl PartialEq for PossibleBorrowerState {
fn eq(&self, other: &Self) -> bool {
if self.domain_size != other.domain_size {
return false;
}
for (borrowed, our_borrowers) in self.map.iter() {
if !other
.map
.get(borrowed)
.map_or(our_borrowers.is_empty(), |their_borrowers| {
our_borrowers.iter().eq(their_borrowers.iter())
})
{
return false;
}
}
for (borrowed, their_borrowers) in other.map.iter() {
if !self
.map
.get(borrowed)
.map_or(their_borrowers.is_empty(), |our_borrowers| {
their_borrowers.iter().eq(our_borrowers.iter())
})
{
return false;
}
}
true
}
}

impl Eq for PossibleBorrowerState {}

impl PossibleBorrowerState {
fn new(domain_size: usize) -> Self {
Self {
Expand All @@ -42,7 +76,7 @@ impl PossibleBorrowerState {
fn add(&mut self, borrowed: Local, borrower: Local) {
self.map
.entry(borrowed)
.or_insert(BitSet::new_empty(self.domain_size))
.or_insert_with(|| HybridBitSet::new_empty(self.domain_size))
.insert(borrower);
}
}
Expand All @@ -64,7 +98,7 @@ impl JoinSemiLattice for PossibleBorrowerState {
changed |= self
.map
.entry(borrowed)
.or_insert(BitSet::new_empty(self.domain_size))
.or_insert_with(|| HybridBitSet::new_empty(self.domain_size))
.union(borrowers);
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/possible_borrower.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn meow(_s: impl AsRef<str>) {}

macro_rules! quad {
($x:stmt) => {
$x
$x
$x
$x
};
}

fn main() {
let i = 0;
quad!(quad!(quad!(quad!(quad!(meow(format!("abc{i}")))))));
}

0 comments on commit 6d033a9

Please sign in to comment.