@@ -219,21 +219,12 @@ rustc_index::newtype_index! {
219219/// index and a def index.
220220///
221221/// 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 ) ]
225223#[ repr( C ) ]
226224#[ rustc_pass_by_value]
227- // We guarantee field order. Note that the order is essential here, see below why.
228225pub 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" ) ) ) ]
233226 pub index : DefIndex ,
234227 pub krate : CrateNum ,
235- #[ cfg( all( target_pointer_width = "64" , target_endian = "big" ) ) ]
236- pub index : DefIndex ,
237228}
238229
239230// To ensure correctness of incremental compilation,
@@ -242,31 +233,6 @@ pub struct DefId {
242233impl !Ord for DefId { }
243234impl !PartialOrd for DefId { }
244235
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-
270236impl DefId {
271237 /// Makes a local `DefId` from the given `DefIndex`.
272238 #[ inline]
0 commit comments