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> {
34 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability });
35 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
36 impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
37 impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
39 impl<'a> HashStable<StableHashingContext<'a>>
42 fn hash_stable<W: StableHasherResult>(&self,
43 hcx: &mut StableHashingContext<'a>,
44 hasher: &mut StableHasher<W>) {
45 mem::discriminant(self).hash_stable(hcx, hasher);
48 mir::BorrowKind::Shared |
49 mir::BorrowKind::Shallow |
50 mir::BorrowKind::Unique => {}
51 mir::BorrowKind::Mut { allow_two_phase_borrow } => {
52 allow_two_phase_borrow.hash_stable(hcx, hasher);
59 impl<'a> HashStable<StableHashingContext<'a>>
60 for mir::UnsafetyViolationKind {
62 fn hash_stable<W: StableHasherResult>(&self,
63 hcx: &mut StableHashingContext<'a>,
64 hasher: &mut StableHasher<W>) {
66 mem::discriminant(self).hash_stable(hcx, hasher);
69 mir::UnsafetyViolationKind::General => {}
70 mir::UnsafetyViolationKind::MinConstFn => {}
71 mir::UnsafetyViolationKind::ExternStatic(lint_node_id) |
72 mir::UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
73 lint_node_id.hash_stable(hcx, hasher);
80 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
85 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
86 where T: HashStable<StableHashingContext<'a>>
89 fn hash_stable<W: StableHasherResult>(&self,
90 hcx: &mut StableHashingContext<'a>,
91 hasher: &mut StableHasher<W>) {
92 mem::discriminant(self).hash_stable(hcx, hasher);
94 mir::ClearCrossCrate::Clear => {}
95 mir::ClearCrossCrate::Set(ref value) => {
96 value.hash_stable(hcx, hasher);
102 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
104 fn hash_stable<W: StableHasherResult>(&self,
105 hcx: &mut StableHashingContext<'a>,
106 hasher: &mut StableHasher<W>) {
107 self.index().hash_stable(hcx, hasher);
111 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
113 fn hash_stable<W: StableHasherResult>(&self,
114 hcx: &mut StableHashingContext<'a>,
115 hasher: &mut StableHasher<W>) {
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 self.index().hash_stable(hcx, hasher);
129 impl<'a> HashStable<StableHashingContext<'a>>
130 for mir::SourceScope {
132 fn hash_stable<W: StableHasherResult>(&self,
133 hcx: &mut StableHashingContext<'a>,
134 hasher: &mut StableHasher<W>) {
135 self.index().hash_stable(hcx, hasher);
139 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
141 fn hash_stable<W: StableHasherResult>(&self,
142 hcx: &mut StableHashingContext<'a>,
143 hasher: &mut StableHasher<W>) {
144 self.index().hash_stable(hcx, hasher);
148 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
149 for mir::TerminatorKind<'gcx> {
150 fn hash_stable<W: StableHasherResult>(&self,
151 hcx: &mut StableHashingContext<'a>,
152 hasher: &mut StableHasher<W>) {
153 mem::discriminant(self).hash_stable(hcx, hasher);
156 mir::TerminatorKind::Goto { ref target } => {
157 target.hash_stable(hcx, hasher);
159 mir::TerminatorKind::SwitchInt { ref discr,
163 discr.hash_stable(hcx, hasher);
164 switch_ty.hash_stable(hcx, hasher);
165 values.hash_stable(hcx, hasher);
166 targets.hash_stable(hcx, hasher);
168 mir::TerminatorKind::Resume |
169 mir::TerminatorKind::Abort |
170 mir::TerminatorKind::Return |
171 mir::TerminatorKind::GeneratorDrop |
172 mir::TerminatorKind::Unreachable => {}
173 mir::TerminatorKind::Drop { ref location, target, unwind } => {
174 location.hash_stable(hcx, hasher);
175 target.hash_stable(hcx, hasher);
176 unwind.hash_stable(hcx, hasher);
178 mir::TerminatorKind::DropAndReplace { ref location,
182 location.hash_stable(hcx, hasher);
183 value.hash_stable(hcx, hasher);
184 target.hash_stable(hcx, hasher);
185 unwind.hash_stable(hcx, hasher);
187 mir::TerminatorKind::Yield { ref value,
190 value.hash_stable(hcx, hasher);
191 resume.hash_stable(hcx, hasher);
192 drop.hash_stable(hcx, hasher);
194 mir::TerminatorKind::Call { ref func,
198 func.hash_stable(hcx, hasher);
199 args.hash_stable(hcx, hasher);
200 destination.hash_stable(hcx, hasher);
201 cleanup.hash_stable(hcx, hasher);
203 mir::TerminatorKind::Assert { ref cond,
208 cond.hash_stable(hcx, hasher);
209 expected.hash_stable(hcx, hasher);
210 msg.hash_stable(hcx, hasher);
211 target.hash_stable(hcx, hasher);
212 cleanup.hash_stable(hcx, hasher);
214 mir::TerminatorKind::FalseEdges { ref real_target, ref imaginary_targets } => {
215 real_target.hash_stable(hcx, hasher);
216 for target in imaginary_targets {
217 target.hash_stable(hcx, hasher);
220 mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
221 real_target.hash_stable(hcx, hasher);
222 unwind.hash_stable(hcx, hasher);
228 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
230 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
231 for mir::StatementKind<'gcx> {
232 fn hash_stable<W: StableHasherResult>(&self,
233 hcx: &mut StableHashingContext<'a>,
234 hasher: &mut StableHasher<W>) {
235 mem::discriminant(self).hash_stable(hcx, hasher);
238 mir::StatementKind::Assign(ref place, ref rvalue) => {
239 place.hash_stable(hcx, hasher);
240 rvalue.hash_stable(hcx, hasher);
242 mir::StatementKind::FakeRead(ref cause, ref place) => {
243 cause.hash_stable(hcx, hasher);
244 place.hash_stable(hcx, hasher);
246 mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
247 place.hash_stable(hcx, hasher);
248 variant_index.hash_stable(hcx, hasher);
250 mir::StatementKind::StorageLive(ref place) |
251 mir::StatementKind::StorageDead(ref place) => {
252 place.hash_stable(hcx, hasher);
254 mir::StatementKind::EndRegion(ref region_scope) => {
255 region_scope.hash_stable(hcx, hasher);
257 mir::StatementKind::Validate(ref op, ref places) => {
258 op.hash_stable(hcx, hasher);
259 places.hash_stable(hcx, hasher);
261 mir::StatementKind::AscribeUserType(ref place, ref variance, ref c_ty) => {
262 place.hash_stable(hcx, hasher);
263 variance.hash_stable(hcx, hasher);
264 c_ty.hash_stable(hcx, hasher);
266 mir::StatementKind::Nop => {}
267 mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
268 asm.hash_stable(hcx, hasher);
269 outputs.hash_stable(hcx, hasher);
270 inputs.hash_stable(hcx, hasher);
276 impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
278 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
279 for mir::ValidationOperand<'gcx, T>
280 where T: HashStable<StableHashingContext<'a>>
282 fn hash_stable<W: StableHasherResult>(&self,
283 hcx: &mut StableHashingContext<'a>,
284 hasher: &mut StableHasher<W>)
286 self.place.hash_stable(hcx, hasher);
287 self.ty.hash_stable(hcx, hasher);
288 self.re.hash_stable(hcx, hasher);
289 self.mutbl.hash_stable(hcx, hasher);
293 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
295 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
296 fn hash_stable<W: StableHasherResult>(&self,
297 hcx: &mut StableHashingContext<'a>,
298 hasher: &mut StableHasher<W>) {
299 mem::discriminant(self).hash_stable(hcx, hasher);
301 mir::Place::Local(ref local) => {
302 local.hash_stable(hcx, hasher);
304 mir::Place::Static(ref statik) => {
305 statik.hash_stable(hcx, hasher);
307 mir::Place::Promoted(ref promoted) => {
308 promoted.hash_stable(hcx, hasher);
310 mir::Place::Projection(ref place_projection) => {
311 place_projection.hash_stable(hcx, hasher);
317 impl<'a, 'gcx, B, V, T> HashStable<StableHashingContext<'a>>
318 for mir::Projection<'gcx, B, V, T>
319 where B: HashStable<StableHashingContext<'a>>,
320 V: HashStable<StableHashingContext<'a>>,
321 T: HashStable<StableHashingContext<'a>>
323 fn hash_stable<W: StableHasherResult>(&self,
324 hcx: &mut StableHashingContext<'a>,
325 hasher: &mut StableHasher<W>) {
326 let mir::Projection {
331 base.hash_stable(hcx, hasher);
332 elem.hash_stable(hcx, hasher);
336 impl<'a, 'gcx, V, T> HashStable<StableHashingContext<'a>>
337 for mir::ProjectionElem<'gcx, V, T>
338 where V: HashStable<StableHashingContext<'a>>,
339 T: HashStable<StableHashingContext<'a>>
341 fn hash_stable<W: StableHasherResult>(&self,
342 hcx: &mut StableHashingContext<'a>,
343 hasher: &mut StableHasher<W>) {
344 mem::discriminant(self).hash_stable(hcx, hasher);
346 mir::ProjectionElem::Deref => {}
347 mir::ProjectionElem::Field(field, ref ty) => {
348 field.hash_stable(hcx, hasher);
349 ty.hash_stable(hcx, hasher);
351 mir::ProjectionElem::Index(ref value) => {
352 value.hash_stable(hcx, hasher);
354 mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
355 offset.hash_stable(hcx, hasher);
356 min_length.hash_stable(hcx, hasher);
357 from_end.hash_stable(hcx, hasher);
359 mir::ProjectionElem::Subslice { from, to } => {
360 from.hash_stable(hcx, hasher);
361 to.hash_stable(hcx, hasher);
363 mir::ProjectionElem::Downcast(adt_def, variant) => {
364 adt_def.hash_stable(hcx, hasher);
365 variant.hash_stable(hcx, hasher);
371 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
372 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
376 impl<'a> HashStable<StableHashingContext<'a>> for mir::Safety {
377 fn hash_stable<W: StableHasherResult>(&self,
378 hcx: &mut StableHashingContext<'a>,
379 hasher: &mut StableHasher<W>) {
380 mem::discriminant(self).hash_stable(hcx, hasher);
384 mir::Safety::BuiltinUnsafe |
385 mir::Safety::FnUnsafe => {}
386 mir::Safety::ExplicitUnsafe(node_id) => {
387 node_id.hash_stable(hcx, hasher);
393 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Operand<'gcx> {
394 fn hash_stable<W: StableHasherResult>(&self,
395 hcx: &mut StableHashingContext<'a>,
396 hasher: &mut StableHasher<W>) {
397 mem::discriminant(self).hash_stable(hcx, hasher);
400 mir::Operand::Copy(ref place) => {
401 place.hash_stable(hcx, hasher);
403 mir::Operand::Move(ref place) => {
404 place.hash_stable(hcx, hasher);
406 mir::Operand::Constant(ref constant) => {
407 constant.hash_stable(hcx, hasher);
413 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
414 fn hash_stable<W: StableHasherResult>(&self,
415 hcx: &mut StableHashingContext<'a>,
416 hasher: &mut StableHasher<W>) {
417 mem::discriminant(self).hash_stable(hcx, hasher);
420 mir::Rvalue::Use(ref operand) => {
421 operand.hash_stable(hcx, hasher);
423 mir::Rvalue::Repeat(ref operand, ref val) => {
424 operand.hash_stable(hcx, hasher);
425 val.hash_stable(hcx, hasher);
427 mir::Rvalue::Ref(region, borrow_kind, ref place) => {
428 region.hash_stable(hcx, hasher);
429 borrow_kind.hash_stable(hcx, hasher);
430 place.hash_stable(hcx, hasher);
432 mir::Rvalue::Len(ref place) => {
433 place.hash_stable(hcx, hasher);
435 mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
436 cast_kind.hash_stable(hcx, hasher);
437 operand.hash_stable(hcx, hasher);
438 ty.hash_stable(hcx, hasher);
440 mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
441 mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
442 op.hash_stable(hcx, hasher);
443 operand1.hash_stable(hcx, hasher);
444 operand2.hash_stable(hcx, hasher);
446 mir::Rvalue::UnaryOp(op, ref operand) => {
447 op.hash_stable(hcx, hasher);
448 operand.hash_stable(hcx, hasher);
450 mir::Rvalue::Discriminant(ref place) => {
451 place.hash_stable(hcx, hasher);
453 mir::Rvalue::NullaryOp(op, ty) => {
454 op.hash_stable(hcx, hasher);
455 ty.hash_stable(hcx, hasher);
457 mir::Rvalue::Aggregate(ref kind, ref operands) => {
458 kind.hash_stable(hcx, hasher);
459 operands.hash_stable(hcx, hasher);
465 impl_stable_hash_for!(enum mir::CastKind {
473 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
474 for mir::AggregateKind<'gcx> {
475 fn hash_stable<W: StableHasherResult>(&self,
476 hcx: &mut StableHashingContext<'a>,
477 hasher: &mut StableHasher<W>) {
478 mem::discriminant(self).hash_stable(hcx, hasher);
480 mir::AggregateKind::Tuple => {}
481 mir::AggregateKind::Array(t) => {
482 t.hash_stable(hcx, hasher);
484 mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => {
485 adt_def.hash_stable(hcx, hasher);
486 idx.hash_stable(hcx, hasher);
487 substs.hash_stable(hcx, hasher);
488 user_substs.hash_stable(hcx, hasher);
489 active_field.hash_stable(hcx, hasher);
491 mir::AggregateKind::Closure(def_id, ref substs) => {
492 def_id.hash_stable(hcx, hasher);
493 substs.hash_stable(hcx, hasher);
495 mir::AggregateKind::Generator(def_id, ref substs, movability) => {
496 def_id.hash_stable(hcx, hasher);
497 substs.hash_stable(hcx, hasher);
498 movability.hash_stable(hcx, hasher);
504 impl_stable_hash_for!(enum mir::BinOp {
524 impl_stable_hash_for!(enum mir::UnOp {
529 impl_stable_hash_for!(enum mir::NullOp {
534 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
536 impl_stable_hash_for!(struct mir::Location { block, statement_index });
538 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
539 closure_requirements,
543 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
545 outlives_requirements
548 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
550 outlived_free_region,
554 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {
555 fn hash_stable<W: StableHasherResult>(&self,
556 hcx: &mut StableHashingContext<'a>,
557 hasher: &mut StableHasher<W>) {
558 mem::discriminant(self).hash_stable(hcx, hasher);
560 mir::ClosureOutlivesSubject::Ty(ref ty) => {
561 ty.hash_stable(hcx, hasher);
563 mir::ClosureOutlivesSubject::Region(ref region) => {
564 region.hash_stable(hcx, hasher);
570 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });