]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_mir.rs
Add more fake borrows to matches
[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     user_ty,
28     name,
29     source_info,
30     visibility_scope,
31     internal,
32     is_user_variable
33 });
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 });
38
39 impl<'a> HashStable<StableHashingContext<'a>>
40 for mir::BorrowKind {
41     #[inline]
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);
46
47         match *self {
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);
53             }
54         }
55     }
56 }
57
58
59 impl<'a> HashStable<StableHashingContext<'a>>
60 for mir::UnsafetyViolationKind {
61     #[inline]
62     fn hash_stable<W: StableHasherResult>(&self,
63                                           hcx: &mut StableHashingContext<'a>,
64                                           hasher: &mut StableHasher<W>) {
65
66         mem::discriminant(self).hash_stable(hcx, hasher);
67
68         match *self {
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);
74             }
75
76         }
77     }
78 }
79
80 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
81     kind,
82     source_info
83 });
84
85 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
86     where T: HashStable<StableHashingContext<'a>>
87 {
88     #[inline]
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);
93         match *self {
94             mir::ClearCrossCrate::Clear => {}
95             mir::ClearCrossCrate::Set(ref value) => {
96                 value.hash_stable(hcx, hasher);
97             }
98         }
99     }
100 }
101
102 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
103     #[inline]
104     fn hash_stable<W: StableHasherResult>(&self,
105                                           hcx: &mut StableHashingContext<'a>,
106                                           hasher: &mut StableHasher<W>) {
107         self.index().hash_stable(hcx, hasher);
108     }
109 }
110
111 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
112     #[inline]
113     fn hash_stable<W: StableHasherResult>(&self,
114                                           hcx: &mut StableHashingContext<'a>,
115                                           hasher: &mut StableHasher<W>) {
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         self.index().hash_stable(hcx, hasher);
126     }
127 }
128
129 impl<'a> HashStable<StableHashingContext<'a>>
130 for mir::SourceScope {
131     #[inline]
132     fn hash_stable<W: StableHasherResult>(&self,
133                                           hcx: &mut StableHashingContext<'a>,
134                                           hasher: &mut StableHasher<W>) {
135         self.index().hash_stable(hcx, hasher);
136     }
137 }
138
139 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
140     #[inline]
141     fn hash_stable<W: StableHasherResult>(&self,
142                                           hcx: &mut StableHashingContext<'a>,
143                                           hasher: &mut StableHasher<W>) {
144         self.index().hash_stable(hcx, hasher);
145     }
146 }
147
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);
154
155         match *self {
156             mir::TerminatorKind::Goto { ref target } => {
157                 target.hash_stable(hcx, hasher);
158             }
159             mir::TerminatorKind::SwitchInt { ref discr,
160                                              switch_ty,
161                                              ref values,
162                                              ref targets } => {
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);
167             }
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);
177             }
178             mir::TerminatorKind::DropAndReplace { ref location,
179                                                   ref value,
180                                                   target,
181                                                   unwind, } => {
182                 location.hash_stable(hcx, hasher);
183                 value.hash_stable(hcx, hasher);
184                 target.hash_stable(hcx, hasher);
185                 unwind.hash_stable(hcx, hasher);
186             }
187             mir::TerminatorKind::Yield { ref value,
188                                         resume,
189                                         drop } => {
190                 value.hash_stable(hcx, hasher);
191                 resume.hash_stable(hcx, hasher);
192                 drop.hash_stable(hcx, hasher);
193             }
194             mir::TerminatorKind::Call { ref func,
195                                         ref args,
196                                         ref destination,
197                                         cleanup } => {
198                 func.hash_stable(hcx, hasher);
199                 args.hash_stable(hcx, hasher);
200                 destination.hash_stable(hcx, hasher);
201                 cleanup.hash_stable(hcx, hasher);
202             }
203             mir::TerminatorKind::Assert { ref cond,
204                                           expected,
205                                           ref msg,
206                                           target,
207                                           cleanup } => {
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);
213             }
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);
218                 }
219             }
220             mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
221                 real_target.hash_stable(hcx, hasher);
222                 unwind.hash_stable(hcx, hasher);
223             }
224         }
225     }
226 }
227
228 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
229
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);
236
237         match *self {
238             mir::StatementKind::Assign(ref place, ref rvalue) => {
239                 place.hash_stable(hcx, hasher);
240                 rvalue.hash_stable(hcx, hasher);
241             }
242             mir::StatementKind::FakeRead(ref cause, ref place) => {
243                 cause.hash_stable(hcx, hasher);
244                 place.hash_stable(hcx, hasher);
245             }
246             mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
247                 place.hash_stable(hcx, hasher);
248                 variant_index.hash_stable(hcx, hasher);
249             }
250             mir::StatementKind::StorageLive(ref place) |
251             mir::StatementKind::StorageDead(ref place) => {
252                 place.hash_stable(hcx, hasher);
253             }
254             mir::StatementKind::EndRegion(ref region_scope) => {
255                 region_scope.hash_stable(hcx, hasher);
256             }
257             mir::StatementKind::Validate(ref op, ref places) => {
258                 op.hash_stable(hcx, hasher);
259                 places.hash_stable(hcx, hasher);
260             }
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);
265             }
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);
271             }
272         }
273     }
274 }
275
276 impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
277
278 impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
279     for mir::ValidationOperand<'gcx, T>
280     where T: HashStable<StableHashingContext<'a>>
281 {
282     fn hash_stable<W: StableHasherResult>(&self,
283                                           hcx: &mut StableHashingContext<'a>,
284                                           hasher: &mut StableHasher<W>)
285     {
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);
290     }
291 }
292
293 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
294
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);
300         match *self {
301             mir::Place::Local(ref local) => {
302                 local.hash_stable(hcx, hasher);
303             }
304             mir::Place::Static(ref statik) => {
305                 statik.hash_stable(hcx, hasher);
306             }
307             mir::Place::Promoted(ref promoted) => {
308                 promoted.hash_stable(hcx, hasher);
309             }
310             mir::Place::Projection(ref place_projection) => {
311                 place_projection.hash_stable(hcx, hasher);
312             }
313         }
314     }
315 }
316
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>>
322 {
323     fn hash_stable<W: StableHasherResult>(&self,
324                                           hcx: &mut StableHashingContext<'a>,
325                                           hasher: &mut StableHasher<W>) {
326         let mir::Projection {
327             ref base,
328             ref elem,
329         } = *self;
330
331         base.hash_stable(hcx, hasher);
332         elem.hash_stable(hcx, hasher);
333     }
334 }
335
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>>
340 {
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);
345         match *self {
346             mir::ProjectionElem::Deref => {}
347             mir::ProjectionElem::Field(field, ref ty) => {
348                 field.hash_stable(hcx, hasher);
349                 ty.hash_stable(hcx, hasher);
350             }
351             mir::ProjectionElem::Index(ref value) => {
352                 value.hash_stable(hcx, hasher);
353             }
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);
358             }
359             mir::ProjectionElem::Subslice { from, to } => {
360                 from.hash_stable(hcx, hasher);
361                 to.hash_stable(hcx, hasher);
362             }
363             mir::ProjectionElem::Downcast(adt_def, variant) => {
364                 adt_def.hash_stable(hcx, hasher);
365                 variant.hash_stable(hcx, hasher);
366             }
367         }
368     }
369 }
370
371 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
372 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
373     lint_root, safety
374 });
375
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);
381
382         match *self {
383             mir::Safety::Safe |
384             mir::Safety::BuiltinUnsafe |
385             mir::Safety::FnUnsafe => {}
386             mir::Safety::ExplicitUnsafe(node_id) => {
387                 node_id.hash_stable(hcx, hasher);
388             }
389         }
390     }
391 }
392
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);
398
399         match *self {
400             mir::Operand::Copy(ref place) => {
401                 place.hash_stable(hcx, hasher);
402             }
403             mir::Operand::Move(ref place) => {
404                 place.hash_stable(hcx, hasher);
405             }
406             mir::Operand::Constant(ref constant) => {
407                 constant.hash_stable(hcx, hasher);
408             }
409         }
410     }
411 }
412
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);
418
419         match *self {
420             mir::Rvalue::Use(ref operand) => {
421                 operand.hash_stable(hcx, hasher);
422             }
423             mir::Rvalue::Repeat(ref operand, ref val) => {
424                 operand.hash_stable(hcx, hasher);
425                 val.hash_stable(hcx, hasher);
426             }
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);
431             }
432             mir::Rvalue::Len(ref place) => {
433                 place.hash_stable(hcx, hasher);
434             }
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);
439             }
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);
445             }
446             mir::Rvalue::UnaryOp(op, ref operand) => {
447                 op.hash_stable(hcx, hasher);
448                 operand.hash_stable(hcx, hasher);
449             }
450             mir::Rvalue::Discriminant(ref place) => {
451                 place.hash_stable(hcx, hasher);
452             }
453             mir::Rvalue::NullaryOp(op, ty) => {
454                 op.hash_stable(hcx, hasher);
455                 ty.hash_stable(hcx, hasher);
456             }
457             mir::Rvalue::Aggregate(ref kind, ref operands) => {
458                 kind.hash_stable(hcx, hasher);
459                 operands.hash_stable(hcx, hasher);
460             }
461         }
462     }
463 }
464
465 impl_stable_hash_for!(enum mir::CastKind {
466     Misc,
467     ReifyFnPointer,
468     ClosureFnPointer,
469     UnsafeFnPointer,
470     Unsize
471 });
472
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);
479         match *self {
480             mir::AggregateKind::Tuple => {}
481             mir::AggregateKind::Array(t) => {
482                 t.hash_stable(hcx, hasher);
483             }
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);
490             }
491             mir::AggregateKind::Closure(def_id, ref substs) => {
492                 def_id.hash_stable(hcx, hasher);
493                 substs.hash_stable(hcx, hasher);
494             }
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);
499             }
500         }
501     }
502 }
503
504 impl_stable_hash_for!(enum mir::BinOp {
505     Add,
506     Sub,
507     Mul,
508     Div,
509     Rem,
510     BitXor,
511     BitAnd,
512     BitOr,
513     Shl,
514     Shr,
515     Eq,
516     Lt,
517     Le,
518     Ne,
519     Ge,
520     Gt,
521     Offset
522 });
523
524 impl_stable_hash_for!(enum mir::UnOp {
525     Not,
526     Neg
527 });
528
529 impl_stable_hash_for!(enum mir::NullOp {
530     Box,
531     SizeOf
532 });
533
534 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
535
536 impl_stable_hash_for!(struct mir::Location { block, statement_index });
537
538 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
539     closure_requirements,
540     used_mut_upvars
541 });
542
543 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
544     num_external_vids,
545     outlives_requirements
546 });
547
548 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
549     subject,
550     outlived_free_region,
551     blame_span
552 });
553
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);
559         match *self {
560             mir::ClosureOutlivesSubject::Ty(ref ty) => {
561                 ty.hash_stable(hcx, hasher);
562             }
563             mir::ClosureOutlivesSubject::Region(ref region) => {
564                 region.hash_stable(hcx, hasher);
565             }
566         }
567     }
568 }
569
570 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });