1 //! This module contains `HashStable` implementations for various MIR data
2 //! types in no particular order.
4 use crate::ich::StableHashingContext;
6 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
10 impl_stable_hash_for!(struct mir::GeneratorLayout<'tcx> { fields });
11 impl_stable_hash_for!(struct mir::SourceInfo { span, scope });
12 impl_stable_hash_for!(enum mir::Mutability { Mut, Not });
13 impl_stable_hash_for!(enum mir::LocalKind { Var, Temp, Arg, ReturnPointer });
14 impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
25 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability });
26 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
27 impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
28 impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
30 impl_stable_hash_for!(enum mir::BorrowKind {
34 Mut { allow_two_phase_borrow },
37 impl_stable_hash_for!(enum mir::UnsafetyViolationKind {
40 ExternStatic(lint_node_id),
41 BorrowPacked(lint_node_id),
44 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
49 impl_stable_hash_for!(
50 impl<T> for enum mir::ClearCrossCrate<T> [ mir::ClearCrossCrate ] {
56 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
58 fn hash_stable<W: StableHasherResult>(&self,
59 hcx: &mut StableHashingContext<'a>,
60 hasher: &mut StableHasher<W>) {
61 self.index().hash_stable(hcx, hasher);
65 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
67 fn hash_stable<W: StableHasherResult>(&self,
68 hcx: &mut StableHashingContext<'a>,
69 hasher: &mut StableHasher<W>) {
70 self.index().hash_stable(hcx, hasher);
74 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
76 fn hash_stable<W: StableHasherResult>(&self,
77 hcx: &mut StableHashingContext<'a>,
78 hasher: &mut StableHasher<W>) {
79 self.index().hash_stable(hcx, hasher);
83 impl<'a> HashStable<StableHashingContext<'a>>
84 for mir::SourceScope {
86 fn hash_stable<W: StableHasherResult>(&self,
87 hcx: &mut StableHashingContext<'a>,
88 hasher: &mut StableHasher<W>) {
89 self.index().hash_stable(hcx, hasher);
93 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
95 fn hash_stable<W: StableHasherResult>(&self,
96 hcx: &mut StableHashingContext<'a>,
97 hasher: &mut StableHasher<W>) {
98 self.index().hash_stable(hcx, hasher);
102 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
103 for mir::TerminatorKind<'gcx> {
104 fn hash_stable<W: StableHasherResult>(&self,
105 hcx: &mut StableHashingContext<'a>,
106 hasher: &mut StableHasher<W>) {
107 mem::discriminant(self).hash_stable(hcx, hasher);
110 mir::TerminatorKind::Goto { ref target } => {
111 target.hash_stable(hcx, hasher);
113 mir::TerminatorKind::SwitchInt { ref discr,
117 discr.hash_stable(hcx, hasher);
118 switch_ty.hash_stable(hcx, hasher);
119 values.hash_stable(hcx, hasher);
120 targets.hash_stable(hcx, hasher);
122 mir::TerminatorKind::Resume |
123 mir::TerminatorKind::Abort |
124 mir::TerminatorKind::Return |
125 mir::TerminatorKind::GeneratorDrop |
126 mir::TerminatorKind::Unreachable => {}
127 mir::TerminatorKind::Drop { ref location, target, unwind } => {
128 location.hash_stable(hcx, hasher);
129 target.hash_stable(hcx, hasher);
130 unwind.hash_stable(hcx, hasher);
132 mir::TerminatorKind::DropAndReplace { ref location,
136 location.hash_stable(hcx, hasher);
137 value.hash_stable(hcx, hasher);
138 target.hash_stable(hcx, hasher);
139 unwind.hash_stable(hcx, hasher);
141 mir::TerminatorKind::Yield { ref value,
144 value.hash_stable(hcx, hasher);
145 resume.hash_stable(hcx, hasher);
146 drop.hash_stable(hcx, hasher);
148 mir::TerminatorKind::Call { ref func,
152 from_hir_call, } => {
153 func.hash_stable(hcx, hasher);
154 args.hash_stable(hcx, hasher);
155 destination.hash_stable(hcx, hasher);
156 cleanup.hash_stable(hcx, hasher);
157 from_hir_call.hash_stable(hcx, hasher);
159 mir::TerminatorKind::Assert { ref cond,
164 cond.hash_stable(hcx, hasher);
165 expected.hash_stable(hcx, hasher);
166 msg.hash_stable(hcx, hasher);
167 target.hash_stable(hcx, hasher);
168 cleanup.hash_stable(hcx, hasher);
170 mir::TerminatorKind::FalseEdges { ref real_target, ref imaginary_targets } => {
171 real_target.hash_stable(hcx, hasher);
172 for target in imaginary_targets {
173 target.hash_stable(hcx, hasher);
176 mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
177 real_target.hash_stable(hcx, hasher);
178 unwind.hash_stable(hcx, hasher);
184 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
186 impl_stable_hash_for!(impl<'gcx> for enum mir::StatementKind<'gcx> [ mir::StatementKind ] {
187 Assign(place, rvalue),
188 FakeRead(cause, place),
189 SetDiscriminant { place, variant_index },
192 Retag(retag_kind, place),
193 AscribeUserType(place, variance, c_ty),
195 InlineAsm { asm, outputs, inputs },
198 impl_stable_hash_for!(enum mir::RetagKind { FnEntry, TwoPhase, Raw, Default });
199 impl_stable_hash_for!(enum mir::FakeReadCause {
206 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
207 fn hash_stable<W: StableHasherResult>(&self,
208 hcx: &mut StableHashingContext<'a>,
209 hasher: &mut StableHasher<W>) {
210 mem::discriminant(self).hash_stable(hcx, hasher);
212 mir::Place::Local(ref local) => {
213 local.hash_stable(hcx, hasher);
215 mir::Place::Static(ref statik) => {
216 statik.hash_stable(hcx, hasher);
218 mir::Place::Promoted(ref promoted) => {
219 promoted.hash_stable(hcx, hasher);
221 mir::Place::Projection(ref place_projection) => {
222 place_projection.hash_stable(hcx, hasher);
228 impl<'a, 'gcx, B, V, T> HashStable<StableHashingContext<'a>>
229 for mir::Projection<'gcx, B, V, T>
230 where B: HashStable<StableHashingContext<'a>>,
231 V: HashStable<StableHashingContext<'a>>,
232 T: HashStable<StableHashingContext<'a>>
234 fn hash_stable<W: StableHasherResult>(&self,
235 hcx: &mut StableHashingContext<'a>,
236 hasher: &mut StableHasher<W>) {
237 let mir::Projection {
242 base.hash_stable(hcx, hasher);
243 elem.hash_stable(hcx, hasher);
247 impl<'a, 'gcx, V, T> HashStable<StableHashingContext<'a>>
248 for mir::ProjectionElem<'gcx, V, T>
249 where V: HashStable<StableHashingContext<'a>>,
250 T: HashStable<StableHashingContext<'a>>
252 fn hash_stable<W: StableHasherResult>(&self,
253 hcx: &mut StableHashingContext<'a>,
254 hasher: &mut StableHasher<W>) {
255 mem::discriminant(self).hash_stable(hcx, hasher);
257 mir::ProjectionElem::Deref => {}
258 mir::ProjectionElem::Field(field, ref ty) => {
259 field.hash_stable(hcx, hasher);
260 ty.hash_stable(hcx, hasher);
262 mir::ProjectionElem::Index(ref value) => {
263 value.hash_stable(hcx, hasher);
265 mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
266 offset.hash_stable(hcx, hasher);
267 min_length.hash_stable(hcx, hasher);
268 from_end.hash_stable(hcx, hasher);
270 mir::ProjectionElem::Subslice { from, to } => {
271 from.hash_stable(hcx, hasher);
272 to.hash_stable(hcx, hasher);
274 mir::ProjectionElem::Downcast(adt_def, variant) => {
275 adt_def.hash_stable(hcx, hasher);
276 variant.hash_stable(hcx, hasher);
282 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
283 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
287 impl<'a> HashStable<StableHashingContext<'a>> for mir::Safety {
288 fn hash_stable<W: StableHasherResult>(&self,
289 hcx: &mut StableHashingContext<'a>,
290 hasher: &mut StableHasher<W>) {
291 mem::discriminant(self).hash_stable(hcx, hasher);
295 mir::Safety::BuiltinUnsafe |
296 mir::Safety::FnUnsafe => {}
297 mir::Safety::ExplicitUnsafe(node_id) => {
298 node_id.hash_stable(hcx, hasher);
304 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Operand<'gcx> {
305 fn hash_stable<W: StableHasherResult>(&self,
306 hcx: &mut StableHashingContext<'a>,
307 hasher: &mut StableHasher<W>) {
308 mem::discriminant(self).hash_stable(hcx, hasher);
311 mir::Operand::Copy(ref place) => {
312 place.hash_stable(hcx, hasher);
314 mir::Operand::Move(ref place) => {
315 place.hash_stable(hcx, hasher);
317 mir::Operand::Constant(ref constant) => {
318 constant.hash_stable(hcx, hasher);
324 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
325 fn hash_stable<W: StableHasherResult>(&self,
326 hcx: &mut StableHashingContext<'a>,
327 hasher: &mut StableHasher<W>) {
328 mem::discriminant(self).hash_stable(hcx, hasher);
331 mir::Rvalue::Use(ref operand) => {
332 operand.hash_stable(hcx, hasher);
334 mir::Rvalue::Repeat(ref operand, ref val) => {
335 operand.hash_stable(hcx, hasher);
336 val.hash_stable(hcx, hasher);
338 mir::Rvalue::Ref(region, borrow_kind, ref place) => {
339 region.hash_stable(hcx, hasher);
340 borrow_kind.hash_stable(hcx, hasher);
341 place.hash_stable(hcx, hasher);
343 mir::Rvalue::Len(ref place) => {
344 place.hash_stable(hcx, hasher);
346 mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
347 cast_kind.hash_stable(hcx, hasher);
348 operand.hash_stable(hcx, hasher);
349 ty.hash_stable(hcx, hasher);
351 mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
352 mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
353 op.hash_stable(hcx, hasher);
354 operand1.hash_stable(hcx, hasher);
355 operand2.hash_stable(hcx, hasher);
357 mir::Rvalue::UnaryOp(op, ref operand) => {
358 op.hash_stable(hcx, hasher);
359 operand.hash_stable(hcx, hasher);
361 mir::Rvalue::Discriminant(ref place) => {
362 place.hash_stable(hcx, hasher);
364 mir::Rvalue::NullaryOp(op, ty) => {
365 op.hash_stable(hcx, hasher);
366 ty.hash_stable(hcx, hasher);
368 mir::Rvalue::Aggregate(ref kind, ref operands) => {
369 kind.hash_stable(hcx, hasher);
370 operands.hash_stable(hcx, hasher);
376 impl_stable_hash_for!(enum mir::CastKind {
384 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
385 for mir::AggregateKind<'gcx> {
386 fn hash_stable<W: StableHasherResult>(&self,
387 hcx: &mut StableHashingContext<'a>,
388 hasher: &mut StableHasher<W>) {
389 mem::discriminant(self).hash_stable(hcx, hasher);
391 mir::AggregateKind::Tuple => {}
392 mir::AggregateKind::Array(t) => {
393 t.hash_stable(hcx, hasher);
395 mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => {
396 adt_def.hash_stable(hcx, hasher);
397 idx.hash_stable(hcx, hasher);
398 substs.hash_stable(hcx, hasher);
399 user_substs.hash_stable(hcx, hasher);
400 active_field.hash_stable(hcx, hasher);
402 mir::AggregateKind::Closure(def_id, ref substs) => {
403 def_id.hash_stable(hcx, hasher);
404 substs.hash_stable(hcx, hasher);
406 mir::AggregateKind::Generator(def_id, ref substs, movability) => {
407 def_id.hash_stable(hcx, hasher);
408 substs.hash_stable(hcx, hasher);
409 movability.hash_stable(hcx, hasher);
415 impl_stable_hash_for!(enum mir::BinOp {
435 impl_stable_hash_for!(enum mir::UnOp {
440 impl_stable_hash_for!(enum mir::NullOp {
445 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
447 impl_stable_hash_for!(struct mir::Location { block, statement_index });
449 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
450 closure_requirements,
454 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
456 outlives_requirements
459 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
461 outlived_free_region,
466 impl_stable_hash_for!(enum mir::ConstraintCategory {
484 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {
485 fn hash_stable<W: StableHasherResult>(&self,
486 hcx: &mut StableHashingContext<'a>,
487 hasher: &mut StableHasher<W>) {
488 mem::discriminant(self).hash_stable(hcx, hasher);
490 mir::ClosureOutlivesSubject::Ty(ref ty) => {
491 ty.hash_stable(hcx, hasher);
493 mir::ClosureOutlivesSubject::Region(ref region) => {
494 region.hash_stable(hcx, hasher);
500 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });
502 impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs });
503 impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents });