@@ -219,21 +219,12 @@ rustc_index::newtype_index! {
219
219
/// index and a def index.
220
220
///
221
221
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
222
- #[ derive( Clone , PartialEq , Eq , Copy ) ]
223
- // On below-64 bit systems we can simply use the derived `Hash` impl
224
- #[ cfg_attr( not( target_pointer_width = "64" ) , derive( Hash ) ) ]
222
+ #[ derive( Clone , PartialEq , Eq , Copy , Hash ) ]
225
223
#[ repr( C ) ]
226
224
#[ rustc_pass_by_value]
227
- // We guarantee field order. Note that the order is essential here, see below why.
228
225
pub struct DefId {
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
231
- // into a direct call to `u64::hash(_)`.
232
- #[ cfg( not( all( target_pointer_width = "64" , target_endian = "big" ) ) ) ]
233
226
pub index : DefIndex ,
234
227
pub krate : CrateNum ,
235
- #[ cfg( all( target_pointer_width = "64" , target_endian = "big" ) ) ]
236
- pub index : DefIndex ,
237
228
}
238
229
239
230
// To ensure correctness of incremental compilation,
@@ -242,31 +233,6 @@ pub struct DefId {
242
233
impl !Ord for DefId { }
243
234
impl !PartialOrd for DefId { }
244
235
245
- // On 64-bit systems, we can hash the whole `DefId` as one `u64` instead of two `u32`s. This
246
- // improves performance without impairing `FxHash` quality. So the below code gets compiled to a
247
- // noop on little endian systems because the memory layout of `DefId` is as follows:
248
- //
249
- // ```
250
- // +-1--------------31-+-32-------------63-+
251
- // ! index ! krate !
252
- // +-------------------+-------------------+
253
- // ```
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.
263
- #[ cfg( target_pointer_width = "64" ) ]
264
- impl Hash for DefId {
265
- fn hash < H : Hasher > ( & self , h : & mut H ) {
266
- ( ( ( self . krate . as_u32 ( ) as u64 ) << 32 ) | ( self . index . as_u32 ( ) as u64 ) ) . hash ( h)
267
- }
268
- }
269
-
270
236
impl DefId {
271
237
/// Makes a local `DefId` from the given `DefIndex`.
272
238
#[ inline]
0 commit comments