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

Manually order DefId on 64-bit big-endian #102382

Merged
merged 1 commit into from
Sep 30, 2022
Merged
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
20 changes: 19 additions & 1 deletion compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ impl<D: Decoder> Decodable<D> for DefIndex {
/// index and a def index.
///
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
#[derive(Clone, PartialEq, Eq, Copy)]
// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
// On below-64 bit systems we can simply use the derived `Hash` impl
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
#[repr(C)]
Expand Down Expand Up @@ -260,6 +262,22 @@ impl Hash for DefId {
}
}

// Implement the same comparison as derived with the other field order.
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
impl Ord for DefId {
#[inline]
fn cmp(&self, other: &DefId) -> std::cmp::Ordering {
Ord::cmp(&(self.index, self.krate), &(other.index, other.krate))
}
}
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
impl PartialOrd for DefId {
#[inline]
fn partial_cmp(&self, other: &DefId) -> Option<std::cmp::Ordering> {
Some(Ord::cmp(self, other))
}
}

impl DefId {
/// Makes a local `DefId` from the given `DefIndex`.
#[inline]
Expand Down