@@ -227,13 +227,13 @@ rustc_index::newtype_index! {
227
227
// We guarantee field order. Note that the order is essential here, see below why.
228
228
pub struct DefId {
229
229
// 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
231
231
// into a direct call to `u64::hash(_)`.
232
232
#[ 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 ,
235
235
#[ cfg( all( target_pointer_width = "64" , target_endian = "big" ) ) ]
236
- pub index : DefIndex ,
236
+ pub krate : DefIndex ,
237
237
}
238
238
239
239
// To ensure correctness of incremental compilation,
@@ -248,22 +248,15 @@ impl !PartialOrd for DefId {}
248
248
//
249
249
// ```
250
250
// +-1--------------31-+-32-------------63-+
251
- // ! index ! krate !
251
+ // ! krate ! index !
252
252
// +-------------------+-------------------+
253
253
// ```
254
254
//
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.
263
256
#[ cfg( target_pointer_width = "64" ) ]
264
257
impl Hash for DefId {
265
258
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)
267
260
}
268
261
}
269
262
0 commit comments