Skip to content

Optimize SbTag::eq #2218

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

Merged
merged 3 commits into from
Jun 8, 2022
Merged
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
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
clippy::single_match,
clippy::useless_format,
clippy::derive_partial_eq_without_eq,
clippy::derive_hash_xor_eq,
clippy::too_many_arguments
)]

Expand Down
20 changes: 19 additions & 1 deletion src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@ pub type CallId = NonZeroU64;
pub type AllocExtra = Stacks;

/// Tracking pointer provenance
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Copy, Clone, Hash, Eq)]
pub enum SbTag {
Tagged(PtrId),
Untagged,
}

impl SbTag {
fn as_u64(self) -> u64 {
match self {
SbTag::Tagged(id) => id.get(),
SbTag::Untagged => 0,
}
}
}

impl PartialEq for SbTag {
fn eq(&self, other: &Self) -> bool {
// The codegen for the derived Partialeq is bad here and includes a branch.
// Since this code is extremely hot, this is optimized here.
// https://github.com/rust-lang/rust/issues/49892
self.as_u64() == other.as_u64()
}
}

impl fmt::Debug for SbTag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down