Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HybridBitSets in possible_borrower #10144

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")))))));
}