1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! This module contains `HashStable` implementations for various data types
12 //! from rustc::ty in no particular order.
14 use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
15 use rustc_data_structures::fx::FxHashMap;
16 use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
17 StableHasher, StableHasherResult};
18 use std::cell::RefCell;
19 use std::hash as std_hash;
27 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
28 for &'gcx ty::Slice<T>
29 where T: HashStable<StableHashingContext<'a>> {
30 fn hash_stable<W: StableHasherResult>(&self,
31 hcx: &mut StableHashingContext<'a>,
32 hasher: &mut StableHasher<W>) {
34 static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
35 RefCell::new(FxHashMap());
38 let hash = CACHE.with(|cache| {
39 let key = (self.as_ptr() as usize, self.len());
40 if let Some(&hash) = cache.borrow().get(&key) {
44 let mut hasher = StableHasher::new();
45 (&self[..]).hash_stable(hcx, &mut hasher);
47 let hash: Fingerprint = hasher.finish();
48 cache.borrow_mut().insert(key, hash);
52 hash.hash_stable(hcx, hasher);
56 impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::Slice<T>
57 where T: HashStable<StableHashingContext<'a>>
59 type KeyType = Fingerprint;
62 fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint {
63 let mut hasher = StableHasher::new();
64 let mut hcx: StableHashingContext<'a> = hcx.clone();
65 self.hash_stable(&mut hcx, &mut hasher);
70 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
71 fn hash_stable<W: StableHasherResult>(&self,
72 hcx: &mut StableHashingContext<'a>,
73 hasher: &mut StableHasher<W>) {
74 self.unpack().hash_stable(hcx, hasher);
78 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
79 for ty::subst::UnpackedKind<'gcx> {
80 fn hash_stable<W: StableHasherResult>(&self,
81 hcx: &mut StableHashingContext<'a>,
82 hasher: &mut StableHasher<W>) {
83 mem::discriminant(self).hash_stable(hcx, hasher);
85 ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher),
86 ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher),
91 impl<'a> HashStable<StableHashingContext<'a>>
93 fn hash_stable<W: StableHasherResult>(&self,
94 hcx: &mut StableHashingContext<'a>,
95 hasher: &mut StableHasher<W>) {
96 mem::discriminant(self).hash_stable(hcx, hasher);
101 // No variant fields to hash for these ...
103 ty::ReCanonical(c) => {
104 c.hash_stable(hcx, hasher);
106 ty::ReLateBound(db, ty::BrAnon(i)) => {
107 db.hash_stable(hcx, hasher);
108 i.hash_stable(hcx, hasher);
110 ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
111 db.hash_stable(hcx, hasher);
112 def_id.hash_stable(hcx, hasher);
113 name.hash_stable(hcx, hasher);
115 ty::ReLateBound(db, ty::BrEnv) => {
116 db.hash_stable(hcx, hasher);
118 ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
119 def_id.hash_stable(hcx, hasher);
120 index.hash_stable(hcx, hasher);
121 name.hash_stable(hcx, hasher);
123 ty::ReScope(scope) => {
124 scope.hash_stable(hcx, hasher);
126 ty::ReFree(ref free_region) => {
127 free_region.hash_stable(hcx, hasher);
129 ty::ReClosureBound(vid) => {
130 vid.hash_stable(hcx, hasher);
132 ty::ReLateBound(..) |
134 ty::ReSkolemized(..) => {
135 bug!("StableHasher: unexpected region {:?}", *self)
141 impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
143 fn hash_stable<W: StableHasherResult>(&self,
144 hcx: &mut StableHashingContext<'a>,
145 hasher: &mut StableHasher<W>) {
146 use rustc_data_structures::indexed_vec::Idx;
147 self.index().hash_stable(hcx, hasher);
151 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::CanonicalVar {
153 fn hash_stable<W: StableHasherResult>(&self,
154 hcx: &mut StableHashingContext<'gcx>,
155 hasher: &mut StableHasher<W>) {
156 use rustc_data_structures::indexed_vec::Idx;
157 self.index().hash_stable(hcx, hasher);
161 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
162 for ty::adjustment::AutoBorrow<'gcx> {
163 fn hash_stable<W: StableHasherResult>(&self,
164 hcx: &mut StableHashingContext<'a>,
165 hasher: &mut StableHasher<W>) {
166 mem::discriminant(self).hash_stable(hcx, hasher);
168 ty::adjustment::AutoBorrow::Ref(ref region, mutability) => {
169 region.hash_stable(hcx, hasher);
170 mutability.hash_stable(hcx, hasher);
172 ty::adjustment::AutoBorrow::RawPtr(mutability) => {
173 mutability.hash_stable(hcx, hasher);
179 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
180 for ty::adjustment::Adjust<'gcx> {
181 fn hash_stable<W: StableHasherResult>(&self,
182 hcx: &mut StableHashingContext<'a>,
183 hasher: &mut StableHasher<W>) {
184 mem::discriminant(self).hash_stable(hcx, hasher);
186 ty::adjustment::Adjust::NeverToAny |
187 ty::adjustment::Adjust::ReifyFnPointer |
188 ty::adjustment::Adjust::UnsafeFnPointer |
189 ty::adjustment::Adjust::ClosureFnPointer |
190 ty::adjustment::Adjust::MutToConstPointer |
191 ty::adjustment::Adjust::Unsize => {}
192 ty::adjustment::Adjust::Deref(ref overloaded) => {
193 overloaded.hash_stable(hcx, hasher);
195 ty::adjustment::Adjust::Borrow(ref autoref) => {
196 autoref.hash_stable(hcx, hasher);
202 impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
203 impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
204 impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
205 impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
210 impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
211 fn hash_stable<W: StableHasherResult>(&self,
212 hcx: &mut StableHashingContext<'gcx>,
213 hasher: &mut StableHasher<W>) {
214 mem::discriminant(self).hash_stable(hcx, hasher);
216 ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
217 allow_two_phase_borrow.hash_stable(hcx, hasher);
219 ty::adjustment::AutoBorrowMutability::Immutable => {}
224 impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
226 impl_stable_hash_for!(enum ty::BorrowKind {
232 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
233 for ty::UpvarCapture<'gcx> {
234 fn hash_stable<W: StableHasherResult>(&self,
235 hcx: &mut StableHashingContext<'a>,
236 hasher: &mut StableHasher<W>) {
237 mem::discriminant(self).hash_stable(hcx, hasher);
239 ty::UpvarCapture::ByValue => {}
240 ty::UpvarCapture::ByRef(ref up_var_borrow) => {
241 up_var_borrow.hash_stable(hcx, hasher);
247 impl_stable_hash_for!(struct ty::GenSig<'tcx> {
252 impl_stable_hash_for!(struct ty::FnSig<'tcx> {
259 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
260 where T: HashStable<StableHashingContext<'a>>
262 fn hash_stable<W: StableHasherResult>(&self,
263 hcx: &mut StableHashingContext<'a>,
264 hasher: &mut StableHasher<W>) {
265 self.skip_binder().hash_stable(hcx, hasher);
269 impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce });
271 impl_stable_hash_for!(enum ty::Visibility {
277 impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
278 impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
279 impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
281 impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
282 for ty::OutlivesPredicate<A, B>
283 where A: HashStable<StableHashingContext<'a>>,
284 B: HashStable<StableHashingContext<'a>>,
286 fn hash_stable<W: StableHasherResult>(&self,
287 hcx: &mut StableHashingContext<'a>,
288 hasher: &mut StableHasher<W>) {
289 let ty::OutlivesPredicate(ref a, ref b) = *self;
290 a.hash_stable(hcx, hasher);
291 b.hash_stable(hcx, hasher);
295 impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
296 impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
299 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
300 fn hash_stable<W: StableHasherResult>(&self,
301 hcx: &mut StableHashingContext<'a>,
302 hasher: &mut StableHasher<W>) {
303 mem::discriminant(self).hash_stable(hcx, hasher);
305 ty::Predicate::Trait(ref pred) => {
306 pred.hash_stable(hcx, hasher);
308 ty::Predicate::Subtype(ref pred) => {
309 pred.hash_stable(hcx, hasher);
311 ty::Predicate::RegionOutlives(ref pred) => {
312 pred.hash_stable(hcx, hasher);
314 ty::Predicate::TypeOutlives(ref pred) => {
315 pred.hash_stable(hcx, hasher);
317 ty::Predicate::Projection(ref pred) => {
318 pred.hash_stable(hcx, hasher);
320 ty::Predicate::WellFormed(ty) => {
321 ty.hash_stable(hcx, hasher);
323 ty::Predicate::ObjectSafe(def_id) => {
324 def_id.hash_stable(hcx, hasher);
326 ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
327 def_id.hash_stable(hcx, hasher);
328 closure_substs.hash_stable(hcx, hasher);
329 closure_kind.hash_stable(hcx, hasher);
331 ty::Predicate::ConstEvaluatable(def_id, substs) => {
332 def_id.hash_stable(hcx, hasher);
333 substs.hash_stable(hcx, hasher);
339 impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
340 fn hash_stable<W: StableHasherResult>(&self,
341 _: &mut StableHashingContext<'a>,
342 hasher: &mut StableHasher<W>) {
343 std_hash::Hash::hash(self, hasher);
347 impl_stable_hash_for!(struct ty::VariantDef {
355 impl_stable_hash_for!(enum ty::VariantDiscr {
360 impl_stable_hash_for!(struct ty::FieldDef {
362 ident -> (ident.name),
366 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
367 for ::mir::interpret::ConstValue<'gcx> {
368 fn hash_stable<W: StableHasherResult>(&self,
369 hcx: &mut StableHashingContext<'a>,
370 hasher: &mut StableHasher<W>) {
371 use mir::interpret::ConstValue::*;
373 mem::discriminant(self).hash_stable(hcx, hasher);
376 Unevaluated(def_id, substs) => {
377 def_id.hash_stable(hcx, hasher);
378 substs.hash_stable(hcx, hasher);
381 val.hash_stable(hcx, hasher);
383 ScalarPair(a, b) => {
384 a.hash_stable(hcx, hasher);
385 b.hash_stable(hcx, hasher);
387 ByRef(alloc, offset) => {
388 alloc.hash_stable(hcx, hasher);
389 offset.hash_stable(hcx, hasher);
395 impl_stable_hash_for!(enum mir::interpret::Value {
401 impl_stable_hash_for!(struct mir::interpret::Pointer {
406 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
407 fn hash_stable<W: StableHasherResult>(
409 hcx: &mut StableHashingContext<'a>,
410 hasher: &mut StableHasher<W>,
412 ty::tls::with_opt(|tcx| {
413 trace!("hashing {:?}", *self);
414 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
415 let alloc_kind = tcx.alloc_map.lock().get(*self).expect("no value for AllocId");
416 alloc_kind.hash_stable(hcx, hasher);
421 impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
422 for mir::interpret::AllocType<'gcx, M> {
423 fn hash_stable<W: StableHasherResult>(&self,
424 hcx: &mut StableHashingContext<'a>,
425 hasher: &mut StableHasher<W>) {
426 use mir::interpret::AllocType::*;
428 mem::discriminant(self).hash_stable(hcx, hasher);
431 Function(instance) => instance.hash_stable(hcx, hasher),
432 Static(def_id) => def_id.hash_stable(hcx, hasher),
433 Memory(ref mem) => mem.hash_stable(hcx, hasher),
438 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
439 fn hash_stable<W: StableHasherResult>(
441 hcx: &mut StableHashingContext<'a>,
442 hasher: &mut StableHasher<W>,
444 self.bytes.hash_stable(hcx, hasher);
445 for reloc in self.relocations.iter() {
446 reloc.hash_stable(hcx, hasher);
448 self.undef_mask.hash_stable(hcx, hasher);
449 self.align.hash_stable(hcx, hasher);
450 self.runtime_mutability.hash_stable(hcx, hasher);
454 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
460 impl<'a> HashStable<StableHashingContext<'a>>
461 for ::mir::interpret::Scalar {
462 fn hash_stable<W: StableHasherResult>(&self,
463 hcx: &mut StableHashingContext<'a>,
464 hasher: &mut StableHasher<W>) {
465 use mir::interpret::Scalar::*;
467 mem::discriminant(self).hash_stable(hcx, hasher);
469 Bits { bits, defined } => {
470 bits.hash_stable(hcx, hasher);
471 defined.hash_stable(hcx, hasher);
473 Ptr(ptr) => ptr.hash_stable(hcx, hasher),
478 impl_stable_hash_for!(struct ty::Const<'tcx> {
483 impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> {
489 impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
495 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
496 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
498 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
503 impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
505 impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
506 for ::mir::interpret::EvalErrorKind<'gcx, O> {
507 fn hash_stable<W: StableHasherResult>(&self,
508 hcx: &mut StableHashingContext<'a>,
509 hasher: &mut StableHasher<W>) {
510 use mir::interpret::EvalErrorKind::*;
512 mem::discriminant(&self).hash_stable(hcx, hasher);
515 DanglingPointerDeref |
517 InvalidMemoryAccess |
518 InvalidFunctionPointer |
520 InvalidDiscriminant |
521 InvalidNullPointerUsage |
528 StackFrameLimitReached |
531 CalledClosureAsFunction |
532 VtableForArgumentlessMethod |
533 ModifiedConstantMemory |
536 ReallocateNonBasePtr |
537 DeallocateNonBasePtr |
541 ReadFromReturnPointer |
542 UnimplementedTraitSelection |
546 DerefFunctionPointer |
551 GeneratorResumedAfterReturn |
552 GeneratorResumedAfterPanic |
554 ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
555 MachineError(ref err) => err.hash_stable(hcx, hasher),
556 FunctionPointerTyMismatch(a, b) => {
557 a.hash_stable(hcx, hasher);
558 b.hash_stable(hcx, hasher)
560 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
561 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
567 ptr.hash_stable(hcx, hasher);
568 access.hash_stable(hcx, hasher);
569 allocation_size.hash_stable(hcx, hasher)
571 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
572 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
573 BoundsCheck { ref len, ref index } => {
574 len.hash_stable(hcx, hasher);
575 index.hash_stable(hcx, hasher)
577 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
578 InvalidChar(c) => c.hash_stable(hcx, hasher),
579 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
580 AlignmentCheckFailed {
584 required.hash_stable(hcx, hasher);
585 has.hash_stable(hcx, hasher)
587 MemoryLockViolation {
594 ptr.hash_stable(hcx, hasher);
595 len.hash_stable(hcx, hasher);
596 frame.hash_stable(hcx, hasher);
597 access.hash_stable(hcx, hasher);
598 lock.hash_stable(hcx, hasher)
600 MemoryAcquireConflict {
606 ptr.hash_stable(hcx, hasher);
607 len.hash_stable(hcx, hasher);
608 kind.hash_stable(hcx, hasher);
609 lock.hash_stable(hcx, hasher)
611 InvalidMemoryLockRelease {
617 ptr.hash_stable(hcx, hasher);
618 len.hash_stable(hcx, hasher);
619 frame.hash_stable(hcx, hasher);
620 lock.hash_stable(hcx, hasher)
622 DeallocatedLockedMemory {
626 ptr.hash_stable(hcx, hasher);
627 lock.hash_stable(hcx, hasher)
629 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
630 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
631 ReallocatedWrongMemoryKind(ref a, ref b) => {
632 a.hash_stable(hcx, hasher);
633 b.hash_stable(hcx, hasher)
635 DeallocatedWrongMemoryKind(ref a, ref b) => {
636 a.hash_stable(hcx, hasher);
637 b.hash_stable(hcx, hasher)
639 IncorrectAllocationInformation(a, b, c, d) => {
640 a.hash_stable(hcx, hasher);
641 b.hash_stable(hcx, hasher);
642 c.hash_stable(hcx, hasher);
643 d.hash_stable(hcx, hasher)
645 Layout(lay) => lay.hash_stable(hcx, hasher),
646 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
647 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
648 Overflow(op) => op.hash_stable(hcx, hasher),
653 impl_stable_hash_for!(enum mir::interpret::Lock {
659 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
664 impl_stable_hash_for!(enum mir::interpret::AccessKind {
669 impl_stable_hash_for!(enum ty::Variance {
676 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
680 impl_stable_hash_for!(struct ty::Generics {
684 // Reverse map to each param's `index` field, from its `def_id`.
685 param_def_id_to_index -> _, // Don't hash this
687 has_late_bound_regions,
690 impl_stable_hash_for!(struct ty::GenericParamDef {
698 impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
699 fn hash_stable<W: StableHasherResult>(&self,
700 hcx: &mut StableHashingContext<'a>,
701 hasher: &mut StableHasher<W>) {
702 mem::discriminant(self).hash_stable(hcx, hasher);
704 ty::GenericParamDefKind::Lifetime => {}
705 ty::GenericParamDefKind::Type {
707 ref object_lifetime_default,
710 has_default.hash_stable(hcx, hasher);
711 object_lifetime_default.hash_stable(hcx, hasher);
712 synthetic.hash_stable(hcx, hasher);
718 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
719 for ::middle::resolve_lifetime::Set1<T>
720 where T: HashStable<StableHashingContext<'a>>
722 fn hash_stable<W: StableHasherResult>(&self,
723 hcx: &mut StableHashingContext<'a>,
724 hasher: &mut StableHasher<W>) {
725 use middle::resolve_lifetime::Set1;
727 mem::discriminant(self).hash_stable(hcx, hasher);
733 Set1::One(ref value) => {
734 value.hash_stable(hcx, hasher);
740 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
745 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
747 EarlyBound(index, decl, is_in_band),
748 LateBound(db_index, decl, is_in_band),
749 LateBoundAnon(db_index, anon_index),
750 Free(call_site_scope_data, decl)
753 impl_stable_hash_for!(enum ty::cast::CastKind {
767 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
768 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
770 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
771 type KeyType = region::Scope;
774 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
779 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
781 first_statement_index
784 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
788 impl_stable_hash_for!(struct ty::FreeRegion {
793 impl_stable_hash_for!(enum ty::BoundRegion {
795 BrNamed(def_id, name),
800 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
801 for ty::TypeVariants<'gcx>
803 fn hash_stable<W: StableHasherResult>(&self,
804 hcx: &mut StableHashingContext<'a>,
805 hasher: &mut StableHasher<W>) {
806 use ty::TypeVariants::*;
808 mem::discriminant(self).hash_stable(hcx, hasher);
815 // Nothing more to hash.
818 int_ty.hash_stable(hcx, hasher);
821 uint_ty.hash_stable(hcx, hasher);
823 TyFloat(float_ty) => {
824 float_ty.hash_stable(hcx, hasher);
826 TyAdt(adt_def, substs) => {
827 adt_def.hash_stable(hcx, hasher);
828 substs.hash_stable(hcx, hasher);
830 TyArray(inner_ty, len) => {
831 inner_ty.hash_stable(hcx, hasher);
832 len.hash_stable(hcx, hasher);
834 TySlice(inner_ty) => {
835 inner_ty.hash_stable(hcx, hasher);
837 TyRawPtr(pointee_ty) => {
838 pointee_ty.hash_stable(hcx, hasher);
840 TyRef(region, pointee_ty, mutbl) => {
841 region.hash_stable(hcx, hasher);
842 pointee_ty.hash_stable(hcx, hasher);
843 mutbl.hash_stable(hcx, hasher);
845 TyFnDef(def_id, substs) => {
846 def_id.hash_stable(hcx, hasher);
847 substs.hash_stable(hcx, hasher);
849 TyFnPtr(ref sig) => {
850 sig.hash_stable(hcx, hasher);
852 TyDynamic(ref existential_predicates, region) => {
853 existential_predicates.hash_stable(hcx, hasher);
854 region.hash_stable(hcx, hasher);
856 TyClosure(def_id, closure_substs) => {
857 def_id.hash_stable(hcx, hasher);
858 closure_substs.hash_stable(hcx, hasher);
860 TyGenerator(def_id, generator_substs, movability) => {
861 def_id.hash_stable(hcx, hasher);
862 generator_substs.hash_stable(hcx, hasher);
863 movability.hash_stable(hcx, hasher);
865 TyGeneratorWitness(types) => {
866 types.hash_stable(hcx, hasher)
868 TyTuple(inner_tys) => {
869 inner_tys.hash_stable(hcx, hasher);
871 TyProjection(ref projection_ty) => {
872 projection_ty.hash_stable(hcx, hasher);
874 TyAnon(def_id, substs) => {
875 def_id.hash_stable(hcx, hasher);
876 substs.hash_stable(hcx, hasher);
878 TyParam(param_ty) => {
879 param_ty.hash_stable(hcx, hasher);
881 TyForeign(def_id) => {
882 def_id.hash_stable(hcx, hasher);
884 TyInfer(infer_ty) => {
885 infer_ty.hash_stable(hcx, hasher);
891 impl_stable_hash_for!(enum ty::InferTy {
901 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
904 fn hash_stable<W: StableHasherResult>(&self,
905 _hcx: &mut StableHashingContext<'a>,
906 _hasher: &mut StableHasher<W>) {
907 // TyVid values are confined to an inference context and hence
908 // should not be hashed.
909 bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
913 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
916 fn hash_stable<W: StableHasherResult>(&self,
917 _hcx: &mut StableHashingContext<'a>,
918 _hasher: &mut StableHasher<W>) {
919 // IntVid values are confined to an inference context and hence
920 // should not be hashed.
921 bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
925 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
928 fn hash_stable<W: StableHasherResult>(&self,
929 _hcx: &mut StableHashingContext<'a>,
930 _hasher: &mut StableHasher<W>) {
931 // FloatVid values are confined to an inference context and hence
932 // should not be hashed.
933 bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
937 impl_stable_hash_for!(struct ty::ParamTy {
942 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
947 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
948 for ty::ExistentialPredicate<'gcx>
950 fn hash_stable<W: StableHasherResult>(&self,
951 hcx: &mut StableHashingContext<'a>,
952 hasher: &mut StableHasher<W>) {
953 mem::discriminant(self).hash_stable(hcx, hasher);
955 ty::ExistentialPredicate::Trait(ref trait_ref) => {
956 trait_ref.hash_stable(hcx, hasher);
958 ty::ExistentialPredicate::Projection(ref projection) => {
959 projection.hash_stable(hcx, hasher);
961 ty::ExistentialPredicate::AutoTrait(def_id) => {
962 def_id.hash_stable(hcx, hasher);
968 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
973 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
979 impl_stable_hash_for!(struct ty::Instance<'tcx> {
984 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
985 fn hash_stable<W: StableHasherResult>(&self,
986 hcx: &mut StableHashingContext<'a>,
987 hasher: &mut StableHasher<W>) {
988 mem::discriminant(self).hash_stable(hcx, hasher);
991 ty::InstanceDef::Item(def_id) => {
992 def_id.hash_stable(hcx, hasher);
994 ty::InstanceDef::Intrinsic(def_id) => {
995 def_id.hash_stable(hcx, hasher);
997 ty::InstanceDef::FnPtrShim(def_id, ty) => {
998 def_id.hash_stable(hcx, hasher);
999 ty.hash_stable(hcx, hasher);
1001 ty::InstanceDef::Virtual(def_id, n) => {
1002 def_id.hash_stable(hcx, hasher);
1003 n.hash_stable(hcx, hasher);
1005 ty::InstanceDef::ClosureOnceShim { call_once } => {
1006 call_once.hash_stable(hcx, hasher);
1008 ty::InstanceDef::DropGlue(def_id, ty) => {
1009 def_id.hash_stable(hcx, hasher);
1010 ty.hash_stable(hcx, hasher);
1012 ty::InstanceDef::CloneShim(def_id, ty) => {
1013 def_id.hash_stable(hcx, hasher);
1014 ty.hash_stable(hcx, hasher);
1020 impl_stable_hash_for!(struct ty::TraitDef {
1021 // We already have the def_path_hash below, no need to hash it twice
1029 impl_stable_hash_for!(struct ty::Destructor {
1033 impl_stable_hash_for!(struct ty::CrateVariancesMap {
1035 // This is just an irrelevant helper value.
1036 empty_variance -> _,
1039 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
1041 // This is just an irrelevant helper value.
1042 empty_predicate -> _,
1045 impl_stable_hash_for!(struct ty::AssociatedItem {
1047 ident -> (ident.name),
1052 method_has_self_argument
1055 impl_stable_hash_for!(enum ty::AssociatedKind {
1061 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1062 TraitContainer(def_id),
1063 ImplContainer(def_id)
1067 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1068 for ty::steal::Steal<T>
1069 where T: HashStable<StableHashingContext<'a>>
1071 fn hash_stable<W: StableHasherResult>(&self,
1072 hcx: &mut StableHashingContext<'a>,
1073 hasher: &mut StableHasher<W>) {
1074 self.borrow().hash_stable(hcx, hasher);
1078 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1083 impl_stable_hash_for!(enum traits::Reveal {
1088 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1094 impl<'a> HashStable<StableHashingContext<'a>>
1095 for ::middle::privacy::AccessLevels {
1096 fn hash_stable<W: StableHasherResult>(&self,
1097 hcx: &mut StableHashingContext<'a>,
1098 hasher: &mut StableHasher<W>) {
1099 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1100 let ::middle::privacy::AccessLevels {
1104 map.hash_stable(hcx, hasher);
1109 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1113 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1115 Errored(error_reported)
1118 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1120 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1124 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1125 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1126 fn hash_stable<W: StableHasherResult>(&self,
1127 hcx: &mut StableHashingContext<'a>,
1128 hasher: &mut StableHasher<W>) {
1129 use traits::Vtable::*;
1131 mem::discriminant(self).hash_stable(hcx, hasher);
1134 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1135 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1136 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1137 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1138 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1139 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1140 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1141 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1146 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1147 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1148 fn hash_stable<W: StableHasherResult>(&self,
1149 hcx: &mut StableHashingContext<'a>,
1150 hasher: &mut StableHasher<W>) {
1151 let traits::VtableImplData {
1156 impl_def_id.hash_stable(hcx, hasher);
1157 substs.hash_stable(hcx, hasher);
1158 nested.hash_stable(hcx, hasher);
1162 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1163 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1164 fn hash_stable<W: StableHasherResult>(&self,
1165 hcx: &mut StableHashingContext<'a>,
1166 hasher: &mut StableHasher<W>) {
1167 let traits::VtableAutoImplData {
1171 trait_def_id.hash_stable(hcx, hasher);
1172 nested.hash_stable(hcx, hasher);
1176 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1177 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1178 fn hash_stable<W: StableHasherResult>(&self,
1179 hcx: &mut StableHashingContext<'a>,
1180 hasher: &mut StableHasher<W>) {
1181 let traits::VtableObjectData {
1186 upcast_trait_ref.hash_stable(hcx, hasher);
1187 vtable_base.hash_stable(hcx, hasher);
1188 nested.hash_stable(hcx, hasher);
1192 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1193 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1194 fn hash_stable<W: StableHasherResult>(&self,
1195 hcx: &mut StableHashingContext<'a>,
1196 hasher: &mut StableHasher<W>) {
1197 let traits::VtableBuiltinData {
1200 nested.hash_stable(hcx, hasher);
1204 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1205 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1206 fn hash_stable<W: StableHasherResult>(&self,
1207 hcx: &mut StableHashingContext<'a>,
1208 hasher: &mut StableHasher<W>) {
1209 let traits::VtableClosureData {
1214 closure_def_id.hash_stable(hcx, hasher);
1215 substs.hash_stable(hcx, hasher);
1216 nested.hash_stable(hcx, hasher);
1220 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1221 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1222 fn hash_stable<W: StableHasherResult>(&self,
1223 hcx: &mut StableHashingContext<'a>,
1224 hasher: &mut StableHasher<W>) {
1225 let traits::VtableFnPointerData {
1229 fn_ty.hash_stable(hcx, hasher);
1230 nested.hash_stable(hcx, hasher);
1234 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1235 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1236 fn hash_stable<W: StableHasherResult>(&self,
1237 hcx: &mut StableHashingContext<'a>,
1238 hasher: &mut StableHasher<W>) {
1239 let traits::VtableGeneratorData {
1244 generator_def_id.hash_stable(hcx, hasher);
1245 substs.hash_stable(hcx, hasher);
1246 nested.hash_stable(hcx, hasher);
1250 impl_stable_hash_for!(
1251 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1256 impl_stable_hash_for!(
1257 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1262 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1266 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1271 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1277 impl_stable_hash_for!(
1278 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1279 var_values, region_constraints, certainty, value
1283 impl_stable_hash_for!(enum infer::canonical::Certainty {
1287 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1288 fn hash_stable<W: StableHasherResult>(&self,
1289 hcx: &mut StableHashingContext<'a>,
1290 hasher: &mut StableHasher<W>) {
1291 use traits::WhereClause::*;
1293 mem::discriminant(self).hash_stable(hcx, hasher);
1295 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1296 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1297 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1298 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1303 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1304 fn hash_stable<W: StableHasherResult>(&self,
1305 hcx: &mut StableHashingContext<'a>,
1306 hasher: &mut StableHasher<W>) {
1307 use traits::WellFormed::*;
1309 mem::discriminant(self).hash_stable(hcx, hasher);
1311 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1312 Ty(ty) => ty.hash_stable(hcx, hasher),
1317 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1318 fn hash_stable<W: StableHasherResult>(&self,
1319 hcx: &mut StableHashingContext<'a>,
1320 hasher: &mut StableHasher<W>) {
1321 use traits::FromEnv::*;
1323 mem::discriminant(self).hash_stable(hcx, hasher);
1325 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1326 Ty(ty) => ty.hash_stable(hcx, hasher),
1331 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1332 fn hash_stable<W: StableHasherResult>(&self,
1333 hcx: &mut StableHashingContext<'a>,
1334 hasher: &mut StableHasher<W>) {
1335 use traits::DomainGoal::*;
1337 mem::discriminant(self).hash_stable(hcx, hasher);
1339 Holds(wc) => wc.hash_stable(hcx, hasher),
1340 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1341 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1342 Normalize(projection) => projection.hash_stable(hcx, hasher),
1347 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1348 fn hash_stable<W: StableHasherResult>(&self,
1349 hcx: &mut StableHashingContext<'a>,
1350 hasher: &mut StableHasher<W>) {
1351 use traits::Goal::*;
1353 mem::discriminant(self).hash_stable(hcx, hasher);
1355 Implies(hypotheses, goal) => {
1356 hypotheses.hash_stable(hcx, hasher);
1357 goal.hash_stable(hcx, hasher);
1359 And(goal1, goal2) => {
1360 goal1.hash_stable(hcx, hasher);
1361 goal2.hash_stable(hcx, hasher);
1363 Not(goal) => goal.hash_stable(hcx, hasher),
1364 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1365 Quantified(quantifier, goal) => {
1366 quantifier.hash_stable(hcx, hasher);
1367 goal.hash_stable(hcx, hasher);
1374 impl_stable_hash_for!(
1375 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1380 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1381 fn hash_stable<W: StableHasherResult>(&self,
1382 hcx: &mut StableHashingContext<'a>,
1383 hasher: &mut StableHasher<W>) {
1384 use traits::Clause::*;
1386 mem::discriminant(self).hash_stable(hcx, hasher);
1388 Implies(clause) => clause.hash_stable(hcx, hasher),
1389 ForAll(clause) => clause.hash_stable(hcx, hasher),
1394 impl_stable_hash_for!(enum traits::QuantifierKind {