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> {
33 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability });
34 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
35 impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
36 impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
38 impl<'a> HashStable<StableHashingContext<'a>>
41 fn hash_stable<W: StableHasherResult>(&self,
42 hcx: &mut StableHashingContext<'a>,
43 hasher: &mut StableHasher<W>) {
44 mem::discriminant(self).hash_stable(hcx, hasher);
47 mir::BorrowKind::Shared |
48 mir::BorrowKind::Unique => {}
49 mir::BorrowKind::Mut { allow_two_phase_borrow } => {
50 allow_two_phase_borrow.hash_stable(hcx, hasher);
57 impl<'a> HashStable<StableHashingContext<'a>>
58 for mir::UnsafetyViolationKind {
60 fn hash_stable<W: StableHasherResult>(&self,
61 hcx: &mut StableHashingContext<'a>,
62 hasher: &mut StableHasher<W>) {
64 mem::discriminant(self).hash_stable(hcx, hasher);
67 mir::UnsafetyViolationKind::General => {}
68 mir::UnsafetyViolationKind::MinConstFn => {}
69 mir::UnsafetyViolationKind::ExternStatic(lint_node_id) |
70 mir::UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
71 lint_node_id.hash_stable(hcx, hasher);
78 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
83 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
84 where T: HashStable<StableHashingContext<'a>>
87 fn hash_stable<W: StableHasherResult>(&self,
88 hcx: &mut StableHashingContext<'a>,
89 hasher: &mut StableHasher<W>) {
90 mem::discriminant(self).hash_stable(hcx, hasher);
92 mir::ClearCrossCrate::Clear => {}
93 mir::ClearCrossCrate::Set(ref value) => {
94 value.hash_stable(hcx, hasher);
100 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
102 fn hash_stable<W: StableHasherResult>(&self,
103 hcx: &mut StableHashingContext<'a>,
104 hasher: &mut StableHasher<W>) {
105 use rustc_data_structures::indexed_vec::Idx;
106 self.index().hash_stable(hcx, hasher);
110 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
112 fn hash_stable<W: StableHasherResult>(&self,
113 hcx: &mut StableHashingContext<'a>,
114 hasher: &mut StableHasher<W>) {
115 use rustc_data_structures::indexed_vec::Idx;
116 self.index().hash_stable(hcx, hasher);
120 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
122 fn hash_stable<W: StableHasherResult>(&self,
123 hcx: &mut StableHashingContext<'a>,
124 hasher: &mut StableHasher<W>) {
125 use rustc_data_structures::indexed_vec::Idx;
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 use rustc_data_structures::indexed_vec::Idx;
137 self.index().hash_stable(hcx, hasher);
141 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
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<'a, 'gcx> HashStable<StableHashingContext<'a>>
152 for mir::TerminatorKind<'gcx> {
153 fn hash_stable<W: StableHasherResult>(&self,
154 hcx: &mut StableHashingContext<'a>,
155 hasher: &mut StableHasher<W>) {
156 mem::discriminant(self).hash_stable(hcx, hasher);
159 mir::TerminatorKind::Goto { ref target } => {
160 target.hash_stable(hcx, hasher);
162 mir::TerminatorKind::SwitchInt { ref discr,
166 discr.hash_stable(hcx, hasher);
167 switch_ty.hash_stable(hcx, hasher);
168 values.hash_stable(hcx, hasher);
169 targets.hash_stable(hcx, hasher);
171 mir::TerminatorKind::Resume |
172 mir::TerminatorKind::Abort |
173 mir::TerminatorKind::Return |
174 mir::TerminatorKind::GeneratorDrop |
175 mir::TerminatorKind::Unreachable => {}
176 mir::TerminatorKind::Drop { ref location, target, unwind } => {
177 location.hash_stable(hcx, hasher);
178 target.hash_stable(hcx, hasher);
179 unwind.hash_stable(hcx, hasher);
181 mir::TerminatorKind::DropAndReplace { ref location,
185 location.hash_stable(hcx, hasher);
186 value.hash_stable(hcx, hasher);
187 target.hash_stable(hcx, hasher);
188 unwind.hash_stable(hcx, hasher);
190 mir::TerminatorKind::Yield { ref value,
193 value.hash_stable(hcx, hasher);
194 resume.hash_stable(hcx, hasher);
195 drop.hash_stable(hcx, hasher);
197 mir::TerminatorKind::Call { ref func,
201 func.hash_stable(hcx, hasher);
202 args.hash_stable(hcx, hasher);
203 destination.hash_stable(hcx, hasher);
204 cleanup.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::ReadForMatch(ref place) => {
246 place.hash_stable(hcx, hasher);
248 mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
249 place.hash_stable(hcx, hasher);
250 variant_index.hash_stable(hcx, hasher);
252 mir::StatementKind::StorageLive(ref place) |
253 mir::StatementKind::StorageDead(ref place) => {
254 place.hash_stable(hcx, hasher);
256 mir::StatementKind::EndRegion(ref region_scope) => {
257 region_scope.hash_stable(hcx, hasher);
259 mir::StatementKind::Validate(ref op, ref places) => {
260 op.hash_stable(hcx, hasher);
261 places.hash_stable(hcx, hasher);
263 mir::StatementKind::UserAssertTy(ref c_ty, ref local) => {
264 c_ty.hash_stable(hcx, hasher);
265 local.hash_stable(hcx, hasher);
267 mir::StatementKind::Nop => {}
268 mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
269 asm.hash_stable(hcx, hasher);
270 outputs.hash_stable(hcx, hasher);
271 inputs.hash_stable(hcx, hasher);
277 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
278 for mir::ValidationOperand<'gcx, T>
279 where T: HashStable<StableHashingContext<'a>>
281 fn hash_stable<W: StableHasherResult>(&self,
282 hcx: &mut StableHashingContext<'a>,
283 hasher: &mut StableHasher<W>)
285 self.place.hash_stable(hcx, hasher);
286 self.ty.hash_stable(hcx, hasher);
287 self.re.hash_stable(hcx, hasher);
288 self.mutbl.hash_stable(hcx, hasher);
292 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
294 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
295 fn hash_stable<W: StableHasherResult>(&self,
296 hcx: &mut StableHashingContext<'a>,
297 hasher: &mut StableHasher<W>) {
298 mem::discriminant(self).hash_stable(hcx, hasher);
300 mir::Place::Local(ref local) => {
301 local.hash_stable(hcx, hasher);
303 mir::Place::Static(ref statik) => {
304 statik.hash_stable(hcx, hasher);
306 mir::Place::Promoted(ref promoted) => {
307 promoted.hash_stable(hcx, hasher);
309 mir::Place::Projection(ref place_projection) => {
310 place_projection.hash_stable(hcx, hasher);
316 impl<'a, 'gcx, B, V, T> HashStable<StableHashingContext<'a>>
317 for mir::Projection<'gcx, B, V, T>
318 where B: HashStable<StableHashingContext<'a>>,
319 V: HashStable<StableHashingContext<'a>>,
320 T: HashStable<StableHashingContext<'a>>
322 fn hash_stable<W: StableHasherResult>(&self,
323 hcx: &mut StableHashingContext<'a>,
324 hasher: &mut StableHasher<W>) {
325 let mir::Projection {
330 base.hash_stable(hcx, hasher);
331 elem.hash_stable(hcx, hasher);
335 impl<'a, 'gcx, V, T> HashStable<StableHashingContext<'a>>
336 for mir::ProjectionElem<'gcx, V, T>
337 where V: HashStable<StableHashingContext<'a>>,
338 T: HashStable<StableHashingContext<'a>>
340 fn hash_stable<W: StableHasherResult>(&self,
341 hcx: &mut StableHashingContext<'a>,
342 hasher: &mut StableHasher<W>) {
343 mem::discriminant(self).hash_stable(hcx, hasher);
345 mir::ProjectionElem::Deref => {}
346 mir::ProjectionElem::Field(field, ref ty) => {
347 field.hash_stable(hcx, hasher);
348 ty.hash_stable(hcx, hasher);
350 mir::ProjectionElem::Index(ref value) => {
351 value.hash_stable(hcx, hasher);
353 mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
354 offset.hash_stable(hcx, hasher);
355 min_length.hash_stable(hcx, hasher);
356 from_end.hash_stable(hcx, hasher);
358 mir::ProjectionElem::Subslice { from, to } => {
359 from.hash_stable(hcx, hasher);
360 to.hash_stable(hcx, hasher);
362 mir::ProjectionElem::Downcast(adt_def, variant) => {
363 adt_def.hash_stable(hcx, hasher);
364 variant.hash_stable(hcx, hasher);
370 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
371 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
375 impl<'a> HashStable<StableHashingContext<'a>> for mir::Safety {
376 fn hash_stable<W: StableHasherResult>(&self,
377 hcx: &mut StableHashingContext<'a>,
378 hasher: &mut StableHasher<W>) {
379 mem::discriminant(self).hash_stable(hcx, hasher);
383 mir::Safety::BuiltinUnsafe |
384 mir::Safety::FnUnsafe => {}
385 mir::Safety::ExplicitUnsafe(node_id) => {
386 node_id.hash_stable(hcx, hasher);
392 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Operand<'gcx> {
393 fn hash_stable<W: StableHasherResult>(&self,
394 hcx: &mut StableHashingContext<'a>,
395 hasher: &mut StableHasher<W>) {
396 mem::discriminant(self).hash_stable(hcx, hasher);
399 mir::Operand::Copy(ref place) => {
400 place.hash_stable(hcx, hasher);
402 mir::Operand::Move(ref place) => {
403 place.hash_stable(hcx, hasher);
405 mir::Operand::Constant(ref constant) => {
406 constant.hash_stable(hcx, hasher);
412 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
413 fn hash_stable<W: StableHasherResult>(&self,
414 hcx: &mut StableHashingContext<'a>,
415 hasher: &mut StableHasher<W>) {
416 mem::discriminant(self).hash_stable(hcx, hasher);
419 mir::Rvalue::Use(ref operand) => {
420 operand.hash_stable(hcx, hasher);
422 mir::Rvalue::Repeat(ref operand, ref val) => {
423 operand.hash_stable(hcx, hasher);
424 val.hash_stable(hcx, hasher);
426 mir::Rvalue::Ref(region, borrow_kind, ref place) => {
427 region.hash_stable(hcx, hasher);
428 borrow_kind.hash_stable(hcx, hasher);
429 place.hash_stable(hcx, hasher);
431 mir::Rvalue::Len(ref place) => {
432 place.hash_stable(hcx, hasher);
434 mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
435 cast_kind.hash_stable(hcx, hasher);
436 operand.hash_stable(hcx, hasher);
437 ty.hash_stable(hcx, hasher);
439 mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
440 mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
441 op.hash_stable(hcx, hasher);
442 operand1.hash_stable(hcx, hasher);
443 operand2.hash_stable(hcx, hasher);
445 mir::Rvalue::UnaryOp(op, ref operand) => {
446 op.hash_stable(hcx, hasher);
447 operand.hash_stable(hcx, hasher);
449 mir::Rvalue::Discriminant(ref place) => {
450 place.hash_stable(hcx, hasher);
452 mir::Rvalue::NullaryOp(op, ty) => {
453 op.hash_stable(hcx, hasher);
454 ty.hash_stable(hcx, hasher);
456 mir::Rvalue::Aggregate(ref kind, ref operands) => {
457 kind.hash_stable(hcx, hasher);
458 operands.hash_stable(hcx, hasher);
464 impl_stable_hash_for!(enum mir::CastKind {
472 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
473 for mir::AggregateKind<'gcx> {
474 fn hash_stable<W: StableHasherResult>(&self,
475 hcx: &mut StableHashingContext<'a>,
476 hasher: &mut StableHasher<W>) {
477 mem::discriminant(self).hash_stable(hcx, hasher);
479 mir::AggregateKind::Tuple => {}
480 mir::AggregateKind::Array(t) => {
481 t.hash_stable(hcx, hasher);
483 mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => {
484 adt_def.hash_stable(hcx, hasher);
485 idx.hash_stable(hcx, hasher);
486 substs.hash_stable(hcx, hasher);
487 user_substs.hash_stable(hcx, hasher);
488 active_field.hash_stable(hcx, hasher);
490 mir::AggregateKind::Closure(def_id, ref substs) => {
491 def_id.hash_stable(hcx, hasher);
492 substs.hash_stable(hcx, hasher);
494 mir::AggregateKind::Generator(def_id, ref substs, movability) => {
495 def_id.hash_stable(hcx, hasher);
496 substs.hash_stable(hcx, hasher);
497 movability.hash_stable(hcx, hasher);
503 impl_stable_hash_for!(enum mir::BinOp {
523 impl_stable_hash_for!(enum mir::UnOp {
528 impl_stable_hash_for!(enum mir::NullOp {
533 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
535 impl_stable_hash_for!(struct mir::Location { block, statement_index });
537 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
538 closure_requirements,
542 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
544 outlives_requirements
547 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
549 outlived_free_region,
553 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {
554 fn hash_stable<W: StableHasherResult>(&self,
555 hcx: &mut StableHashingContext<'a>,
556 hasher: &mut StableHasher<W>) {
557 mem::discriminant(self).hash_stable(hcx, hasher);
559 mir::ClosureOutlivesSubject::Ty(ref ty) => {
560 ty.hash_stable(hcx, hasher);
562 mir::ClosureOutlivesSubject::Region(ref region) => {
563 region.hash_stable(hcx, hasher);
569 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });