@@ -6,6 +6,8 @@ use crate::spec::Target;
66use std:: ops:: { Add , Deref , Sub , Mul , AddAssign , Range , RangeInclusive } ;
77
88use rustc_index:: vec:: { Idx , IndexVec } ;
9+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
10+ use rustc_macros:: HashStable_Generic ;
911use syntax_pos:: Span ;
1012
1113pub mod call;
@@ -246,6 +248,12 @@ pub struct Size {
246248 raw : u64
247249}
248250
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+
249257impl Size {
250258 pub const ZERO : Size = Self :: from_bytes ( 0 ) ;
251259
@@ -369,6 +377,12 @@ pub struct Align {
369377 pow2 : u8 ,
370378}
371379
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+
372386impl Align {
373387 pub fn from_bits ( bits : u64 ) -> Result < Align , String > {
374388 Align :: from_bytes ( Size :: from_bits ( bits) . bytes ( ) )
@@ -422,7 +436,8 @@ impl Align {
422436}
423437
424438/// 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 ) ]
426441pub struct AbiAndPrefAlign {
427442 pub abi : Align ,
428443 pub pref : Align ,
@@ -452,7 +467,7 @@ impl AbiAndPrefAlign {
452467}
453468
454469/// 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 ) ]
456471pub enum Integer {
457472 I8 ,
458473 I16 ,
@@ -533,7 +548,7 @@ impl Integer {
533548}
534549
535550/// 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 ) ]
537552pub enum Primitive {
538553 /// The `bool` is the signedness of the `Integer` type.
539554 ///
@@ -608,6 +623,15 @@ pub struct Scalar {
608623 pub valid_range : RangeInclusive < u128 > ,
609624}
610625
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+
611635impl Scalar {
612636 pub fn is_bool ( & self ) -> bool {
613637 if let Int ( I8 , _) = self . value {
@@ -636,7 +660,7 @@ impl Scalar {
636660}
637661
638662/// 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 ) ]
640664pub enum FieldPlacement {
641665 /// All fields start at no offset. The `usize` is the field count.
642666 ///
@@ -752,7 +776,7 @@ impl FieldPlacement {
752776
753777/// Describes how values of the type are passed by target ABIs,
754778/// 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 ) ]
756780pub enum Abi {
757781 Uninhabited ,
758782 Scalar ( Scalar ) ,
@@ -803,7 +827,13 @@ rustc_index::newtype_index! {
803827 pub struct VariantIdx { .. }
804828}
805829
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 ) ]
807837pub enum Variants {
808838 /// Single enum variants, structs/tuples, unions, and all non-ADTs.
809839 Single {
@@ -842,7 +872,28 @@ pub enum DiscriminantKind {
842872 } ,
843873}
844874
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 ) ]
846897pub struct Niche {
847898 pub offset : Size ,
848899 pub scalar : Scalar ,
@@ -906,7 +957,7 @@ impl Niche {
906957 }
907958}
908959
909- #[ derive( PartialEq , Eq , Hash , Debug ) ]
960+ #[ derive( PartialEq , Eq , Hash , Debug , HashStable_Generic ) ]
910961pub struct LayoutDetails {
911962 pub variants : Variants ,
912963 pub fields : FieldPlacement ,
0 commit comments