diff options
| author | bors <bors@rust-lang.org> | 2022-01-11 08:09:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-01-11 08:09:00 +0000 |
| commit | e4b1d5841494d6eb7f4944c91a057e16b0f0a9ea (patch) | |
| tree | aa63bc52d66a7d20dda32903704d328bd96fbd63 /compiler/rustc_span | |
| parent | 1f213d983ddf44df10eb52627d3c24213d102e39 (diff) | |
| parent | 7f7b5514a424a49c16a2c2b2833f3f959c2b077c (diff) | |
| download | rust-e4b1d5841494d6eb7f4944c91a057e16b0f0a9ea.tar.gz rust-e4b1d5841494d6eb7f4944c91a057e16b0f0a9ea.zip | |
Auto merge of #92012 - llogiq:repr-c-def-id, r=michaelwoerister
Make `DefId` `repr(C)`, optimize big-endian field order r? `@michaelwoerister`
Diffstat (limited to 'compiler/rustc_span')
| -rw-r--r-- | compiler/rustc_span/src/def_id.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 24d2a8ac073..0bba918994c 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -221,10 +221,17 @@ impl<D: Decoder> Decodable<D> for DefIndex { #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)] // On below-64 bit systems we can simply use the derived `Hash` impl #[cfg_attr(not(target_pointer_width = "64"), derive(Hash))] -// Note that the order is essential here, see below why +#[repr(C)] +// We guarantee field order. Note that the order is essential here, see below why. pub struct DefId { + // cfg-ing the order of fields so that the `DefIndex` which is high entropy always ends up in + // the lower bits no matter the endianness. This allows the compiler to turn that `Hash` impl + // into a direct call to 'u64::hash(_)`. + #[cfg(not(all(target_pointer_width = "64", target_endian = "big")))] pub index: DefIndex, pub krate: CrateNum, + #[cfg(all(target_pointer_width = "64", target_endian = "big"))] + pub index: DefIndex, } // On 64-bit systems, we can hash the whole `DefId` as one `u64` instead of two `u32`s. This |
