]>
Commit | Line | Data |
---|---|---|
cc61c64b XL |
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. | |
4 | // | |
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. | |
10 | ||
11 | //! This module contains `HashStable` implementations for various data types | |
12 | //! from rustc::ty in no particular order. | |
13 | ||
14 | use ich::{self, StableHashingContext, NodeIdHashingMode}; | |
15 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher, | |
16 | StableHasherResult}; | |
17 | use std::hash as std_hash; | |
18 | use std::mem; | |
19 | use syntax_pos::symbol::InternedString; | |
20 | use ty; | |
21 | ||
cc61c64b XL |
22 | impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T> |
23 | where T: HashStable<StableHashingContext<'a, 'tcx>> { | |
24 | fn hash_stable<W: StableHasherResult>(&self, | |
25 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
26 | hasher: &mut StableHasher<W>) { | |
27 | (&self[..]).hash_stable(hcx, hasher); | |
28 | } | |
29 | } | |
30 | ||
31 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::subst::Kind<'tcx> { | |
32 | fn hash_stable<W: StableHasherResult>(&self, | |
33 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
34 | hasher: &mut StableHasher<W>) { | |
35 | self.as_type().hash_stable(hcx, hasher); | |
36 | self.as_region().hash_stable(hcx, hasher); | |
37 | } | |
38 | } | |
39 | ||
7cac9316 | 40 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionKind { |
cc61c64b XL |
41 | fn hash_stable<W: StableHasherResult>(&self, |
42 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
43 | hasher: &mut StableHasher<W>) { | |
44 | mem::discriminant(self).hash_stable(hcx, hasher); | |
45 | match *self { | |
46 | ty::ReErased | | |
47 | ty::ReStatic | | |
48 | ty::ReEmpty => { | |
49 | // No variant fields to hash for these ... | |
50 | } | |
51 | ty::ReLateBound(db, ty::BrAnon(i)) => { | |
52 | db.depth.hash_stable(hcx, hasher); | |
53 | i.hash_stable(hcx, hasher); | |
54 | } | |
7cac9316 XL |
55 | ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => { |
56 | def_id.hash_stable(hcx, hasher); | |
cc61c64b XL |
57 | index.hash_stable(hcx, hasher); |
58 | name.hash_stable(hcx, hasher); | |
59 | } | |
60 | ty::ReScope(code_extent) => { | |
61 | code_extent.hash_stable(hcx, hasher); | |
62 | } | |
63 | ty::ReFree(ref free_region) => { | |
64 | free_region.hash_stable(hcx, hasher); | |
65 | } | |
66 | ty::ReLateBound(..) | | |
67 | ty::ReVar(..) | | |
68 | ty::ReSkolemized(..) => { | |
69 | bug!("TypeIdHasher: unexpected region {:?}", *self) | |
70 | } | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::AutoBorrow<'tcx> { | |
76 | fn hash_stable<W: StableHasherResult>(&self, | |
77 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
78 | hasher: &mut StableHasher<W>) { | |
79 | mem::discriminant(self).hash_stable(hcx, hasher); | |
80 | match *self { | |
81 | ty::adjustment::AutoBorrow::Ref(ref region, mutability) => { | |
82 | region.hash_stable(hcx, hasher); | |
83 | mutability.hash_stable(hcx, hasher); | |
84 | } | |
85 | ty::adjustment::AutoBorrow::RawPtr(mutability) => { | |
86 | mutability.hash_stable(hcx, hasher); | |
87 | } | |
88 | } | |
89 | } | |
90 | } | |
91 | ||
92 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Adjust<'tcx> { | |
93 | fn hash_stable<W: StableHasherResult>(&self, | |
94 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
95 | hasher: &mut StableHasher<W>) { | |
96 | mem::discriminant(self).hash_stable(hcx, hasher); | |
97 | match *self { | |
98 | ty::adjustment::Adjust::NeverToAny | | |
99 | ty::adjustment::Adjust::ReifyFnPointer | | |
100 | ty::adjustment::Adjust::UnsafeFnPointer | | |
101 | ty::adjustment::Adjust::ClosureFnPointer | | |
7cac9316 XL |
102 | ty::adjustment::Adjust::MutToConstPointer | |
103 | ty::adjustment::Adjust::Unsize => {} | |
104 | ty::adjustment::Adjust::Deref(ref overloaded) => { | |
105 | overloaded.hash_stable(hcx, hasher); | |
106 | } | |
107 | ty::adjustment::Adjust::Borrow(ref autoref) => { | |
cc61c64b | 108 | autoref.hash_stable(hcx, hasher); |
cc61c64b XL |
109 | } |
110 | } | |
111 | } | |
112 | } | |
113 | ||
114 | impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target }); | |
7cac9316 | 115 | impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl }); |
cc61c64b XL |
116 | impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id }); |
117 | impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region }); | |
118 | ||
119 | impl_stable_hash_for!(enum ty::BorrowKind { | |
120 | ImmBorrow, | |
121 | UniqueImmBorrow, | |
122 | MutBorrow | |
123 | }); | |
124 | ||
125 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::UpvarCapture<'tcx> { | |
126 | fn hash_stable<W: StableHasherResult>(&self, | |
127 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
128 | hasher: &mut StableHasher<W>) { | |
129 | mem::discriminant(self).hash_stable(hcx, hasher); | |
130 | match *self { | |
131 | ty::UpvarCapture::ByValue => {} | |
132 | ty::UpvarCapture::ByRef(ref up_var_borrow) => { | |
133 | up_var_borrow.hash_stable(hcx, hasher); | |
134 | } | |
135 | } | |
136 | } | |
137 | } | |
138 | ||
139 | impl_stable_hash_for!(struct ty::FnSig<'tcx> { | |
140 | inputs_and_output, | |
141 | variadic, | |
142 | unsafety, | |
143 | abi | |
144 | }); | |
145 | ||
146 | impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for ty::Binder<T> | |
147 | where T: HashStable<StableHashingContext<'a, 'tcx>> + ty::fold::TypeFoldable<'tcx> | |
148 | { | |
149 | fn hash_stable<W: StableHasherResult>(&self, | |
150 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
151 | hasher: &mut StableHasher<W>) { | |
152 | hcx.tcx().anonymize_late_bound_regions(self).0.hash_stable(hcx, hasher); | |
153 | } | |
154 | } | |
155 | ||
156 | impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce }); | |
157 | ||
158 | impl_stable_hash_for!(enum ty::Visibility { | |
159 | Public, | |
160 | Restricted(def_id), | |
161 | Invisible | |
162 | }); | |
163 | ||
164 | impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs }); | |
165 | impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref }); | |
166 | impl_stable_hash_for!(tuple_struct ty::EquatePredicate<'tcx> { t1, t2 }); | |
167 | impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b }); | |
168 | ||
169 | impl<'a, 'tcx, A, B> HashStable<StableHashingContext<'a, 'tcx>> for ty::OutlivesPredicate<A, B> | |
170 | where A: HashStable<StableHashingContext<'a, 'tcx>>, | |
171 | B: HashStable<StableHashingContext<'a, 'tcx>>, | |
172 | { | |
173 | fn hash_stable<W: StableHasherResult>(&self, | |
174 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
175 | hasher: &mut StableHasher<W>) { | |
176 | let ty::OutlivesPredicate(ref a, ref b) = *self; | |
177 | a.hash_stable(hcx, hasher); | |
178 | b.hash_stable(hcx, hasher); | |
179 | } | |
180 | } | |
181 | ||
182 | impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty }); | |
7cac9316 | 183 | impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { trait_ref, item_def_id }); |
cc61c64b XL |
184 | |
185 | ||
186 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Predicate<'tcx> { | |
187 | fn hash_stable<W: StableHasherResult>(&self, | |
188 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
189 | hasher: &mut StableHasher<W>) { | |
190 | mem::discriminant(self).hash_stable(hcx, hasher); | |
191 | match *self { | |
192 | ty::Predicate::Trait(ref pred) => { | |
193 | pred.hash_stable(hcx, hasher); | |
194 | } | |
195 | ty::Predicate::Equate(ref pred) => { | |
196 | pred.hash_stable(hcx, hasher); | |
197 | } | |
198 | ty::Predicate::Subtype(ref pred) => { | |
199 | pred.hash_stable(hcx, hasher); | |
200 | } | |
201 | ty::Predicate::RegionOutlives(ref pred) => { | |
202 | pred.hash_stable(hcx, hasher); | |
203 | } | |
204 | ty::Predicate::TypeOutlives(ref pred) => { | |
205 | pred.hash_stable(hcx, hasher); | |
206 | } | |
207 | ty::Predicate::Projection(ref pred) => { | |
208 | pred.hash_stable(hcx, hasher); | |
209 | } | |
210 | ty::Predicate::WellFormed(ty) => { | |
211 | ty.hash_stable(hcx, hasher); | |
212 | } | |
213 | ty::Predicate::ObjectSafe(def_id) => { | |
214 | def_id.hash_stable(hcx, hasher); | |
215 | } | |
216 | ty::Predicate::ClosureKind(def_id, closure_kind) => { | |
217 | def_id.hash_stable(hcx, hasher); | |
218 | closure_kind.hash_stable(hcx, hasher); | |
219 | } | |
220 | } | |
221 | } | |
222 | } | |
223 | ||
224 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::AdtFlags { | |
225 | fn hash_stable<W: StableHasherResult>(&self, | |
226 | _: &mut StableHashingContext<'a, 'tcx>, | |
227 | hasher: &mut StableHasher<W>) { | |
228 | std_hash::Hash::hash(self, hasher); | |
229 | } | |
230 | } | |
231 | ||
232 | impl_stable_hash_for!(struct ty::VariantDef { | |
233 | did, | |
234 | name, | |
235 | discr, | |
236 | fields, | |
237 | ctor_kind | |
238 | }); | |
239 | ||
240 | impl_stable_hash_for!(enum ty::VariantDiscr { | |
241 | Explicit(def_id), | |
242 | Relative(distance) | |
243 | }); | |
244 | ||
245 | impl_stable_hash_for!(struct ty::FieldDef { | |
246 | did, | |
247 | name, | |
248 | vis | |
249 | }); | |
250 | ||
251 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> | |
252 | for ::middle::const_val::ConstVal<'tcx> { | |
253 | fn hash_stable<W: StableHasherResult>(&self, | |
254 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
255 | hasher: &mut StableHasher<W>) { | |
256 | use middle::const_val::ConstVal; | |
257 | ||
258 | mem::discriminant(self).hash_stable(hcx, hasher); | |
259 | ||
260 | match *self { | |
261 | ConstVal::Float(ref value) => { | |
262 | value.hash_stable(hcx, hasher); | |
263 | } | |
264 | ConstVal::Integral(ref value) => { | |
265 | value.hash_stable(hcx, hasher); | |
266 | } | |
267 | ConstVal::Str(ref value) => { | |
268 | value.hash_stable(hcx, hasher); | |
269 | } | |
270 | ConstVal::ByteStr(ref value) => { | |
271 | value.hash_stable(hcx, hasher); | |
272 | } | |
273 | ConstVal::Bool(value) => { | |
274 | value.hash_stable(hcx, hasher); | |
275 | } | |
276 | ConstVal::Char(value) => { | |
277 | value.hash_stable(hcx, hasher); | |
278 | } | |
279 | ConstVal::Variant(def_id) => { | |
280 | def_id.hash_stable(hcx, hasher); | |
281 | } | |
282 | ConstVal::Function(def_id, substs) => { | |
283 | def_id.hash_stable(hcx, hasher); | |
284 | substs.hash_stable(hcx, hasher); | |
285 | } | |
286 | ConstVal::Struct(ref name_value_map) => { | |
287 | let mut values: Vec<(InternedString, &ConstVal)> = | |
288 | name_value_map.iter() | |
289 | .map(|(name, val)| (name.as_str(), val)) | |
290 | .collect(); | |
291 | ||
292 | values.sort_unstable_by_key(|&(ref name, _)| name.clone()); | |
293 | values.hash_stable(hcx, hasher); | |
294 | } | |
295 | ConstVal::Tuple(ref value) => { | |
296 | value.hash_stable(hcx, hasher); | |
297 | } | |
298 | ConstVal::Array(ref value) => { | |
299 | value.hash_stable(hcx, hasher); | |
300 | } | |
301 | ConstVal::Repeat(ref value, times) => { | |
302 | value.hash_stable(hcx, hasher); | |
303 | times.hash_stable(hcx, hasher); | |
304 | } | |
305 | } | |
306 | } | |
307 | } | |
308 | ||
309 | impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs }); | |
310 | ||
311 | impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> { | |
312 | parent, | |
313 | predicates | |
314 | }); | |
315 | ||
316 | impl_stable_hash_for!(enum ty::Variance { | |
317 | Covariant, | |
318 | Invariant, | |
319 | Contravariant, | |
320 | Bivariant | |
321 | }); | |
322 | ||
323 | impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized { | |
324 | Struct(index) | |
325 | }); | |
326 | ||
327 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Generics { | |
328 | fn hash_stable<W: StableHasherResult>(&self, | |
329 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
330 | hasher: &mut StableHasher<W>) { | |
331 | let ty::Generics { | |
332 | parent, | |
333 | parent_regions, | |
334 | parent_types, | |
335 | ref regions, | |
336 | ref types, | |
337 | ||
338 | // Reverse map to each `TypeParameterDef`'s `index` field, from | |
339 | // `def_id.index` (`def_id.krate` is the same as the item's). | |
340 | type_param_to_index: _, // Don't hash this | |
341 | has_self, | |
342 | } = *self; | |
343 | ||
344 | parent.hash_stable(hcx, hasher); | |
345 | parent_regions.hash_stable(hcx, hasher); | |
346 | parent_types.hash_stable(hcx, hasher); | |
347 | regions.hash_stable(hcx, hasher); | |
348 | types.hash_stable(hcx, hasher); | |
349 | has_self.hash_stable(hcx, hasher); | |
350 | } | |
351 | } | |
352 | ||
353 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionParameterDef { | |
354 | fn hash_stable<W: StableHasherResult>(&self, | |
355 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
356 | hasher: &mut StableHasher<W>) { | |
357 | let ty::RegionParameterDef { | |
358 | name, | |
359 | def_id, | |
360 | index, | |
361 | issue_32330: _, | |
362 | pure_wrt_drop | |
363 | } = *self; | |
364 | ||
365 | name.hash_stable(hcx, hasher); | |
366 | def_id.hash_stable(hcx, hasher); | |
367 | index.hash_stable(hcx, hasher); | |
368 | pure_wrt_drop.hash_stable(hcx, hasher); | |
369 | } | |
370 | } | |
371 | ||
372 | impl_stable_hash_for!(struct ty::TypeParameterDef { | |
373 | name, | |
374 | def_id, | |
375 | index, | |
376 | has_default, | |
377 | object_lifetime_default, | |
378 | pure_wrt_drop | |
379 | }); | |
380 | ||
381 | ||
382 | impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> | |
383 | for ::middle::resolve_lifetime::Set1<T> | |
384 | where T: HashStable<StableHashingContext<'a, 'tcx>> | |
385 | { | |
386 | fn hash_stable<W: StableHasherResult>(&self, | |
387 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
388 | hasher: &mut StableHasher<W>) { | |
389 | use middle::resolve_lifetime::Set1; | |
390 | ||
391 | mem::discriminant(self).hash_stable(hcx, hasher); | |
392 | match *self { | |
393 | Set1::Empty | | |
394 | Set1::Many => { | |
395 | // Nothing to do. | |
396 | } | |
397 | Set1::One(ref value) => { | |
398 | value.hash_stable(hcx, hasher); | |
399 | } | |
400 | } | |
401 | } | |
402 | } | |
403 | ||
404 | impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region { | |
405 | Static, | |
406 | EarlyBound(index, decl), | |
407 | LateBound(db_index, decl), | |
408 | LateBoundAnon(db_index, anon_index), | |
409 | Free(call_site_scope_data, decl) | |
410 | }); | |
411 | ||
cc61c64b XL |
412 | impl_stable_hash_for!(struct ty::DebruijnIndex { |
413 | depth | |
414 | }); | |
415 | ||
416 | impl_stable_hash_for!(enum ty::cast::CastKind { | |
417 | CoercionCast, | |
418 | PtrPtrCast, | |
419 | PtrAddrCast, | |
420 | AddrPtrCast, | |
421 | NumericCast, | |
422 | EnumCast, | |
423 | PrimIntCast, | |
424 | U8CharCast, | |
425 | ArrayPtrCast, | |
426 | FnPtrPtrCast, | |
427 | FnPtrAddrCast | |
428 | }); | |
429 | ||
430 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtent | |
431 | { | |
432 | fn hash_stable<W: StableHasherResult>(&self, | |
433 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
434 | hasher: &mut StableHasher<W>) { | |
7cac9316 | 435 | use middle::region::CodeExtent; |
cc61c64b XL |
436 | |
437 | mem::discriminant(self).hash_stable(hcx, hasher); | |
438 | match *self { | |
7cac9316 XL |
439 | CodeExtent::Misc(node_id) | |
440 | CodeExtent::DestructionScope(node_id) => { | |
cc61c64b XL |
441 | node_id.hash_stable(hcx, hasher); |
442 | } | |
7cac9316 XL |
443 | CodeExtent::CallSiteScope(body_id) | |
444 | CodeExtent::ParameterScope(body_id) => { | |
cc61c64b XL |
445 | body_id.hash_stable(hcx, hasher); |
446 | } | |
7cac9316 | 447 | CodeExtent::Remainder(block_remainder) => { |
cc61c64b XL |
448 | block_remainder.hash_stable(hcx, hasher); |
449 | } | |
450 | } | |
451 | } | |
452 | } | |
453 | ||
454 | impl_stable_hash_for!(struct ::middle::region::BlockRemainder { | |
455 | block, | |
456 | first_statement_index | |
457 | }); | |
458 | ||
459 | impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo { | |
460 | custom_kind | |
461 | }); | |
462 | ||
463 | impl_stable_hash_for!(struct ty::FreeRegion { | |
464 | scope, | |
465 | bound_region | |
466 | }); | |
467 | ||
468 | impl_stable_hash_for!(enum ty::BoundRegion { | |
469 | BrAnon(index), | |
470 | BrNamed(def_id, name), | |
471 | BrFresh(index), | |
472 | BrEnv | |
473 | }); | |
474 | ||
475 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeVariants<'tcx> | |
476 | { | |
477 | fn hash_stable<W: StableHasherResult>(&self, | |
478 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
479 | hasher: &mut StableHasher<W>) { | |
480 | use ty::TypeVariants::*; | |
481 | ||
482 | mem::discriminant(self).hash_stable(hcx, hasher); | |
483 | match *self { | |
484 | TyBool | | |
485 | TyChar | | |
486 | TyStr | | |
487 | TyNever => { | |
488 | // Nothing more to hash. | |
489 | } | |
490 | TyInt(int_ty) => { | |
491 | int_ty.hash_stable(hcx, hasher); | |
492 | } | |
493 | TyUint(uint_ty) => { | |
494 | uint_ty.hash_stable(hcx, hasher); | |
495 | } | |
496 | TyFloat(float_ty) => { | |
497 | float_ty.hash_stable(hcx, hasher); | |
498 | } | |
499 | TyAdt(adt_def, substs) => { | |
500 | adt_def.hash_stable(hcx, hasher); | |
501 | substs.hash_stable(hcx, hasher); | |
502 | } | |
503 | TyArray(inner_ty, len) => { | |
504 | inner_ty.hash_stable(hcx, hasher); | |
505 | len.hash_stable(hcx, hasher); | |
506 | } | |
507 | TySlice(inner_ty) => { | |
508 | inner_ty.hash_stable(hcx, hasher); | |
509 | } | |
510 | TyRawPtr(pointee_ty) => { | |
511 | pointee_ty.hash_stable(hcx, hasher); | |
512 | } | |
513 | TyRef(region, pointee_ty) => { | |
514 | region.hash_stable(hcx, hasher); | |
515 | pointee_ty.hash_stable(hcx, hasher); | |
516 | } | |
517 | TyFnDef(def_id, substs, ref sig) => { | |
518 | def_id.hash_stable(hcx, hasher); | |
519 | substs.hash_stable(hcx, hasher); | |
520 | sig.hash_stable(hcx, hasher); | |
521 | } | |
522 | TyFnPtr(ref sig) => { | |
523 | sig.hash_stable(hcx, hasher); | |
524 | } | |
525 | TyDynamic(ref existential_predicates, region) => { | |
526 | existential_predicates.hash_stable(hcx, hasher); | |
527 | region.hash_stable(hcx, hasher); | |
528 | } | |
529 | TyClosure(def_id, closure_substs) => { | |
530 | def_id.hash_stable(hcx, hasher); | |
531 | closure_substs.hash_stable(hcx, hasher); | |
532 | } | |
533 | TyTuple(inner_tys, from_diverging_type_var) => { | |
534 | inner_tys.hash_stable(hcx, hasher); | |
535 | from_diverging_type_var.hash_stable(hcx, hasher); | |
536 | } | |
537 | TyProjection(ref projection_ty) => { | |
538 | projection_ty.hash_stable(hcx, hasher); | |
539 | } | |
540 | TyAnon(def_id, substs) => { | |
541 | def_id.hash_stable(hcx, hasher); | |
542 | substs.hash_stable(hcx, hasher); | |
543 | } | |
544 | TyParam(param_ty) => { | |
545 | param_ty.hash_stable(hcx, hasher); | |
546 | } | |
547 | ||
548 | TyError | | |
549 | TyInfer(..) => { | |
550 | bug!("ty::TypeVariants::hash_stable() - Unexpected variant.") | |
551 | } | |
552 | } | |
553 | } | |
554 | } | |
555 | ||
556 | impl_stable_hash_for!(struct ty::ParamTy { | |
557 | idx, | |
558 | name | |
559 | }); | |
560 | ||
561 | impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> { | |
562 | ty, | |
563 | mutbl | |
564 | }); | |
565 | ||
566 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::ExistentialPredicate<'tcx> | |
567 | { | |
568 | fn hash_stable<W: StableHasherResult>(&self, | |
569 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
570 | hasher: &mut StableHasher<W>) { | |
571 | mem::discriminant(self).hash_stable(hcx, hasher); | |
572 | match *self { | |
573 | ty::ExistentialPredicate::Trait(ref trait_ref) => { | |
574 | trait_ref.hash_stable(hcx, hasher); | |
575 | } | |
576 | ty::ExistentialPredicate::Projection(ref projection) => { | |
577 | projection.hash_stable(hcx, hasher); | |
578 | } | |
579 | ty::ExistentialPredicate::AutoTrait(def_id) => { | |
580 | def_id.hash_stable(hcx, hasher); | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
586 | impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> { | |
587 | def_id, | |
588 | substs | |
589 | }); | |
590 | ||
591 | impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> { | |
592 | trait_ref, | |
593 | item_name, | |
594 | ty | |
595 | }); | |
596 | ||
597 | ||
598 | impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'tcx> { | |
599 | fn hash_stable<W: StableHasherResult>(&self, | |
600 | hcx: &mut StableHashingContext<'a, 'tcx>, | |
601 | hasher: &mut StableHasher<W>) { | |
602 | let ty::TypeckTables { | |
7cac9316 | 603 | ref type_dependent_defs, |
cc61c64b | 604 | ref node_types, |
7cac9316 | 605 | ref node_substs, |
cc61c64b | 606 | ref adjustments, |
cc61c64b XL |
607 | ref upvar_capture_map, |
608 | ref closure_tys, | |
609 | ref closure_kinds, | |
610 | ref liberated_fn_sigs, | |
611 | ref fru_field_types, | |
612 | ||
613 | ref cast_kinds, | |
614 | ||
615 | // FIXME(#41184): This is still ignored at the moment. | |
616 | lints: _, | |
617 | ref used_trait_imports, | |
618 | tainted_by_errors, | |
619 | ref free_region_map, | |
620 | } = *self; | |
621 | ||
622 | hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { | |
7cac9316 | 623 | ich::hash_stable_nodemap(hcx, hasher, type_dependent_defs); |
cc61c64b | 624 | ich::hash_stable_nodemap(hcx, hasher, node_types); |
7cac9316 | 625 | ich::hash_stable_nodemap(hcx, hasher, node_substs); |
cc61c64b | 626 | ich::hash_stable_nodemap(hcx, hasher, adjustments); |
cc61c64b XL |
627 | ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| { |
628 | let ty::UpvarId { | |
629 | var_id, | |
630 | closure_expr_id | |
631 | } = *up_var_id; | |
632 | ||
633 | let var_def_id = hcx.tcx().hir.local_def_id(var_id); | |
634 | let closure_def_id = hcx.tcx().hir.local_def_id(closure_expr_id); | |
635 | (hcx.def_path_hash(var_def_id), hcx.def_path_hash(closure_def_id)) | |
636 | }); | |
637 | ||
638 | ich::hash_stable_nodemap(hcx, hasher, closure_tys); | |
639 | ich::hash_stable_nodemap(hcx, hasher, closure_kinds); | |
640 | ich::hash_stable_nodemap(hcx, hasher, liberated_fn_sigs); | |
641 | ich::hash_stable_nodemap(hcx, hasher, fru_field_types); | |
642 | ich::hash_stable_nodemap(hcx, hasher, cast_kinds); | |
643 | ||
644 | ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| { | |
645 | hcx.def_path_hash(*def_id) | |
646 | }); | |
647 | ||
648 | tainted_by_errors.hash_stable(hcx, hasher); | |
649 | free_region_map.hash_stable(hcx, hasher); | |
650 | }) | |
651 | } | |
652 | } |