@@ -402,17 +402,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
402
402
// `isize` completely when hashing. To ensure that these don't leak in we use a
403
403
// custom hasher implementation here which inflates the size of these to a `u64`
404
404
// and `i64`.
405
- struct WidenUsizeHasher < H > {
405
+ //
406
+ // The same goes for endianess: We always convert multi-byte integers to little
407
+ // endian before hashing.
408
+ struct ArchIndependentHasher < H > {
406
409
inner : H ,
407
410
}
408
411
409
- impl < H > WidenUsizeHasher < H > {
410
- fn new ( inner : H ) -> WidenUsizeHasher < H > {
411
- WidenUsizeHasher { inner : inner }
412
+ impl < H > ArchIndependentHasher < H > {
413
+ fn new ( inner : H ) -> ArchIndependentHasher < H > {
414
+ ArchIndependentHasher { inner : inner }
412
415
}
413
416
}
414
417
415
- impl < H : Hasher > Hasher for WidenUsizeHasher < H > {
418
+ impl < H : Hasher > Hasher for ArchIndependentHasher < H > {
416
419
fn write ( & mut self , bytes : & [ u8 ] ) {
417
420
self . inner . write ( bytes)
418
421
}
@@ -425,44 +428,44 @@ impl<H: Hasher> Hasher for WidenUsizeHasher<H> {
425
428
self . inner . write_u8 ( i)
426
429
}
427
430
fn write_u16 ( & mut self , i : u16 ) {
428
- self . inner . write_u16 ( i)
431
+ self . inner . write_u16 ( i. to_le ( ) )
429
432
}
430
433
fn write_u32 ( & mut self , i : u32 ) {
431
- self . inner . write_u32 ( i)
434
+ self . inner . write_u32 ( i. to_le ( ) )
432
435
}
433
436
fn write_u64 ( & mut self , i : u64 ) {
434
- self . inner . write_u64 ( i)
437
+ self . inner . write_u64 ( i. to_le ( ) )
435
438
}
436
439
fn write_usize ( & mut self , i : usize ) {
437
- self . inner . write_u64 ( i as u64 )
440
+ self . inner . write_u64 ( ( i as u64 ) . to_le ( ) )
438
441
}
439
442
fn write_i8 ( & mut self , i : i8 ) {
440
443
self . inner . write_i8 ( i)
441
444
}
442
445
fn write_i16 ( & mut self , i : i16 ) {
443
- self . inner . write_i16 ( i)
446
+ self . inner . write_i16 ( i. to_le ( ) )
444
447
}
445
448
fn write_i32 ( & mut self , i : i32 ) {
446
- self . inner . write_i32 ( i)
449
+ self . inner . write_i32 ( i. to_le ( ) )
447
450
}
448
451
fn write_i64 ( & mut self , i : i64 ) {
449
- self . inner . write_i64 ( i)
452
+ self . inner . write_i64 ( i. to_le ( ) )
450
453
}
451
454
fn write_isize ( & mut self , i : isize ) {
452
- self . inner . write_i64 ( i as i64 )
455
+ self . inner . write_i64 ( ( i as i64 ) . to_le ( ) )
453
456
}
454
457
}
455
458
456
459
pub struct TypeIdHasher < ' a , ' gcx : ' a +' tcx , ' tcx : ' a , H > {
457
460
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
458
- state : WidenUsizeHasher < H > ,
461
+ state : ArchIndependentHasher < H > ,
459
462
}
460
463
461
464
impl < ' a , ' gcx , ' tcx , H : Hasher > TypeIdHasher < ' a , ' gcx , ' tcx , H > {
462
465
pub fn new ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , state : H ) -> Self {
463
466
TypeIdHasher {
464
467
tcx : tcx,
465
- state : WidenUsizeHasher :: new ( state) ,
468
+ state : ArchIndependentHasher :: new ( state) ,
466
469
}
467
470
}
468
471
@@ -493,6 +496,10 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeIdHasher<'a, 'gcx, 'tcx, H> {
493
496
pub fn def_path ( & mut self , def_path : & ast_map:: DefPath ) {
494
497
def_path. deterministic_hash_to ( self . tcx , & mut self . state ) ;
495
498
}
499
+
500
+ pub fn into_inner ( self ) -> H {
501
+ self . state . inner
502
+ }
496
503
}
497
504
498
505
impl < ' a , ' gcx , ' tcx , H : Hasher > TypeVisitor < ' tcx > for TypeIdHasher < ' a , ' gcx , ' tcx , H > {
0 commit comments