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 MIR data
12 //! types in no particular order.
14 use ich::StableHashingContext;
16 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
20 impl_stable_hash_for!(struct mir::GeneratorLayout<'tcx> { fields });
21 impl_stable_hash_for!(struct mir::SourceInfo { span, scope });
22 impl_stable_hash_for!(enum mir::Mutability { Mut, Not });
23 impl_stable_hash_for!(enum mir::LocalKind { Var, Temp, Arg, ReturnPointer });
24 impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
35 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability });
36 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
37 impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
38 impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
40 impl<'a> HashStable<StableHashingContext<'a>>
43 fn hash_stable<W: StableHasherResult>(&self,
44 hcx: &mut StableHashingContext<'a>,
45 hasher: &mut StableHasher<W>) {
46 mem::discriminant(self).hash_stable(hcx, hasher);
49 mir::BorrowKind::Shared |
50 mir::BorrowKind::Shallow |
51 mir::BorrowKind::Unique => {}
52 mir::BorrowKind::Mut { allow_two_phase_borrow } => {
53 allow_two_phase_borrow.hash_stable(hcx, hasher);
60 impl<'a> HashStable<StableHashingContext<'a>>
61 for mir::UnsafetyViolationKind {
63 fn hash_stable<W: StableHasherResult>(&self,
64 hcx: &mut StableHashingContext<'a>,
65 hasher: &mut StableHasher<W>) {
67 mem::discriminant(self).hash_stable(hcx, hasher);
70 mir::UnsafetyViolationKind::General => {}
71 mir::UnsafetyViolationKind::MinConstFn => {}
72 mir::UnsafetyViolationKind::ExternStatic(lint_node_id) |
73 mir::UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
74 lint_node_id.hash_stable(hcx, hasher);
81 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
86 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
87 where T: HashStable<StableHashingContext<'a>>
90 fn hash_stable<W: StableHasherResult>(&self,
91 hcx: &mut StableHashingContext<'a>,
92 hasher: &mut StableHasher<W>) {
93 mem::discriminant(self).hash_stable(hcx, hasher);
95 mir::ClearCrossCrate::Clear => {}
96 mir::ClearCrossCrate::Set(ref value) => {
97 value.hash_stable(hcx, hasher);
103 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
105 fn hash_stable<W: StableHasherResult>(&self,
106 hcx: &mut StableHashingContext<'a>,
107 hasher: &mut StableHasher<W>) {
108 self.index().hash_stable(hcx, hasher);
112 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
114 fn hash_stable<W: StableHasherResult>(&self,
115 hcx: &mut StableHashingContext<'a>,
116 hasher: &mut StableHasher<W>) {
117 self.index().hash_stable(hcx, hasher);
121 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
123 fn hash_stable<W: StableHasherResult>(&self,
124 hcx: &mut StableHashingContext<'a>,
125 hasher: &mut StableHasher<W>) {
126 self.index().hash_stable(hcx, hasher);
130 impl<'a> HashStable<StableHashingContext<'a>>
131 for mir::SourceScope {
133 fn hash_stable<W: StableHasherResult>(&self,
134 hcx: &mut StableHashingContext<'a>,
135 hasher: &mut StableHasher<W>) {
136 self.index().hash_stable(hcx, hasher);
140 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
142 fn hash_stable<W: StableHasherResult>(&self,
143 hcx: &mut StableHashingContext<'a>,
144 hasher: &mut StableHasher<W>) {
145 self.index().hash_stable(hcx, hasher);
149 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
150 for mir::TerminatorKind<'gcx> {
151 fn hash_stable<W: StableHasherResult>(&self,
152 hcx: &mut StableHashingContext<'a>,
153 hasher: &mut StableHasher<W>) {
154 mem::discriminant(self).hash_stable(hcx, hasher);
157 mir::TerminatorKind::Goto { ref target } => {
158 target.hash_stable(hcx, hasher);
160 mir::TerminatorKind::SwitchInt { ref discr,
164 discr.hash_stable(hcx, hasher);
165 switch_ty.hash_stable(hcx, hasher);
166 values.hash_stable(hcx, hasher);
167 targets.hash_stable(hcx, hasher);
169 mir::TerminatorKind::Resume |
170 mir::TerminatorKind::Abort |
171 mir::TerminatorKind::Return |
172 mir::TerminatorKind::GeneratorDrop |
173 mir::TerminatorKind::Unreachable => {}
174 mir::TerminatorKind::Drop { ref location, target, unwind } => {
175 location.hash_stable(hcx, hasher);
176 target.hash_stable(hcx, hasher);
177 unwind.hash_stable(hcx, hasher);
179 mir::TerminatorKind::DropAndReplace { ref location,
183 location.hash_stable(hcx, hasher);
184 value.hash_stable(hcx, hasher);
185 target.hash_stable(hcx, hasher);
186 unwind.hash_stable(hcx, hasher);
188 mir::TerminatorKind::Yield { ref value,
191 value.hash_stable(hcx, hasher);
192 resume.hash_stable(hcx, hasher);
193 drop.hash_stable(hcx, hasher);
195 mir::TerminatorKind::Call { ref func,
199 from_hir_call, } => {
200 func.hash_stable(hcx, hasher);
201 args.hash_stable(hcx, hasher);
202 destination.hash_stable(hcx, hasher);
203 cleanup.hash_stable(hcx, hasher);
204 from_hir_call.hash_stable(hcx, hasher);
206 mir::TerminatorKind::Assert { ref cond,
211 cond.hash_stable(hcx, hasher);
212 expected.hash_stable(hcx, hasher);
213 msg.hash_stable(hcx, hasher);
214 target.hash_stable(hcx, hasher);
215 cleanup.hash_stable(hcx, hasher);
217 mir::TerminatorKind::FalseEdges { ref real_target, ref imaginary_targets } => {
218 real_target.hash_stable(hcx, hasher);
219 for target in imaginary_targets {
220 target.hash_stable(hcx, hasher);
223 mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
224 real_target.hash_stable(hcx, hasher);
225 unwind.hash_stable(hcx, hasher);
231 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
233 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
234 for mir::StatementKind<'gcx> {
235 fn hash_stable<W: StableHasherResult>(&self,
236 hcx: &mut StableHashingContext<'a>,
237 hasher: &mut StableHasher<W>) {
238 mem::discriminant(self).hash_stable(hcx, hasher);
241 mir::StatementKind::Assign(ref place, ref rvalue) => {
242 place.hash_stable(hcx, hasher);
243 rvalue.hash_stable(hcx, hasher);
245 mir::StatementKind::FakeRead(ref cause, ref place) => {
246 cause.hash_stable(hcx, hasher);
247 place.hash_stable(hcx, hasher);
249 mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
250 place.hash_stable(hcx, hasher);
251 variant_index.hash_stable(hcx, hasher);
253 mir::StatementKind::StorageLive(ref place) |
254 mir::StatementKind::StorageDead(ref place) => {
255 place.hash_stable(hcx, hasher);
257 mir::StatementKind::EndRegion(ref region_scope) => {
258 region_scope.hash_stable(hcx, hasher);
260 mir::StatementKind::Validate(ref op, ref places) => {
261 op.hash_stable(hcx, hasher);
262 places.hash_stable(hcx, hasher);
264 mir::StatementKind::AscribeUserType(ref place, ref variance, ref c_ty) => {
265 place.hash_stable(hcx, hasher);
266 variance.hash_stable(hcx, hasher);
267 c_ty.hash_stable(hcx, hasher);
269 mir::StatementKind::Nop => {}
270 mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
271 asm.hash_stable(hcx, hasher);
272 outputs.hash_stable(hcx, hasher);
273 inputs.hash_stable(hcx, hasher);
279 impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
281 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
282 for mir::ValidationOperand<'gcx, T>
283 where T: HashStable<StableHashingContext<'a>>
285 fn hash_stable<W: StableHasherResult>(&self,
286 hcx: &mut StableHashingContext<'a>,
287 hasher: &mut StableHasher<W>)
289 self.place.hash_stable(hcx, hasher);
290 self.ty.hash_stable(hcx, hasher);
291 self.re.hash_stable(hcx, hasher);
292 self.mutbl.hash_stable(hcx, hasher);
296 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
298 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
299 fn hash_stable<W: StableHasherResult>(&self,
300 hcx: &mut StableHashingContext<'a>,
301 hasher: &mut StableHasher<W>) {
302 mem::discriminant(self).hash_stable(hcx, hasher);
304 mir::Place::Local(ref local) => {
305 local.hash_stable(hcx, hasher);
307 mir::Place::Static(ref statik) => {
308 statik.hash_stable(hcx, hasher);
310 mir::Place::Promoted(ref promoted) => {
311 promoted.hash_stable(hcx, hasher);
313 mir::Place::Projection(ref place_projection) => {
314 place_projection.hash_stable(hcx, hasher);
320 impl<'a, 'gcx, B, V, T> HashStable<StableHashingContext<'a>>
321 for mir::Projection<'gcx, B, V, T>
322 where B: HashStable<StableHashingContext<'a>>,
323 V: HashStable<StableHashingContext<'a>>,
324 T: HashStable<StableHashingContext<'a>>
326 fn hash_stable<W: StableHasherResult>(&self,
327 hcx: &mut StableHashingContext<'a>,
328 hasher: &mut StableHasher<W>) {
329 let mir::Projection {
334 base.hash_stable(hcx, hasher);
335 elem.hash_stable(hcx, hasher);
339 impl<'a, 'gcx, V, T> HashStable<StableHashingContext<'a>>
340 for mir::ProjectionElem<'gcx, V, T>
341 where V: HashStable<StableHashingContext<'a>>,
342 T: HashStable<StableHashingContext<'a>>
344 fn hash_stable<W: StableHasherResult>(&self,
345 hcx: &mut StableHashingContext<'a>,
346 hasher: &mut StableHasher<W>) {
347 mem::discriminant(self).hash_stable(hcx, hasher);
349 mir::ProjectionElem::Deref => {}
350 mir::ProjectionElem::Field(field, ref ty) => {
351 field.hash_stable(hcx, hasher);
352 ty.hash_stable(hcx, hasher);
354 mir::ProjectionElem::Index(ref value) => {
355 value.hash_stable(hcx, hasher);
357 mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
358 offset.hash_stable(hcx, hasher);
359 min_length.hash_stable(hcx, hasher);
360 from_end.hash_stable(hcx, hasher);
362 mir::ProjectionElem::Subslice { from, to } => {
363 from.hash_stable(hcx, hasher);
364 to.hash_stable(hcx, hasher);
366 mir::ProjectionElem::Downcast(adt_def, variant) => {
367 adt_def.hash_stable(hcx, hasher);
368 variant.hash_stable(hcx, hasher);
374 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
375 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
379 impl<'a> HashStable<StableHashingContext<'a>> for mir::Safety {
380 fn hash_stable<W: StableHasherResult>(&self,
381 hcx: &mut StableHashingContext<'a>,
382 hasher: &mut StableHasher<W>) {
383 mem::discriminant(self).hash_stable(hcx, hasher);
387 mir::Safety::BuiltinUnsafe |
388 mir::Safety::FnUnsafe => {}
389 mir::Safety::ExplicitUnsafe(node_id) => {
390 node_id.hash_stable(hcx, hasher);
396 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Operand<'gcx> {
397 fn hash_stable<W: StableHasherResult>(&self,
398 hcx: &mut StableHashingContext<'a>,
399 hasher: &mut StableHasher<W>) {
400 mem::discriminant(self).hash_stable(hcx, hasher);
403 mir::Operand::Copy(ref place) => {
404 place.hash_stable(hcx, hasher);
406 mir::Operand::Move(ref place) => {
407 place.hash_stable(hcx, hasher);
409 mir::Operand::Constant(ref constant) => {
410 constant.hash_stable(hcx, hasher);
416 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
417 fn hash_stable<W: StableHasherResult>(&self,
418 hcx: &mut StableHashingContext<'a>,
419 hasher: &mut StableHasher<W>) {
420 mem::discriminant(self).hash_stable(hcx, hasher);
423 mir::Rvalue::Use(ref operand) => {
424 operand.hash_stable(hcx, hasher);
426 mir::Rvalue::Repeat(ref operand, ref val) => {
427 operand.hash_stable(hcx, hasher);
428 val.hash_stable(hcx, hasher);
430 mir::Rvalue::Ref(region, borrow_kind, ref place) => {
431 region.hash_stable(hcx, hasher);
432 borrow_kind.hash_stable(hcx, hasher);
433 place.hash_stable(hcx, hasher);
435 mir::Rvalue::Len(ref place) => {
436 place.hash_stable(hcx, hasher);
438 mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
439 cast_kind.hash_stable(hcx, hasher);
440 operand.hash_stable(hcx, hasher);
441 ty.hash_stable(hcx, hasher);
443 mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
444 mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
445 op.hash_stable(hcx, hasher);
446 operand1.hash_stable(hcx, hasher);
447 operand2.hash_stable(hcx, hasher);
449 mir::Rvalue::UnaryOp(op, ref operand) => {
450 op.hash_stable(hcx, hasher);
451 operand.hash_stable(hcx, hasher);
453 mir::Rvalue::Discriminant(ref place) => {
454 place.hash_stable(hcx, hasher);
456 mir::Rvalue::NullaryOp(op, ty) => {
457 op.hash_stable(hcx, hasher);
458 ty.hash_stable(hcx, hasher);
460 mir::Rvalue::Aggregate(ref kind, ref operands) => {
461 kind.hash_stable(hcx, hasher);
462 operands.hash_stable(hcx, hasher);
468 impl_stable_hash_for!(enum mir::CastKind {
476 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
477 for mir::AggregateKind<'gcx> {
478 fn hash_stable<W: StableHasherResult>(&self,
479 hcx: &mut StableHashingContext<'a>,
480 hasher: &mut StableHasher<W>) {
481 mem::discriminant(self).hash_stable(hcx, hasher);
483 mir::AggregateKind::Tuple => {}
484 mir::AggregateKind::Array(t) => {
485 t.hash_stable(hcx, hasher);
487 mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => {
488 adt_def.hash_stable(hcx, hasher);
489 idx.hash_stable(hcx, hasher);
490 substs.hash_stable(hcx, hasher);
491 user_substs.hash_stable(hcx, hasher);
492 active_field.hash_stable(hcx, hasher);
494 mir::AggregateKind::Closure(def_id, ref substs) => {
495 def_id.hash_stable(hcx, hasher);
496 substs.hash_stable(hcx, hasher);
498 mir::AggregateKind::Generator(def_id, ref substs, movability) => {
499 def_id.hash_stable(hcx, hasher);
500 substs.hash_stable(hcx, hasher);
501 movability.hash_stable(hcx, hasher);
507 impl_stable_hash_for!(enum mir::BinOp {
527 impl_stable_hash_for!(enum mir::UnOp {
532 impl_stable_hash_for!(enum mir::NullOp {
537 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
539 impl_stable_hash_for!(struct mir::Location { block, statement_index });
541 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
542 closure_requirements,
546 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
548 outlives_requirements
551 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
553 outlived_free_region,
558 impl_stable_hash_for!(enum mir::ConstraintCategory {
573 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {
574 fn hash_stable<W: StableHasherResult>(&self,
575 hcx: &mut StableHashingContext<'a>,
576 hasher: &mut StableHasher<W>) {
577 mem::discriminant(self).hash_stable(hcx, hasher);
579 mir::ClosureOutlivesSubject::Ty(ref ty) => {
580 ty.hash_stable(hcx, hasher);
582 mir::ClosureOutlivesSubject::Region(ref region) => {
583 region.hash_stable(hcx, hasher);
589 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });
591 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<'gcx> {
592 fn hash_stable<W: StableHasherResult>(&self,
593 hcx: &mut StableHashingContext<'a>,
594 hasher: &mut StableHasher<W>) {
595 mem::discriminant(self).hash_stable(hcx, hasher);
597 mir::UserTypeAnnotation::Ty(ref ty) => {
598 ty.hash_stable(hcx, hasher);
600 mir::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => {
601 def_id.hash_stable(hcx, hasher);
602 substs.hash_stable(hcx, hasher);