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

Reduce alignment of TypeId to u64 alignment #121358

Merged
merged 3 commits into from
Mar 9, 2024
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
11 changes: 8 additions & 3 deletions library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ impl dyn Any + Send + Sync {
#[derive(Clone, Copy, Debug, Eq, PartialOrd, Ord)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct TypeId {
t: u128,
// We avoid using `u128` because that imposes higher alignment requirements on many platforms.
// See issue #115620 for more information.
t: (u64, u64),
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -637,7 +639,10 @@ impl TypeId {
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
pub const fn of<T: ?Sized + 'static>() -> TypeId {
let t: u128 = intrinsics::type_id::<T>();
TypeId { t }

let t1 = (t >> 64) as u64;
let t2 = t as u64;
TypeId { t: (t1, t2) }
}
}

Expand All @@ -657,7 +662,7 @@ impl hash::Hash for TypeId {
// - It is correct to do so -- only hashing a subset of `self` is still
// with an `Eq` implementation that considers the entire value, as
// ours does.
(self.t as u64).hash(state);
GnomedDev marked this conversation as resolved.
Show resolved Hide resolved
self.t.1.hash(state);
}
}

Expand Down
Loading