]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_mir.rs
Auto merge of #57609 - matthewjasper:more-restrictive-match, r=pnkfelix
[rust.git] / src / librustc / ich / impls_mir.rs
1 //! This module contains `HashStable` implementations for various MIR data
2 //! types in no particular order.
3
4 use crate::ich::StableHashingContext;
5 use crate::mir;
6 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
7                                            StableHasherResult};
8 use std::mem;
9
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> {
15     mutability,
16     ty,
17     user_ty,
18     name,
19     source_info,
20     visibility_scope,
21     internal,
22     is_block_tail,
23     is_user_variable
24 });
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 });
29
30 impl_stable_hash_for!(enum mir::BorrowKind {
31     Shared,
32     Shallow,
33     Unique,
34     Mut { allow_two_phase_borrow },
35 });
36
37 impl_stable_hash_for!(enum mir::UnsafetyViolationKind {
38     General,
39     GeneralAndConstFn,
40     ExternStatic(lint_node_id),
41     BorrowPacked(lint_node_id),
42 });
43
44 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
45     kind,
46     source_info
47 });
48
49 impl_stable_hash_for!(
50     impl<T> for enum mir::ClearCrossCrate<T> [ mir::ClearCrossCrate ] {
51         Clear,
52         Set(value),
53     }
54 );
55
56 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
57     #[inline]
58     fn hash_stable<W: StableHasherResult>(&self,
59                                           hcx: &mut StableHashingContext<'a>,
60                                           hasher: &mut StableHasher<W>) {
61         self.index().hash_stable(hcx, hasher);
62     }
63 }
64
65 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
66     #[inline]
67     fn hash_stable<W: StableHasherResult>(&self,
68                                           hcx: &mut StableHashingContext<'a>,
69                                           hasher: &mut StableHasher<W>) {
70         self.index().hash_stable(hcx, hasher);
71     }
72 }
73
74 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
75     #[inline]
76     fn hash_stable<W: StableHasherResult>(&self,
77                                           hcx: &mut StableHashingContext<'a>,
78                                           hasher: &mut StableHasher<W>) {
79         self.index().hash_stable(hcx, hasher);
80     }
81 }
82
83 impl<'a> HashStable<StableHashingContext<'a>>
84 for mir::SourceScope {
85     #[inline]
86     fn hash_stable<W: StableHasherResult>(&self,
87                                           hcx: &mut StableHashingContext<'a>,
88                                           hasher: &mut StableHasher<W>) {
89         self.index().hash_stable(hcx, hasher);
90     }
91 }
92
93 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
94     #[inline]
95     fn hash_stable<W: StableHasherResult>(&self,
96                                           hcx: &mut StableHashingContext<'a>,
97                                           hasher: &mut StableHasher<W>) {
98         self.index().hash_stable(hcx, hasher);
99     }
100 }
101
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);
108
109         match *self {
110             mir::TerminatorKind::Goto { ref target } => {
111                 target.hash_stable(hcx, hasher);
112             }
113             mir::TerminatorKind::SwitchInt { ref discr,
114                                              switch_ty,
115                                              ref values,
116                                              ref targets } => {
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);
121             }
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);
131             }
132             mir::TerminatorKind::DropAndReplace { ref location,
133                                                   ref value,
134                                                   target,
135                                                   unwind, } => {
136                 location.hash_stable(hcx, hasher);
137                 value.hash_stable(hcx, hasher);
138                 target.hash_stable(hcx, hasher);
139                 unwind.hash_stable(hcx, hasher);
140             }
141             mir::TerminatorKind::Yield { ref value,
142                                         resume,
143                                         drop } => {
144                 value.hash_stable(hcx, hasher);
145                 resume.hash_stable(hcx, hasher);
146                 drop.hash_stable(hcx, hasher);
147             }
148             mir::TerminatorKind::Call { ref func,
149                                         ref args,
150                                         ref destination,
151                                         cleanup,
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);
158             }
159             mir::TerminatorKind::Assert { ref cond,
160                                           expected,
161                                           ref msg,
162                                           target,
163                                           cleanup } => {
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);
169             }
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);
174                 }
175             }
176             mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
177                 real_target.hash_stable(hcx, hasher);
178                 unwind.hash_stable(hcx, hasher);
179             }
180         }
181     }
182 }
183
184 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
185
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 },
190     StorageLive(place),
191     StorageDead(place),
192     Retag(retag_kind, place),
193     AscribeUserType(place, variance, c_ty),
194     Nop,
195     InlineAsm { asm, outputs, inputs },
196 });
197
198 impl_stable_hash_for!(enum mir::RetagKind { FnEntry, TwoPhase, Raw, Default });
199 impl_stable_hash_for!(enum mir::FakeReadCause {
200     ForMatchGuard,
201     ForMatchedPlace,
202     ForGuardBinding,
203     ForLet
204 });
205
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);
211         match *self {
212             mir::Place::Local(ref local) => {
213                 local.hash_stable(hcx, hasher);
214             }
215             mir::Place::Static(ref statik) => {
216                 statik.hash_stable(hcx, hasher);
217             }
218             mir::Place::Promoted(ref promoted) => {
219                 promoted.hash_stable(hcx, hasher);
220             }
221             mir::Place::Projection(ref place_projection) => {
222                 place_projection.hash_stable(hcx, hasher);
223             }
224         }
225     }
226 }
227
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>>
233 {
234     fn hash_stable<W: StableHasherResult>(&self,
235                                           hcx: &mut StableHashingContext<'a>,
236                                           hasher: &mut StableHasher<W>) {
237         let mir::Projection {
238             ref base,
239             ref elem,
240         } = *self;
241
242         base.hash_stable(hcx, hasher);
243         elem.hash_stable(hcx, hasher);
244     }
245 }
246
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>>
251 {
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);
256         match *self {
257             mir::ProjectionElem::Deref => {}
258             mir::ProjectionElem::Field(field, ref ty) => {
259                 field.hash_stable(hcx, hasher);
260                 ty.hash_stable(hcx, hasher);
261             }
262             mir::ProjectionElem::Index(ref value) => {
263                 value.hash_stable(hcx, hasher);
264             }
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);
269             }
270             mir::ProjectionElem::Subslice { from, to } => {
271                 from.hash_stable(hcx, hasher);
272                 to.hash_stable(hcx, hasher);
273             }
274             mir::ProjectionElem::Downcast(adt_def, variant) => {
275                 adt_def.hash_stable(hcx, hasher);
276                 variant.hash_stable(hcx, hasher);
277             }
278         }
279     }
280 }
281
282 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
283 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
284     lint_root, safety
285 });
286
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);
292
293         match *self {
294             mir::Safety::Safe |
295             mir::Safety::BuiltinUnsafe |
296             mir::Safety::FnUnsafe => {}
297             mir::Safety::ExplicitUnsafe(node_id) => {
298                 node_id.hash_stable(hcx, hasher);
299             }
300         }
301     }
302 }
303
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);
309
310         match *self {
311             mir::Operand::Copy(ref place) => {
312                 place.hash_stable(hcx, hasher);
313             }
314             mir::Operand::Move(ref place) => {
315                 place.hash_stable(hcx, hasher);
316             }
317             mir::Operand::Constant(ref constant) => {
318                 constant.hash_stable(hcx, hasher);
319             }
320         }
321     }
322 }
323
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);
329
330         match *self {
331             mir::Rvalue::Use(ref operand) => {
332                 operand.hash_stable(hcx, hasher);
333             }
334             mir::Rvalue::Repeat(ref operand, ref val) => {
335                 operand.hash_stable(hcx, hasher);
336                 val.hash_stable(hcx, hasher);
337             }
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);
342             }
343             mir::Rvalue::Len(ref place) => {
344                 place.hash_stable(hcx, hasher);
345             }
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);
350             }
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);
356             }
357             mir::Rvalue::UnaryOp(op, ref operand) => {
358                 op.hash_stable(hcx, hasher);
359                 operand.hash_stable(hcx, hasher);
360             }
361             mir::Rvalue::Discriminant(ref place) => {
362                 place.hash_stable(hcx, hasher);
363             }
364             mir::Rvalue::NullaryOp(op, ty) => {
365                 op.hash_stable(hcx, hasher);
366                 ty.hash_stable(hcx, hasher);
367             }
368             mir::Rvalue::Aggregate(ref kind, ref operands) => {
369                 kind.hash_stable(hcx, hasher);
370                 operands.hash_stable(hcx, hasher);
371             }
372         }
373     }
374 }
375
376 impl_stable_hash_for!(enum mir::CastKind {
377     Misc,
378     ReifyFnPointer,
379     ClosureFnPointer,
380     UnsafeFnPointer,
381     Unsize
382 });
383
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);
390         match *self {
391             mir::AggregateKind::Tuple => {}
392             mir::AggregateKind::Array(t) => {
393                 t.hash_stable(hcx, hasher);
394             }
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);
401             }
402             mir::AggregateKind::Closure(def_id, ref substs) => {
403                 def_id.hash_stable(hcx, hasher);
404                 substs.hash_stable(hcx, hasher);
405             }
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);
410             }
411         }
412     }
413 }
414
415 impl_stable_hash_for!(enum mir::BinOp {
416     Add,
417     Sub,
418     Mul,
419     Div,
420     Rem,
421     BitXor,
422     BitAnd,
423     BitOr,
424     Shl,
425     Shr,
426     Eq,
427     Lt,
428     Le,
429     Ne,
430     Ge,
431     Gt,
432     Offset
433 });
434
435 impl_stable_hash_for!(enum mir::UnOp {
436     Not,
437     Neg
438 });
439
440 impl_stable_hash_for!(enum mir::NullOp {
441     Box,
442     SizeOf
443 });
444
445 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
446
447 impl_stable_hash_for!(struct mir::Location { block, statement_index });
448
449 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
450     closure_requirements,
451     used_mut_upvars
452 });
453
454 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
455     num_external_vids,
456     outlives_requirements
457 });
458
459 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
460     subject,
461     outlived_free_region,
462     blame_span,
463     category
464 });
465
466 impl_stable_hash_for!(enum mir::ConstraintCategory {
467     Return,
468     Yield,
469     UseAsConst,
470     UseAsStatic,
471     TypeAnnotation,
472     Cast,
473     ClosureBounds,
474     CallArgument,
475     CopyBound,
476     SizedBound,
477     Assignment,
478     OpaqueType,
479     Boring,
480     BoringNoLocation,
481     Internal,
482 });
483
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);
489         match *self {
490             mir::ClosureOutlivesSubject::Ty(ref ty) => {
491                 ty.hash_stable(hcx, hasher);
492             }
493             mir::ClosureOutlivesSubject::Region(ref region) => {
494                 region.hash_stable(hcx, hasher);
495             }
496         }
497     }
498 }
499
500 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });
501
502 impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs });
503 impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents });