]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_mir.rs
Auto merge of #53815 - F001:if-let-guard, r=petrochenkov
[rust.git] / src / librustc / ich / impls_mir.rs
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.
4 //
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.
10
11 //! This module contains `HashStable` implementations for various MIR data
12 //! types in no particular order.
13
14 use ich::StableHashingContext;
15 use mir;
16 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
17                                            StableHasherResult};
18 use std::mem;
19
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> {
25     mutability,
26     ty,
27     name,
28     source_info,
29     visibility_scope,
30     internal,
31     is_user_variable
32 });
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 });
37
38 impl<'a> HashStable<StableHashingContext<'a>>
39 for mir::BorrowKind {
40     #[inline]
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);
45
46         match *self {
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);
51             }
52         }
53     }
54 }
55
56
57 impl<'a> HashStable<StableHashingContext<'a>>
58 for mir::UnsafetyViolationKind {
59     #[inline]
60     fn hash_stable<W: StableHasherResult>(&self,
61                                           hcx: &mut StableHashingContext<'a>,
62                                           hasher: &mut StableHasher<W>) {
63
64         mem::discriminant(self).hash_stable(hcx, hasher);
65
66         match *self {
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);
72             }
73
74         }
75     }
76 }
77
78 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
79     kind,
80     source_info
81 });
82
83 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
84     where T: HashStable<StableHashingContext<'a>>
85 {
86     #[inline]
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);
91         match *self {
92             mir::ClearCrossCrate::Clear => {}
93             mir::ClearCrossCrate::Set(ref value) => {
94                 value.hash_stable(hcx, hasher);
95             }
96         }
97     }
98 }
99
100 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
101     #[inline]
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);
107     }
108 }
109
110 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
111     #[inline]
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);
117     }
118 }
119
120 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
121     #[inline]
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);
127     }
128 }
129
130 impl<'a> HashStable<StableHashingContext<'a>>
131 for mir::SourceScope {
132     #[inline]
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);
138     }
139 }
140
141 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
142     #[inline]
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);
148     }
149 }
150
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);
157
158         match *self {
159             mir::TerminatorKind::Goto { ref target } => {
160                 target.hash_stable(hcx, hasher);
161             }
162             mir::TerminatorKind::SwitchInt { ref discr,
163                                              switch_ty,
164                                              ref values,
165                                              ref targets } => {
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);
170             }
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);
180             }
181             mir::TerminatorKind::DropAndReplace { ref location,
182                                                   ref value,
183                                                   target,
184                                                   unwind, } => {
185                 location.hash_stable(hcx, hasher);
186                 value.hash_stable(hcx, hasher);
187                 target.hash_stable(hcx, hasher);
188                 unwind.hash_stable(hcx, hasher);
189             }
190             mir::TerminatorKind::Yield { ref value,
191                                         resume,
192                                         drop } => {
193                 value.hash_stable(hcx, hasher);
194                 resume.hash_stable(hcx, hasher);
195                 drop.hash_stable(hcx, hasher);
196             }
197             mir::TerminatorKind::Call { ref func,
198                                         ref args,
199                                         ref destination,
200                                         cleanup } => {
201                 func.hash_stable(hcx, hasher);
202                 args.hash_stable(hcx, hasher);
203                 destination.hash_stable(hcx, hasher);
204                 cleanup.hash_stable(hcx, hasher);
205             }
206             mir::TerminatorKind::Assert { ref cond,
207                                           expected,
208                                           ref msg,
209                                           target,
210                                           cleanup } => {
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);
216             }
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);
221                 }
222             }
223             mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
224                 real_target.hash_stable(hcx, hasher);
225                 unwind.hash_stable(hcx, hasher);
226             }
227         }
228     }
229 }
230
231 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
232
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);
239
240         match *self {
241             mir::StatementKind::Assign(ref place, ref rvalue) => {
242                 place.hash_stable(hcx, hasher);
243                 rvalue.hash_stable(hcx, hasher);
244             }
245             mir::StatementKind::ReadForMatch(ref place) => {
246                 place.hash_stable(hcx, hasher);
247             }
248             mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
249                 place.hash_stable(hcx, hasher);
250                 variant_index.hash_stable(hcx, hasher);
251             }
252             mir::StatementKind::StorageLive(ref place) |
253             mir::StatementKind::StorageDead(ref place) => {
254                 place.hash_stable(hcx, hasher);
255             }
256             mir::StatementKind::EndRegion(ref region_scope) => {
257                 region_scope.hash_stable(hcx, hasher);
258             }
259             mir::StatementKind::Validate(ref op, ref places) => {
260                 op.hash_stable(hcx, hasher);
261                 places.hash_stable(hcx, hasher);
262             }
263             mir::StatementKind::UserAssertTy(ref c_ty, ref local) => {
264                 c_ty.hash_stable(hcx, hasher);
265                 local.hash_stable(hcx, hasher);
266             }
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);
272             }
273         }
274     }
275 }
276
277 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
278     for mir::ValidationOperand<'gcx, T>
279     where T: HashStable<StableHashingContext<'a>>
280 {
281     fn hash_stable<W: StableHasherResult>(&self,
282                                           hcx: &mut StableHashingContext<'a>,
283                                           hasher: &mut StableHasher<W>)
284     {
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);
289     }
290 }
291
292 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
293
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);
299         match *self {
300             mir::Place::Local(ref local) => {
301                 local.hash_stable(hcx, hasher);
302             }
303             mir::Place::Static(ref statik) => {
304                 statik.hash_stable(hcx, hasher);
305             }
306             mir::Place::Promoted(ref promoted) => {
307                 promoted.hash_stable(hcx, hasher);
308             }
309             mir::Place::Projection(ref place_projection) => {
310                 place_projection.hash_stable(hcx, hasher);
311             }
312         }
313     }
314 }
315
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>>
321 {
322     fn hash_stable<W: StableHasherResult>(&self,
323                                           hcx: &mut StableHashingContext<'a>,
324                                           hasher: &mut StableHasher<W>) {
325         let mir::Projection {
326             ref base,
327             ref elem,
328         } = *self;
329
330         base.hash_stable(hcx, hasher);
331         elem.hash_stable(hcx, hasher);
332     }
333 }
334
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>>
339 {
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);
344         match *self {
345             mir::ProjectionElem::Deref => {}
346             mir::ProjectionElem::Field(field, ref ty) => {
347                 field.hash_stable(hcx, hasher);
348                 ty.hash_stable(hcx, hasher);
349             }
350             mir::ProjectionElem::Index(ref value) => {
351                 value.hash_stable(hcx, hasher);
352             }
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);
357             }
358             mir::ProjectionElem::Subslice { from, to } => {
359                 from.hash_stable(hcx, hasher);
360                 to.hash_stable(hcx, hasher);
361             }
362             mir::ProjectionElem::Downcast(adt_def, variant) => {
363                 adt_def.hash_stable(hcx, hasher);
364                 variant.hash_stable(hcx, hasher);
365             }
366         }
367     }
368 }
369
370 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
371 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
372     lint_root, safety
373 });
374
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);
380
381         match *self {
382             mir::Safety::Safe |
383             mir::Safety::BuiltinUnsafe |
384             mir::Safety::FnUnsafe => {}
385             mir::Safety::ExplicitUnsafe(node_id) => {
386                 node_id.hash_stable(hcx, hasher);
387             }
388         }
389     }
390 }
391
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);
397
398         match *self {
399             mir::Operand::Copy(ref place) => {
400                 place.hash_stable(hcx, hasher);
401             }
402             mir::Operand::Move(ref place) => {
403                 place.hash_stable(hcx, hasher);
404             }
405             mir::Operand::Constant(ref constant) => {
406                 constant.hash_stable(hcx, hasher);
407             }
408         }
409     }
410 }
411
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);
417
418         match *self {
419             mir::Rvalue::Use(ref operand) => {
420                 operand.hash_stable(hcx, hasher);
421             }
422             mir::Rvalue::Repeat(ref operand, ref val) => {
423                 operand.hash_stable(hcx, hasher);
424                 val.hash_stable(hcx, hasher);
425             }
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);
430             }
431             mir::Rvalue::Len(ref place) => {
432                 place.hash_stable(hcx, hasher);
433             }
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);
438             }
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);
444             }
445             mir::Rvalue::UnaryOp(op, ref operand) => {
446                 op.hash_stable(hcx, hasher);
447                 operand.hash_stable(hcx, hasher);
448             }
449             mir::Rvalue::Discriminant(ref place) => {
450                 place.hash_stable(hcx, hasher);
451             }
452             mir::Rvalue::NullaryOp(op, ty) => {
453                 op.hash_stable(hcx, hasher);
454                 ty.hash_stable(hcx, hasher);
455             }
456             mir::Rvalue::Aggregate(ref kind, ref operands) => {
457                 kind.hash_stable(hcx, hasher);
458                 operands.hash_stable(hcx, hasher);
459             }
460         }
461     }
462 }
463
464 impl_stable_hash_for!(enum mir::CastKind {
465     Misc,
466     ReifyFnPointer,
467     ClosureFnPointer,
468     UnsafeFnPointer,
469     Unsize
470 });
471
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);
478         match *self {
479             mir::AggregateKind::Tuple => {}
480             mir::AggregateKind::Array(t) => {
481                 t.hash_stable(hcx, hasher);
482             }
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);
489             }
490             mir::AggregateKind::Closure(def_id, ref substs) => {
491                 def_id.hash_stable(hcx, hasher);
492                 substs.hash_stable(hcx, hasher);
493             }
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);
498             }
499         }
500     }
501 }
502
503 impl_stable_hash_for!(enum mir::BinOp {
504     Add,
505     Sub,
506     Mul,
507     Div,
508     Rem,
509     BitXor,
510     BitAnd,
511     BitOr,
512     Shl,
513     Shr,
514     Eq,
515     Lt,
516     Le,
517     Ne,
518     Ge,
519     Gt,
520     Offset
521 });
522
523 impl_stable_hash_for!(enum mir::UnOp {
524     Not,
525     Neg
526 });
527
528 impl_stable_hash_for!(enum mir::NullOp {
529     Box,
530     SizeOf
531 });
532
533 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
534
535 impl_stable_hash_for!(struct mir::Location { block, statement_index });
536
537 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
538     closure_requirements,
539     used_mut_upvars
540 });
541
542 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
543     num_external_vids,
544     outlives_requirements
545 });
546
547 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
548     subject,
549     outlived_free_region,
550     blame_span
551 });
552
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);
558         match *self {
559             mir::ClosureOutlivesSubject::Ty(ref ty) => {
560                 ty.hash_stable(hcx, hasher);
561             }
562             mir::ClosureOutlivesSubject::Region(ref region) => {
563                 region.hash_stable(hcx, hasher);
564             }
565         }
566     }
567 }
568
569 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });