@@ -227,13 +227,13 @@ rustc_index::newtype_index! {
227227// We guarantee field order. Note that the order is essential here, see below why.
228228pub struct DefId {
229229 // cfg-ing the order of fields so that the `DefIndex` which is high entropy always ends up in
230- // the lower bits no matter the endianness. This allows the compiler to turn that `Hash` impl
230+ // the higher bits no matter the endianness. This allows the compiler to turn that `Hash` impl
231231 // into a direct call to `u64::hash(_)`.
232232 #[ cfg( not( all( target_pointer_width = "64" , target_endian = "big" ) ) ) ]
233- pub index : DefIndex ,
234- pub krate : CrateNum ,
233+ pub krate : DefIndex ,
234+ pub index : CrateNum ,
235235 #[ cfg( all( target_pointer_width = "64" , target_endian = "big" ) ) ]
236- pub index : DefIndex ,
236+ pub krate : DefIndex ,
237237}
238238
239239// To ensure correctness of incremental compilation,
@@ -248,22 +248,15 @@ impl !PartialOrd for DefId {}
248248//
249249// ```
250250// +-1--------------31-+-32-------------63-+
251- // ! index ! krate !
251+ // ! krate ! index !
252252// +-------------------+-------------------+
253253// ```
254254//
255- // The order here has direct impact on `FxHash` quality because we have far more `DefIndex` per
256- // crate than we have `Crate`s within one compilation. Or in other words, this arrangement puts
257- // more entropy in the low bits than the high bits. The reason this matters is that `FxHash`, which
258- // is used throughout rustc, has problems distributing the entropy from the high bits, so reversing
259- // the order would lead to a large number of collisions and thus far worse performance.
260- //
261- // On 64-bit big-endian systems, this compiles to a 64-bit rotation by 32 bits, which is still
262- // faster than another `FxHash` round.
255+ // On 64-bit big-endian systems, this compiles to a 64-bit rotation by 32 bits, or a 64-bit load.
263256#[ cfg( target_pointer_width = "64" ) ]
264257impl Hash for DefId {
265258 fn hash < H : Hasher > ( & self , h : & mut H ) {
266- ( ( ( self . krate . as_u32 ( ) as u64 ) << 32 ) | ( self . index . as_u32 ( ) as u64 ) ) . hash ( h)
259+ ( ( ( self . index . as_u32 ( ) as u64 ) << 32 ) | ( self . krate . as_u32 ( ) as u64 ) ) . hash ( h)
267260 }
268261}
269262
0 commit comments