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>>
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::List<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::ScalarMaybeUndef {
400 impl_stable_hash_for!(struct mir::interpret::Pointer {
405 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
406 fn hash_stable<W: StableHasherResult>(
408 hcx: &mut StableHashingContext<'a>,
409 hasher: &mut StableHasher<W>,
411 ty::tls::with_opt(|tcx| {
412 trace!("hashing {:?}", *self);
413 let tcx = tcx.expect("can't hash AllocIds during hir lowering");
414 let alloc_kind = tcx.alloc_map.lock().get(*self).expect("no value for AllocId");
415 alloc_kind.hash_stable(hcx, hasher);
420 impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
421 for mir::interpret::AllocType<'gcx, M> {
422 fn hash_stable<W: StableHasherResult>(&self,
423 hcx: &mut StableHashingContext<'a>,
424 hasher: &mut StableHasher<W>) {
425 use mir::interpret::AllocType::*;
427 mem::discriminant(self).hash_stable(hcx, hasher);
430 Function(instance) => instance.hash_stable(hcx, hasher),
431 Static(def_id) => def_id.hash_stable(hcx, hasher),
432 Memory(ref mem) => mem.hash_stable(hcx, hasher),
437 impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
438 fn hash_stable<W: StableHasherResult>(
440 hcx: &mut StableHashingContext<'a>,
441 hasher: &mut StableHasher<W>,
443 self.bytes.hash_stable(hcx, hasher);
444 for reloc in self.relocations.iter() {
445 reloc.hash_stable(hcx, hasher);
447 self.undef_mask.hash_stable(hcx, hasher);
448 self.align.hash_stable(hcx, hasher);
449 self.runtime_mutability.hash_stable(hcx, hasher);
453 impl_stable_hash_for!(enum ::syntax::ast::Mutability {
459 impl<'a> HashStable<StableHashingContext<'a>>
460 for ::mir::interpret::Scalar {
461 fn hash_stable<W: StableHasherResult>(&self,
462 hcx: &mut StableHashingContext<'a>,
463 hasher: &mut StableHasher<W>) {
464 use mir::interpret::Scalar::*;
466 mem::discriminant(self).hash_stable(hcx, hasher);
468 Bits { bits, size } => {
469 bits.hash_stable(hcx, hasher);
470 size.hash_stable(hcx, hasher);
472 Ptr(ptr) => ptr.hash_stable(hcx, hasher),
477 impl_stable_hash_for!(struct ty::Const<'tcx> {
482 impl_stable_hash_for!(struct ::mir::interpret::ConstEvalErr<'tcx> {
488 impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
494 impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
495 impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
497 impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
502 impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
504 impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
505 for ::mir::interpret::EvalErrorKind<'gcx, O> {
506 fn hash_stable<W: StableHasherResult>(&self,
507 hcx: &mut StableHashingContext<'a>,
508 hasher: &mut StableHasher<W>) {
509 use mir::interpret::EvalErrorKind::*;
511 mem::discriminant(&self).hash_stable(hcx, hasher);
514 DanglingPointerDeref |
516 InvalidMemoryAccess |
517 InvalidFunctionPointer |
519 InvalidDiscriminant |
520 InvalidNullPointerUsage |
527 StackFrameLimitReached |
530 CalledClosureAsFunction |
531 VtableForArgumentlessMethod |
532 ModifiedConstantMemory |
535 ReallocateNonBasePtr |
536 DeallocateNonBasePtr |
539 ReadFromReturnPointer |
540 UnimplementedTraitSelection |
544 DerefFunctionPointer |
549 GeneratorResumedAfterReturn |
550 GeneratorResumedAfterPanic |
552 Panic { ref msg, ref file, line, col } => {
553 msg.hash_stable(hcx, hasher);
554 file.hash_stable(hcx, hasher);
555 line.hash_stable(hcx, hasher);
556 col.hash_stable(hcx, hasher);
558 ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
559 MachineError(ref err) => err.hash_stable(hcx, hasher),
560 FunctionPointerTyMismatch(a, b) => {
561 a.hash_stable(hcx, hasher);
562 b.hash_stable(hcx, hasher)
564 NoMirFor(ref s) => s.hash_stable(hcx, hasher),
565 UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
571 ptr.hash_stable(hcx, hasher);
572 access.hash_stable(hcx, hasher);
573 allocation_size.hash_stable(hcx, hasher)
575 InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
576 Unimplemented(ref s) => s.hash_stable(hcx, hasher),
577 BoundsCheck { ref len, ref index } => {
578 len.hash_stable(hcx, hasher);
579 index.hash_stable(hcx, hasher)
581 Intrinsic(ref s) => s.hash_stable(hcx, hasher),
582 InvalidChar(c) => c.hash_stable(hcx, hasher),
583 AbiViolation(ref s) => s.hash_stable(hcx, hasher),
584 AlignmentCheckFailed {
588 required.hash_stable(hcx, hasher);
589 has.hash_stable(hcx, hasher)
591 MemoryLockViolation {
598 ptr.hash_stable(hcx, hasher);
599 len.hash_stable(hcx, hasher);
600 frame.hash_stable(hcx, hasher);
601 access.hash_stable(hcx, hasher);
602 lock.hash_stable(hcx, hasher)
604 MemoryAcquireConflict {
610 ptr.hash_stable(hcx, hasher);
611 len.hash_stable(hcx, hasher);
612 kind.hash_stable(hcx, hasher);
613 lock.hash_stable(hcx, hasher)
615 InvalidMemoryLockRelease {
621 ptr.hash_stable(hcx, hasher);
622 len.hash_stable(hcx, hasher);
623 frame.hash_stable(hcx, hasher);
624 lock.hash_stable(hcx, hasher)
626 DeallocatedLockedMemory {
630 ptr.hash_stable(hcx, hasher);
631 lock.hash_stable(hcx, hasher)
633 ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
634 TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
635 ReallocatedWrongMemoryKind(ref a, ref b) => {
636 a.hash_stable(hcx, hasher);
637 b.hash_stable(hcx, hasher)
639 DeallocatedWrongMemoryKind(ref a, ref b) => {
640 a.hash_stable(hcx, hasher);
641 b.hash_stable(hcx, hasher)
643 IncorrectAllocationInformation(a, b, c, d) => {
644 a.hash_stable(hcx, hasher);
645 b.hash_stable(hcx, hasher);
646 c.hash_stable(hcx, hasher);
647 d.hash_stable(hcx, hasher)
649 Layout(lay) => lay.hash_stable(hcx, hasher),
650 HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
651 PathNotFound(ref v) => v.hash_stable(hcx, hasher),
652 Overflow(op) => op.hash_stable(hcx, hasher),
657 impl_stable_hash_for!(enum mir::interpret::Lock {
663 impl_stable_hash_for!(struct mir::interpret::DynamicLifetime {
668 impl_stable_hash_for!(enum mir::interpret::AccessKind {
673 impl_stable_hash_for!(enum ty::Variance {
680 impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
684 impl_stable_hash_for!(struct ty::Generics {
688 // Reverse map to each param's `index` field, from its `def_id`.
689 param_def_id_to_index -> _, // Don't hash this
691 has_late_bound_regions,
694 impl_stable_hash_for!(struct ty::GenericParamDef {
702 impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
703 fn hash_stable<W: StableHasherResult>(&self,
704 hcx: &mut StableHashingContext<'a>,
705 hasher: &mut StableHasher<W>) {
706 mem::discriminant(self).hash_stable(hcx, hasher);
708 ty::GenericParamDefKind::Lifetime => {}
709 ty::GenericParamDefKind::Type {
711 ref object_lifetime_default,
714 has_default.hash_stable(hcx, hasher);
715 object_lifetime_default.hash_stable(hcx, hasher);
716 synthetic.hash_stable(hcx, hasher);
722 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
723 for ::middle::resolve_lifetime::Set1<T>
724 where T: HashStable<StableHashingContext<'a>>
726 fn hash_stable<W: StableHasherResult>(&self,
727 hcx: &mut StableHashingContext<'a>,
728 hasher: &mut StableHasher<W>) {
729 use middle::resolve_lifetime::Set1;
731 mem::discriminant(self).hash_stable(hcx, hasher);
737 Set1::One(ref value) => {
738 value.hash_stable(hcx, hasher);
744 impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
749 impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region {
751 EarlyBound(index, decl, is_in_band),
752 LateBound(db_index, decl, is_in_band),
753 LateBoundAnon(db_index, anon_index),
754 Free(call_site_scope_data, decl)
757 impl_stable_hash_for!(enum ty::cast::CastKind {
771 impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
772 impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
774 impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
775 type KeyType = region::Scope;
778 fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope {
783 impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
785 first_statement_index
788 impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
792 impl_stable_hash_for!(struct ty::FreeRegion {
797 impl_stable_hash_for!(enum ty::BoundRegion {
799 BrNamed(def_id, name),
804 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
807 fn hash_stable<W: StableHasherResult>(&self,
808 hcx: &mut StableHashingContext<'a>,
809 hasher: &mut StableHasher<W>) {
812 mem::discriminant(self).hash_stable(hcx, hasher);
819 // Nothing more to hash.
822 int_ty.hash_stable(hcx, hasher);
825 uint_ty.hash_stable(hcx, hasher);
828 float_ty.hash_stable(hcx, hasher);
830 Adt(adt_def, substs) => {
831 adt_def.hash_stable(hcx, hasher);
832 substs.hash_stable(hcx, hasher);
834 Array(inner_ty, len) => {
835 inner_ty.hash_stable(hcx, hasher);
836 len.hash_stable(hcx, hasher);
839 inner_ty.hash_stable(hcx, hasher);
841 RawPtr(pointee_ty) => {
842 pointee_ty.hash_stable(hcx, hasher);
844 Ref(region, pointee_ty, mutbl) => {
845 region.hash_stable(hcx, hasher);
846 pointee_ty.hash_stable(hcx, hasher);
847 mutbl.hash_stable(hcx, hasher);
849 FnDef(def_id, substs) => {
850 def_id.hash_stable(hcx, hasher);
851 substs.hash_stable(hcx, hasher);
854 sig.hash_stable(hcx, hasher);
856 Dynamic(ref existential_predicates, region) => {
857 existential_predicates.hash_stable(hcx, hasher);
858 region.hash_stable(hcx, hasher);
860 Closure(def_id, closure_substs) => {
861 def_id.hash_stable(hcx, hasher);
862 closure_substs.hash_stable(hcx, hasher);
864 Generator(def_id, generator_substs, movability) => {
865 def_id.hash_stable(hcx, hasher);
866 generator_substs.hash_stable(hcx, hasher);
867 movability.hash_stable(hcx, hasher);
869 GeneratorWitness(types) => {
870 types.hash_stable(hcx, hasher)
872 Tuple(inner_tys) => {
873 inner_tys.hash_stable(hcx, hasher);
875 Projection(ref projection_ty) => {
876 projection_ty.hash_stable(hcx, hasher);
878 Anon(def_id, substs) => {
879 def_id.hash_stable(hcx, hasher);
880 substs.hash_stable(hcx, hasher);
883 param_ty.hash_stable(hcx, hasher);
886 def_id.hash_stable(hcx, hasher);
889 infer_ty.hash_stable(hcx, hasher);
895 impl_stable_hash_for!(enum ty::InferTy {
905 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
908 fn hash_stable<W: StableHasherResult>(&self,
909 _hcx: &mut StableHashingContext<'a>,
910 _hasher: &mut StableHasher<W>) {
911 // TyVid values are confined to an inference context and hence
912 // should not be hashed.
913 bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self)
917 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
920 fn hash_stable<W: StableHasherResult>(&self,
921 _hcx: &mut StableHashingContext<'a>,
922 _hasher: &mut StableHasher<W>) {
923 // IntVid values are confined to an inference context and hence
924 // should not be hashed.
925 bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self)
929 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
932 fn hash_stable<W: StableHasherResult>(&self,
933 _hcx: &mut StableHashingContext<'a>,
934 _hasher: &mut StableHasher<W>) {
935 // FloatVid values are confined to an inference context and hence
936 // should not be hashed.
937 bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self)
941 impl_stable_hash_for!(struct ty::ParamTy {
946 impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {
951 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
952 for ty::ExistentialPredicate<'gcx>
954 fn hash_stable<W: StableHasherResult>(&self,
955 hcx: &mut StableHashingContext<'a>,
956 hasher: &mut StableHasher<W>) {
957 mem::discriminant(self).hash_stable(hcx, hasher);
959 ty::ExistentialPredicate::Trait(ref trait_ref) => {
960 trait_ref.hash_stable(hcx, hasher);
962 ty::ExistentialPredicate::Projection(ref projection) => {
963 projection.hash_stable(hcx, hasher);
965 ty::ExistentialPredicate::AutoTrait(def_id) => {
966 def_id.hash_stable(hcx, hasher);
972 impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> {
977 impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
983 impl_stable_hash_for!(struct ty::Instance<'tcx> {
988 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
989 fn hash_stable<W: StableHasherResult>(&self,
990 hcx: &mut StableHashingContext<'a>,
991 hasher: &mut StableHasher<W>) {
992 mem::discriminant(self).hash_stable(hcx, hasher);
995 ty::InstanceDef::Item(def_id) => {
996 def_id.hash_stable(hcx, hasher);
998 ty::InstanceDef::Intrinsic(def_id) => {
999 def_id.hash_stable(hcx, hasher);
1001 ty::InstanceDef::FnPtrShim(def_id, ty) => {
1002 def_id.hash_stable(hcx, hasher);
1003 ty.hash_stable(hcx, hasher);
1005 ty::InstanceDef::Virtual(def_id, n) => {
1006 def_id.hash_stable(hcx, hasher);
1007 n.hash_stable(hcx, hasher);
1009 ty::InstanceDef::ClosureOnceShim { call_once } => {
1010 call_once.hash_stable(hcx, hasher);
1012 ty::InstanceDef::DropGlue(def_id, ty) => {
1013 def_id.hash_stable(hcx, hasher);
1014 ty.hash_stable(hcx, hasher);
1016 ty::InstanceDef::CloneShim(def_id, ty) => {
1017 def_id.hash_stable(hcx, hasher);
1018 ty.hash_stable(hcx, hasher);
1024 impl_stable_hash_for!(struct ty::TraitDef {
1025 // We already have the def_path_hash below, no need to hash it twice
1033 impl_stable_hash_for!(struct ty::Destructor {
1037 impl_stable_hash_for!(struct ty::CrateVariancesMap {
1039 // This is just an irrelevant helper value.
1040 empty_variance -> _,
1043 impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
1045 // This is just an irrelevant helper value.
1046 empty_predicate -> _,
1049 impl_stable_hash_for!(struct ty::AssociatedItem {
1051 ident -> (ident.name),
1056 method_has_self_argument
1059 impl_stable_hash_for!(enum ty::AssociatedKind {
1066 impl_stable_hash_for!(enum ty::AssociatedItemContainer {
1067 TraitContainer(def_id),
1068 ImplContainer(def_id)
1072 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
1073 for ty::steal::Steal<T>
1074 where T: HashStable<StableHashingContext<'a>>
1076 fn hash_stable<W: StableHasherResult>(&self,
1077 hcx: &mut StableHashingContext<'a>,
1078 hasher: &mut StableHasher<W>) {
1079 self.borrow().hash_stable(hcx, hasher);
1083 impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
1088 impl_stable_hash_for!(enum traits::Reveal {
1093 impl_stable_hash_for!(enum ::middle::privacy::AccessLevel {
1099 impl<'a> HashStable<StableHashingContext<'a>>
1100 for ::middle::privacy::AccessLevels {
1101 fn hash_stable<W: StableHasherResult>(&self,
1102 hcx: &mut StableHashingContext<'a>,
1103 hasher: &mut StableHasher<W>) {
1104 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1105 let ::middle::privacy::AccessLevels {
1109 map.hash_stable(hcx, hasher);
1114 impl_stable_hash_for!(struct ty::CrateInherentImpls {
1118 impl_stable_hash_for!(enum ::session::CompileIncomplete {
1120 Errored(error_reported)
1123 impl_stable_hash_for!(struct ::util::common::ErrorReported {});
1125 impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet {
1129 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1130 for traits::Vtable<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1131 fn hash_stable<W: StableHasherResult>(&self,
1132 hcx: &mut StableHashingContext<'a>,
1133 hasher: &mut StableHasher<W>) {
1134 use traits::Vtable::*;
1136 mem::discriminant(self).hash_stable(hcx, hasher);
1139 &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher),
1140 &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher),
1141 &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher),
1142 &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher),
1143 &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher),
1144 &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher),
1145 &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher),
1146 &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher),
1151 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1152 for traits::VtableImplData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1153 fn hash_stable<W: StableHasherResult>(&self,
1154 hcx: &mut StableHashingContext<'a>,
1155 hasher: &mut StableHasher<W>) {
1156 let traits::VtableImplData {
1161 impl_def_id.hash_stable(hcx, hasher);
1162 substs.hash_stable(hcx, hasher);
1163 nested.hash_stable(hcx, hasher);
1167 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1168 for traits::VtableAutoImplData<N> where N: HashStable<StableHashingContext<'a>> {
1169 fn hash_stable<W: StableHasherResult>(&self,
1170 hcx: &mut StableHashingContext<'a>,
1171 hasher: &mut StableHasher<W>) {
1172 let traits::VtableAutoImplData {
1176 trait_def_id.hash_stable(hcx, hasher);
1177 nested.hash_stable(hcx, hasher);
1181 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1182 for traits::VtableObjectData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1183 fn hash_stable<W: StableHasherResult>(&self,
1184 hcx: &mut StableHashingContext<'a>,
1185 hasher: &mut StableHasher<W>) {
1186 let traits::VtableObjectData {
1191 upcast_trait_ref.hash_stable(hcx, hasher);
1192 vtable_base.hash_stable(hcx, hasher);
1193 nested.hash_stable(hcx, hasher);
1197 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1198 for traits::VtableBuiltinData<N> where N: HashStable<StableHashingContext<'a>> {
1199 fn hash_stable<W: StableHasherResult>(&self,
1200 hcx: &mut StableHashingContext<'a>,
1201 hasher: &mut StableHasher<W>) {
1202 let traits::VtableBuiltinData {
1205 nested.hash_stable(hcx, hasher);
1209 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1210 for traits::VtableClosureData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1211 fn hash_stable<W: StableHasherResult>(&self,
1212 hcx: &mut StableHashingContext<'a>,
1213 hasher: &mut StableHasher<W>) {
1214 let traits::VtableClosureData {
1219 closure_def_id.hash_stable(hcx, hasher);
1220 substs.hash_stable(hcx, hasher);
1221 nested.hash_stable(hcx, hasher);
1225 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1226 for traits::VtableFnPointerData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1227 fn hash_stable<W: StableHasherResult>(&self,
1228 hcx: &mut StableHashingContext<'a>,
1229 hasher: &mut StableHasher<W>) {
1230 let traits::VtableFnPointerData {
1234 fn_ty.hash_stable(hcx, hasher);
1235 nested.hash_stable(hcx, hasher);
1239 impl<'a, 'gcx, N> HashStable<StableHashingContext<'a>>
1240 for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContext<'a>> {
1241 fn hash_stable<W: StableHasherResult>(&self,
1242 hcx: &mut StableHashingContext<'a>,
1243 hasher: &mut StableHasher<W>) {
1244 let traits::VtableGeneratorData {
1249 generator_def_id.hash_stable(hcx, hasher);
1250 substs.hash_stable(hcx, hasher);
1251 nested.hash_stable(hcx, hasher);
1255 impl_stable_hash_for!(
1256 impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
1261 impl_stable_hash_for!(
1262 impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1267 impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo {
1271 impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
1276 impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
1282 impl_stable_hash_for!(
1283 impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
1284 var_values, region_constraints, certainty, value
1288 impl_stable_hash_for!(enum infer::canonical::Certainty {
1292 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClause<'tcx> {
1293 fn hash_stable<W: StableHasherResult>(&self,
1294 hcx: &mut StableHashingContext<'a>,
1295 hasher: &mut StableHasher<W>) {
1296 use traits::WhereClause::*;
1298 mem::discriminant(self).hash_stable(hcx, hasher);
1300 Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1301 ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
1302 TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher),
1303 RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher),
1308 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WellFormed<'tcx> {
1309 fn hash_stable<W: StableHasherResult>(&self,
1310 hcx: &mut StableHashingContext<'a>,
1311 hasher: &mut StableHasher<W>) {
1312 use traits::WellFormed::*;
1314 mem::discriminant(self).hash_stable(hcx, hasher);
1316 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1317 Ty(ty) => ty.hash_stable(hcx, hasher),
1322 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::FromEnv<'tcx> {
1323 fn hash_stable<W: StableHasherResult>(&self,
1324 hcx: &mut StableHashingContext<'a>,
1325 hasher: &mut StableHasher<W>) {
1326 use traits::FromEnv::*;
1328 mem::discriminant(self).hash_stable(hcx, hasher);
1330 Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1331 Ty(ty) => ty.hash_stable(hcx, hasher),
1336 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx> {
1337 fn hash_stable<W: StableHasherResult>(&self,
1338 hcx: &mut StableHashingContext<'a>,
1339 hasher: &mut StableHasher<W>) {
1340 use traits::DomainGoal::*;
1342 mem::discriminant(self).hash_stable(hcx, hasher);
1344 Holds(wc) => wc.hash_stable(hcx, hasher),
1345 WellFormed(wf) => wf.hash_stable(hcx, hasher),
1346 FromEnv(from_env) => from_env.hash_stable(hcx, hasher),
1347 Normalize(projection) => projection.hash_stable(hcx, hasher),
1352 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1353 fn hash_stable<W: StableHasherResult>(&self,
1354 hcx: &mut StableHashingContext<'a>,
1355 hasher: &mut StableHasher<W>) {
1356 use traits::Goal::*;
1358 mem::discriminant(self).hash_stable(hcx, hasher);
1360 Implies(hypotheses, goal) => {
1361 hypotheses.hash_stable(hcx, hasher);
1362 goal.hash_stable(hcx, hasher);
1364 And(goal1, goal2) => {
1365 goal1.hash_stable(hcx, hasher);
1366 goal2.hash_stable(hcx, hasher);
1368 Not(goal) => goal.hash_stable(hcx, hasher),
1369 DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1370 Quantified(quantifier, goal) => {
1371 quantifier.hash_stable(hcx, hasher);
1372 goal.hash_stable(hcx, hasher);
1379 impl_stable_hash_for!(
1380 impl<'tcx> for struct traits::ProgramClause<'tcx> {
1385 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
1386 fn hash_stable<W: StableHasherResult>(&self,
1387 hcx: &mut StableHashingContext<'a>,
1388 hasher: &mut StableHasher<W>) {
1389 use traits::Clause::*;
1391 mem::discriminant(self).hash_stable(hcx, hasher);
1393 Implies(clause) => clause.hash_stable(hcx, hasher),
1394 ForAll(clause) => clause.hash_stable(hcx, hasher),
1399 impl_stable_hash_for!(enum traits::QuantifierKind {