@@ -6,6 +6,8 @@ use crate::spec::Target;
6
6
use std:: ops:: { Add , Deref , Sub , Mul , AddAssign , Range , RangeInclusive } ;
7
7
8
8
use rustc_index:: vec:: { Idx , IndexVec } ;
9
+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
10
+ use rustc_macros:: HashStable_Generic ;
9
11
use syntax_pos:: Span ;
10
12
11
13
pub mod call;
@@ -246,6 +248,12 @@ pub struct Size {
246
248
raw : u64
247
249
}
248
250
251
+ impl < CTX > HashStable < CTX > for Size {
252
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
253
+ self . bytes ( ) . hash_stable ( hcx, hasher) ;
254
+ }
255
+ }
256
+
249
257
impl Size {
250
258
pub const ZERO : Size = Self :: from_bytes ( 0 ) ;
251
259
@@ -369,6 +377,12 @@ pub struct Align {
369
377
pow2 : u8 ,
370
378
}
371
379
380
+ impl < CTX > HashStable < CTX > for Align {
381
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
382
+ self . bytes ( ) . hash_stable ( hcx, hasher) ;
383
+ }
384
+ }
385
+
372
386
impl Align {
373
387
pub fn from_bits ( bits : u64 ) -> Result < Align , String > {
374
388
Align :: from_bytes ( Size :: from_bits ( bits) . bytes ( ) )
@@ -422,7 +436,8 @@ impl Align {
422
436
}
423
437
424
438
/// A pair of aligments, ABI-mandated and preferred.
425
- #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
439
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ,
440
+ RustcEncodable , RustcDecodable , HashStable_Generic ) ]
426
441
pub struct AbiAndPrefAlign {
427
442
pub abi : Align ,
428
443
pub pref : Align ,
@@ -452,7 +467,7 @@ impl AbiAndPrefAlign {
452
467
}
453
468
454
469
/// Integers, also used for enum discriminants.
455
- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
470
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , HashStable_Generic ) ]
456
471
pub enum Integer {
457
472
I8 ,
458
473
I16 ,
@@ -533,7 +548,7 @@ impl Integer {
533
548
}
534
549
535
550
/// Fundamental unit of memory access and layout.
536
- #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
551
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
537
552
pub enum Primitive {
538
553
/// The `bool` is the signedness of the `Integer` type.
539
554
///
@@ -608,6 +623,15 @@ pub struct Scalar {
608
623
pub valid_range : RangeInclusive < u128 > ,
609
624
}
610
625
626
+ impl < CTX > HashStable < CTX > for Scalar {
627
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
628
+ let Scalar { value, ref valid_range } = * self ;
629
+ value. hash_stable ( hcx, hasher) ;
630
+ valid_range. start ( ) . hash_stable ( hcx, hasher) ;
631
+ valid_range. end ( ) . hash_stable ( hcx, hasher) ;
632
+ }
633
+ }
634
+
611
635
impl Scalar {
612
636
pub fn is_bool ( & self ) -> bool {
613
637
if let Int ( I8 , _) = self . value {
@@ -636,7 +660,7 @@ impl Scalar {
636
660
}
637
661
638
662
/// Describes how the fields of a type are located in memory.
639
- #[ derive( PartialEq , Eq , Hash , Debug ) ]
663
+ #[ derive( PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
640
664
pub enum FieldPlacement {
641
665
/// All fields start at no offset. The `usize` is the field count.
642
666
///
@@ -752,7 +776,7 @@ impl FieldPlacement {
752
776
753
777
/// Describes how values of the type are passed by target ABIs,
754
778
/// in terms of categories of C types there are ABI rules for.
755
- #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
779
+ #[ derive( Clone , PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
756
780
pub enum Abi {
757
781
Uninhabited ,
758
782
Scalar ( Scalar ) ,
@@ -803,7 +827,13 @@ rustc_index::newtype_index! {
803
827
pub struct VariantIdx { .. }
804
828
}
805
829
806
- #[ derive( PartialEq , Eq , Hash , Debug ) ]
830
+ impl < CTX > HashStable < CTX > for VariantIdx {
831
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
832
+ self . as_u32 ( ) . hash_stable ( hcx, hasher)
833
+ }
834
+ }
835
+
836
+ #[ derive( PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
807
837
pub enum Variants {
808
838
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
809
839
Single {
@@ -842,7 +872,28 @@ pub enum DiscriminantKind {
842
872
} ,
843
873
}
844
874
845
- #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
875
+ impl < CTX > HashStable < CTX > for DiscriminantKind {
876
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
877
+ use DiscriminantKind :: * ;
878
+ std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
879
+
880
+ match * self {
881
+ Tag => { }
882
+ Niche {
883
+ dataful_variant,
884
+ ref niche_variants,
885
+ niche_start,
886
+ } => {
887
+ dataful_variant. hash_stable ( hcx, hasher) ;
888
+ niche_variants. start ( ) . hash_stable ( hcx, hasher) ;
889
+ niche_variants. end ( ) . hash_stable ( hcx, hasher) ;
890
+ niche_start. hash_stable ( hcx, hasher) ;
891
+ }
892
+ }
893
+ }
894
+ }
895
+
896
+ #[ derive( Clone , PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
846
897
pub struct Niche {
847
898
pub offset : Size ,
848
899
pub scalar : Scalar ,
@@ -906,7 +957,7 @@ impl Niche {
906
957
}
907
958
}
908
959
909
- #[ derive( PartialEq , Eq , Hash , Debug ) ]
960
+ #[ derive( PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
910
961
pub struct LayoutDetails {
911
962
pub variants : Variants ,
912
963
pub fields : FieldPlacement ,
0 commit comments