@@ -15,23 +15,18 @@ use hir::def_id::DefId;
15
15
use hir:: map:: { DefPathData , Node } ;
16
16
use hir;
17
17
use ich:: NodeIdHashingMode ;
18
- use middle:: const_val:: ConstVal ;
19
18
use traits:: { self , ObligationCause } ;
20
19
use ty:: { self , Ty , TyCtxt , GenericParamDefKind , TypeFoldable } ;
21
- use ty:: fold:: TypeVisitor ;
22
20
use ty:: subst:: { Substs , UnpackedKind } ;
23
21
use ty:: maps:: TyCtxtAt ;
24
22
use ty:: TypeVariants :: * ;
25
23
use ty:: layout:: { Integer , IntegerExt } ;
26
24
use util:: common:: ErrorReported ;
27
25
use middle:: lang_items;
28
26
29
- use rustc_data_structures:: stable_hasher:: { StableHasher , StableHasherResult ,
30
- HashStable } ;
27
+ use rustc_data_structures:: stable_hasher:: { StableHasher , HashStable } ;
31
28
use rustc_data_structures:: fx:: FxHashMap ;
32
29
use std:: { cmp, fmt} ;
33
- use std:: hash:: Hash ;
34
- use std:: intrinsics;
35
30
use syntax:: ast;
36
31
use syntax:: attr:: { self , SignedInt , UnsignedInt } ;
37
32
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -615,150 +610,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
615
610
}
616
611
}
617
612
618
- pub struct TypeIdHasher < ' a , ' gcx : ' a +' tcx , ' tcx : ' a , W > {
619
- tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
620
- state : StableHasher < W > ,
621
- }
622
-
623
- impl < ' a , ' gcx , ' tcx , W > TypeIdHasher < ' a , ' gcx , ' tcx , W >
624
- where W : StableHasherResult
625
- {
626
- pub fn new ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Self {
627
- TypeIdHasher { tcx : tcx, state : StableHasher :: new ( ) }
628
- }
629
-
630
- pub fn finish ( self ) -> W {
631
- self . state . finish ( )
632
- }
633
-
634
- pub fn hash < T : Hash > ( & mut self , x : T ) {
635
- x. hash ( & mut self . state ) ;
636
- }
637
-
638
- fn hash_discriminant_u8 < T > ( & mut self , x : & T ) {
639
- let v = unsafe {
640
- intrinsics:: discriminant_value ( x)
641
- } ;
642
- let b = v as u8 ;
643
- assert_eq ! ( v, b as u64 ) ;
644
- self . hash ( b)
645
- }
646
-
647
- fn def_id ( & mut self , did : DefId ) {
648
- // Hash the DefPath corresponding to the DefId, which is independent
649
- // of compiler internal state. We already have a stable hash value of
650
- // all DefPaths available via tcx.def_path_hash(), so we just feed that
651
- // into the hasher.
652
- let hash = self . tcx . def_path_hash ( did) ;
653
- self . hash ( hash) ;
654
- }
655
- }
656
-
657
- impl < ' a , ' gcx , ' tcx , W > TypeVisitor < ' tcx > for TypeIdHasher < ' a , ' gcx , ' tcx , W >
658
- where W : StableHasherResult
659
- {
660
- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
661
- // Distinguish between the Ty variants uniformly.
662
- self . hash_discriminant_u8 ( & ty. sty ) ;
663
-
664
- match ty. sty {
665
- TyInt ( i) => self . hash ( i) ,
666
- TyUint ( u) => self . hash ( u) ,
667
- TyFloat ( f) => self . hash ( f) ,
668
- TyArray ( _, n) => {
669
- self . hash_discriminant_u8 ( & n. val ) ;
670
- match n. val {
671
- ConstVal :: Value ( alloc) => self . hash ( alloc) ,
672
- ConstVal :: Unevaluated ( def_id, _) => self . def_id ( def_id) ,
673
- }
674
- }
675
- TyRawPtr ( m) => self . hash ( m. mutbl ) ,
676
- TyRef ( _, _, mutbl) => self . hash ( mutbl) ,
677
- TyClosure ( def_id, _) |
678
- TyGenerator ( def_id, _, _) |
679
- TyAnon ( def_id, _) |
680
- TyFnDef ( def_id, _) => self . def_id ( def_id) ,
681
- TyAdt ( d, _) => self . def_id ( d. did ) ,
682
- TyForeign ( def_id) => self . def_id ( def_id) ,
683
- TyFnPtr ( f) => {
684
- self . hash ( f. unsafety ( ) ) ;
685
- self . hash ( f. abi ( ) ) ;
686
- self . hash ( f. variadic ( ) ) ;
687
- self . hash ( f. inputs ( ) . skip_binder ( ) . len ( ) ) ;
688
- }
689
- TyDynamic ( ref data, ..) => {
690
- if let Some ( p) = data. principal ( ) {
691
- self . def_id ( p. def_id ( ) ) ;
692
- }
693
- for d in data. auto_traits ( ) {
694
- self . def_id ( d) ;
695
- }
696
- }
697
- TyGeneratorWitness ( tys) => {
698
- self . hash ( tys. skip_binder ( ) . len ( ) ) ;
699
- }
700
- TyTuple ( tys) => {
701
- self . hash ( tys. len ( ) ) ;
702
- }
703
- TyParam ( p) => {
704
- self . hash ( p. idx ) ;
705
- self . hash ( p. name ) ;
706
- }
707
- TyProjection ( ref data) => {
708
- self . def_id ( data. item_def_id ) ;
709
- }
710
- TyNever |
711
- TyBool |
712
- TyChar |
713
- TyStr |
714
- TySlice ( _) => { }
715
-
716
- TyError |
717
- TyInfer ( _) => bug ! ( "TypeIdHasher: unexpected type {}" , ty)
718
- }
719
-
720
- ty. super_visit_with ( self )
721
- }
722
-
723
- fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> bool {
724
- self . hash_discriminant_u8 ( r) ;
725
- match * r {
726
- ty:: ReErased |
727
- ty:: ReStatic |
728
- ty:: ReEmpty => {
729
- // No variant fields to hash for these ...
730
- }
731
- ty:: ReCanonical ( c) => {
732
- self . hash ( c) ;
733
- }
734
- ty:: ReLateBound ( db, ty:: BrAnon ( i) ) => {
735
- self . hash ( db. depth ) ;
736
- self . hash ( i) ;
737
- }
738
- ty:: ReEarlyBound ( ty:: EarlyBoundRegion { def_id, .. } ) => {
739
- self . def_id ( def_id) ;
740
- }
741
-
742
- ty:: ReClosureBound ( ..) |
743
- ty:: ReLateBound ( ..) |
744
- ty:: ReFree ( ..) |
745
- ty:: ReScope ( ..) |
746
- ty:: ReVar ( ..) |
747
- ty:: ReSkolemized ( ..) => {
748
- bug ! ( "TypeIdHasher: unexpected region {:?}" , r)
749
- }
750
- }
751
- false
752
- }
753
-
754
- fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , x : & ty:: Binder < T > ) -> bool {
755
- // Anonymize late-bound regions so that, for example:
756
- // `for<'a, b> fn(&'a &'b T)` and `for<'a, b> fn(&'b &'a T)`
757
- // result in the same TypeId (the two types are equivalent).
758
- self . tcx . anonymize_late_bound_regions ( x) . super_visit_with ( self )
759
- }
760
- }
761
-
762
613
impl < ' a , ' tcx > ty:: TyS < ' tcx > {
763
614
pub fn moves_by_default ( & ' tcx self ,
764
615
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments