]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_mir.rs
Emit feature gate suggestion
[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_block_tail,
33     is_user_variable
34 });
35 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability });
36 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
37 impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
38 impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
39
40 impl_stable_hash_for!(enum mir::BorrowKind {
41     Shared,
42     Shallow,
43     Unique,
44     Mut { allow_two_phase_borrow },
45 });
46
47 impl_stable_hash_for!(enum mir::UnsafetyViolationKind {
48     General,
49     GeneralAndConstFn,
50     GatedConstFnCall,
51     ExternStatic(lint_node_id),
52     BorrowPacked(lint_node_id),
53 });
54
55 impl_stable_hash_for!(struct mir::Terminator<'tcx> {
56     kind,
57     source_info
58 });
59
60 impl_stable_hash_for!(
61     impl<T> for enum mir::ClearCrossCrate<T> [ mir::ClearCrossCrate ] {
62         Clear,
63         Set(value),
64     }
65 );
66
67 impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
68     #[inline]
69     fn hash_stable<W: StableHasherResult>(&self,
70                                           hcx: &mut StableHashingContext<'a>,
71                                           hasher: &mut StableHasher<W>) {
72         self.index().hash_stable(hcx, hasher);
73     }
74 }
75
76 impl<'a> HashStable<StableHashingContext<'a>> for mir::BasicBlock {
77     #[inline]
78     fn hash_stable<W: StableHasherResult>(&self,
79                                           hcx: &mut StableHashingContext<'a>,
80                                           hasher: &mut StableHasher<W>) {
81         self.index().hash_stable(hcx, hasher);
82     }
83 }
84
85 impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
86     #[inline]
87     fn hash_stable<W: StableHasherResult>(&self,
88                                           hcx: &mut StableHashingContext<'a>,
89                                           hasher: &mut StableHasher<W>) {
90         self.index().hash_stable(hcx, hasher);
91     }
92 }
93
94 impl<'a> HashStable<StableHashingContext<'a>>
95 for mir::SourceScope {
96     #[inline]
97     fn hash_stable<W: StableHasherResult>(&self,
98                                           hcx: &mut StableHashingContext<'a>,
99                                           hasher: &mut StableHasher<W>) {
100         self.index().hash_stable(hcx, hasher);
101     }
102 }
103
104 impl<'a> HashStable<StableHashingContext<'a>> for mir::Promoted {
105     #[inline]
106     fn hash_stable<W: StableHasherResult>(&self,
107                                           hcx: &mut StableHashingContext<'a>,
108                                           hasher: &mut StableHasher<W>) {
109         self.index().hash_stable(hcx, hasher);
110     }
111 }
112
113 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
114 for mir::TerminatorKind<'gcx> {
115     fn hash_stable<W: StableHasherResult>(&self,
116                                           hcx: &mut StableHashingContext<'a>,
117                                           hasher: &mut StableHasher<W>) {
118         mem::discriminant(self).hash_stable(hcx, hasher);
119
120         match *self {
121             mir::TerminatorKind::Goto { ref target } => {
122                 target.hash_stable(hcx, hasher);
123             }
124             mir::TerminatorKind::SwitchInt { ref discr,
125                                              switch_ty,
126                                              ref values,
127                                              ref targets } => {
128                 discr.hash_stable(hcx, hasher);
129                 switch_ty.hash_stable(hcx, hasher);
130                 values.hash_stable(hcx, hasher);
131                 targets.hash_stable(hcx, hasher);
132             }
133             mir::TerminatorKind::Resume |
134             mir::TerminatorKind::Abort |
135             mir::TerminatorKind::Return |
136             mir::TerminatorKind::GeneratorDrop |
137             mir::TerminatorKind::Unreachable => {}
138             mir::TerminatorKind::Drop { ref location, target, unwind } => {
139                 location.hash_stable(hcx, hasher);
140                 target.hash_stable(hcx, hasher);
141                 unwind.hash_stable(hcx, hasher);
142             }
143             mir::TerminatorKind::DropAndReplace { ref location,
144                                                   ref value,
145                                                   target,
146                                                   unwind, } => {
147                 location.hash_stable(hcx, hasher);
148                 value.hash_stable(hcx, hasher);
149                 target.hash_stable(hcx, hasher);
150                 unwind.hash_stable(hcx, hasher);
151             }
152             mir::TerminatorKind::Yield { ref value,
153                                         resume,
154                                         drop } => {
155                 value.hash_stable(hcx, hasher);
156                 resume.hash_stable(hcx, hasher);
157                 drop.hash_stable(hcx, hasher);
158             }
159             mir::TerminatorKind::Call { ref func,
160                                         ref args,
161                                         ref destination,
162                                         cleanup,
163                                         from_hir_call, } => {
164                 func.hash_stable(hcx, hasher);
165                 args.hash_stable(hcx, hasher);
166                 destination.hash_stable(hcx, hasher);
167                 cleanup.hash_stable(hcx, hasher);
168                 from_hir_call.hash_stable(hcx, hasher);
169             }
170             mir::TerminatorKind::Assert { ref cond,
171                                           expected,
172                                           ref msg,
173                                           target,
174                                           cleanup } => {
175                 cond.hash_stable(hcx, hasher);
176                 expected.hash_stable(hcx, hasher);
177                 msg.hash_stable(hcx, hasher);
178                 target.hash_stable(hcx, hasher);
179                 cleanup.hash_stable(hcx, hasher);
180             }
181             mir::TerminatorKind::FalseEdges { ref real_target, ref imaginary_targets } => {
182                 real_target.hash_stable(hcx, hasher);
183                 for target in imaginary_targets {
184                     target.hash_stable(hcx, hasher);
185                 }
186             }
187             mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => {
188                 real_target.hash_stable(hcx, hasher);
189                 unwind.hash_stable(hcx, hasher);
190             }
191         }
192     }
193 }
194
195 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
196
197 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
198 for mir::StatementKind<'gcx> {
199     fn hash_stable<W: StableHasherResult>(&self,
200                                           hcx: &mut StableHashingContext<'a>,
201                                           hasher: &mut StableHasher<W>) {
202         mem::discriminant(self).hash_stable(hcx, hasher);
203
204         match *self {
205             mir::StatementKind::Assign(ref place, ref rvalue) => {
206                 place.hash_stable(hcx, hasher);
207                 rvalue.hash_stable(hcx, hasher);
208             }
209             mir::StatementKind::FakeRead(ref cause, ref place) => {
210                 cause.hash_stable(hcx, hasher);
211                 place.hash_stable(hcx, hasher);
212             }
213             mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
214                 place.hash_stable(hcx, hasher);
215                 variant_index.hash_stable(hcx, hasher);
216             }
217             mir::StatementKind::StorageLive(ref place) |
218             mir::StatementKind::StorageDead(ref place) => {
219                 place.hash_stable(hcx, hasher);
220             }
221             mir::StatementKind::EscapeToRaw(ref place) => {
222                 place.hash_stable(hcx, hasher);
223             }
224             mir::StatementKind::Retag { fn_entry, ref place } => {
225                 fn_entry.hash_stable(hcx, hasher);
226                 place.hash_stable(hcx, hasher);
227             }
228             mir::StatementKind::AscribeUserType(ref place, ref variance, ref c_ty) => {
229                 place.hash_stable(hcx, hasher);
230                 variance.hash_stable(hcx, hasher);
231                 c_ty.hash_stable(hcx, hasher);
232             }
233             mir::StatementKind::Nop => {}
234             mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
235                 asm.hash_stable(hcx, hasher);
236                 outputs.hash_stable(hcx, hasher);
237                 inputs.hash_stable(hcx, hasher);
238             }
239         }
240     }
241 }
242
243 impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
244
245 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
246     fn hash_stable<W: StableHasherResult>(&self,
247                                           hcx: &mut StableHashingContext<'a>,
248                                           hasher: &mut StableHasher<W>) {
249         mem::discriminant(self).hash_stable(hcx, hasher);
250         match *self {
251             mir::Place::Local(ref local) => {
252                 local.hash_stable(hcx, hasher);
253             }
254             mir::Place::Static(ref statik) => {
255                 statik.hash_stable(hcx, hasher);
256             }
257             mir::Place::Promoted(ref promoted) => {
258                 promoted.hash_stable(hcx, hasher);
259             }
260             mir::Place::Projection(ref place_projection) => {
261                 place_projection.hash_stable(hcx, hasher);
262             }
263         }
264     }
265 }
266
267 impl<'a, 'gcx, B, V, T> HashStable<StableHashingContext<'a>>
268 for mir::Projection<'gcx, B, V, T>
269     where B: HashStable<StableHashingContext<'a>>,
270           V: HashStable<StableHashingContext<'a>>,
271           T: HashStable<StableHashingContext<'a>>
272 {
273     fn hash_stable<W: StableHasherResult>(&self,
274                                           hcx: &mut StableHashingContext<'a>,
275                                           hasher: &mut StableHasher<W>) {
276         let mir::Projection {
277             ref base,
278             ref elem,
279         } = *self;
280
281         base.hash_stable(hcx, hasher);
282         elem.hash_stable(hcx, hasher);
283     }
284 }
285
286 impl<'a, 'gcx, V, T> HashStable<StableHashingContext<'a>>
287 for mir::ProjectionElem<'gcx, V, T>
288     where V: HashStable<StableHashingContext<'a>>,
289           T: HashStable<StableHashingContext<'a>>
290 {
291     fn hash_stable<W: StableHasherResult>(&self,
292                                           hcx: &mut StableHashingContext<'a>,
293                                           hasher: &mut StableHasher<W>) {
294         mem::discriminant(self).hash_stable(hcx, hasher);
295         match *self {
296             mir::ProjectionElem::Deref => {}
297             mir::ProjectionElem::Field(field, ref ty) => {
298                 field.hash_stable(hcx, hasher);
299                 ty.hash_stable(hcx, hasher);
300             }
301             mir::ProjectionElem::Index(ref value) => {
302                 value.hash_stable(hcx, hasher);
303             }
304             mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
305                 offset.hash_stable(hcx, hasher);
306                 min_length.hash_stable(hcx, hasher);
307                 from_end.hash_stable(hcx, hasher);
308             }
309             mir::ProjectionElem::Subslice { from, to } => {
310                 from.hash_stable(hcx, hasher);
311                 to.hash_stable(hcx, hasher);
312             }
313             mir::ProjectionElem::Downcast(adt_def, variant) => {
314                 adt_def.hash_stable(hcx, hasher);
315                 variant.hash_stable(hcx, hasher);
316             }
317         }
318     }
319 }
320
321 impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
322 impl_stable_hash_for!(struct mir::SourceScopeLocalData {
323     lint_root, safety
324 });
325
326 impl<'a> HashStable<StableHashingContext<'a>> for mir::Safety {
327     fn hash_stable<W: StableHasherResult>(&self,
328                                           hcx: &mut StableHashingContext<'a>,
329                                           hasher: &mut StableHasher<W>) {
330         mem::discriminant(self).hash_stable(hcx, hasher);
331
332         match *self {
333             mir::Safety::Safe |
334             mir::Safety::BuiltinUnsafe |
335             mir::Safety::FnUnsafe => {}
336             mir::Safety::ExplicitUnsafe(node_id) => {
337                 node_id.hash_stable(hcx, hasher);
338             }
339         }
340     }
341 }
342
343 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Operand<'gcx> {
344     fn hash_stable<W: StableHasherResult>(&self,
345                                           hcx: &mut StableHashingContext<'a>,
346                                           hasher: &mut StableHasher<W>) {
347         mem::discriminant(self).hash_stable(hcx, hasher);
348
349         match *self {
350             mir::Operand::Copy(ref place) => {
351                 place.hash_stable(hcx, hasher);
352             }
353             mir::Operand::Move(ref place) => {
354                 place.hash_stable(hcx, hasher);
355             }
356             mir::Operand::Constant(ref constant) => {
357                 constant.hash_stable(hcx, hasher);
358             }
359         }
360     }
361 }
362
363 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
364     fn hash_stable<W: StableHasherResult>(&self,
365                                           hcx: &mut StableHashingContext<'a>,
366                                           hasher: &mut StableHasher<W>) {
367         mem::discriminant(self).hash_stable(hcx, hasher);
368
369         match *self {
370             mir::Rvalue::Use(ref operand) => {
371                 operand.hash_stable(hcx, hasher);
372             }
373             mir::Rvalue::Repeat(ref operand, ref val) => {
374                 operand.hash_stable(hcx, hasher);
375                 val.hash_stable(hcx, hasher);
376             }
377             mir::Rvalue::Ref(region, borrow_kind, ref place) => {
378                 region.hash_stable(hcx, hasher);
379                 borrow_kind.hash_stable(hcx, hasher);
380                 place.hash_stable(hcx, hasher);
381             }
382             mir::Rvalue::Len(ref place) => {
383                 place.hash_stable(hcx, hasher);
384             }
385             mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
386                 cast_kind.hash_stable(hcx, hasher);
387                 operand.hash_stable(hcx, hasher);
388                 ty.hash_stable(hcx, hasher);
389             }
390             mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
391             mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
392                 op.hash_stable(hcx, hasher);
393                 operand1.hash_stable(hcx, hasher);
394                 operand2.hash_stable(hcx, hasher);
395             }
396             mir::Rvalue::UnaryOp(op, ref operand) => {
397                 op.hash_stable(hcx, hasher);
398                 operand.hash_stable(hcx, hasher);
399             }
400             mir::Rvalue::Discriminant(ref place) => {
401                 place.hash_stable(hcx, hasher);
402             }
403             mir::Rvalue::NullaryOp(op, ty) => {
404                 op.hash_stable(hcx, hasher);
405                 ty.hash_stable(hcx, hasher);
406             }
407             mir::Rvalue::Aggregate(ref kind, ref operands) => {
408                 kind.hash_stable(hcx, hasher);
409                 operands.hash_stable(hcx, hasher);
410             }
411         }
412     }
413 }
414
415 impl_stable_hash_for!(enum mir::CastKind {
416     Misc,
417     ReifyFnPointer,
418     ClosureFnPointer,
419     UnsafeFnPointer,
420     Unsize
421 });
422
423 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
424 for mir::AggregateKind<'gcx> {
425     fn hash_stable<W: StableHasherResult>(&self,
426                                           hcx: &mut StableHashingContext<'a>,
427                                           hasher: &mut StableHasher<W>) {
428         mem::discriminant(self).hash_stable(hcx, hasher);
429         match *self {
430             mir::AggregateKind::Tuple => {}
431             mir::AggregateKind::Array(t) => {
432                 t.hash_stable(hcx, hasher);
433             }
434             mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => {
435                 adt_def.hash_stable(hcx, hasher);
436                 idx.hash_stable(hcx, hasher);
437                 substs.hash_stable(hcx, hasher);
438                 user_substs.hash_stable(hcx, hasher);
439                 active_field.hash_stable(hcx, hasher);
440             }
441             mir::AggregateKind::Closure(def_id, ref substs) => {
442                 def_id.hash_stable(hcx, hasher);
443                 substs.hash_stable(hcx, hasher);
444             }
445             mir::AggregateKind::Generator(def_id, ref substs, movability) => {
446                 def_id.hash_stable(hcx, hasher);
447                 substs.hash_stable(hcx, hasher);
448                 movability.hash_stable(hcx, hasher);
449             }
450         }
451     }
452 }
453
454 impl_stable_hash_for!(enum mir::BinOp {
455     Add,
456     Sub,
457     Mul,
458     Div,
459     Rem,
460     BitXor,
461     BitAnd,
462     BitOr,
463     Shl,
464     Shr,
465     Eq,
466     Lt,
467     Le,
468     Ne,
469     Ge,
470     Gt,
471     Offset
472 });
473
474 impl_stable_hash_for!(enum mir::UnOp {
475     Not,
476     Neg
477 });
478
479 impl_stable_hash_for!(enum mir::NullOp {
480     Box,
481     SizeOf
482 });
483
484 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal });
485
486 impl_stable_hash_for!(struct mir::Location { block, statement_index });
487
488 impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> {
489     closure_requirements,
490     used_mut_upvars
491 });
492
493 impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
494     num_external_vids,
495     outlives_requirements
496 });
497
498 impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
499     subject,
500     outlived_free_region,
501     blame_span,
502     category
503 });
504
505 impl_stable_hash_for!(enum mir::ConstraintCategory {
506     Return,
507     UseAsConst,
508     UseAsStatic,
509     TypeAnnotation,
510     Cast,
511     ClosureBounds,
512     CallArgument,
513     CopyBound,
514     SizedBound,
515     Assignment,
516     OpaqueType,
517     Boring,
518     BoringNoLocation,
519     Internal,
520 });
521
522 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {
523     fn hash_stable<W: StableHasherResult>(&self,
524                                           hcx: &mut StableHashingContext<'a>,
525                                           hasher: &mut StableHasher<W>) {
526         mem::discriminant(self).hash_stable(hcx, hasher);
527         match *self {
528             mir::ClosureOutlivesSubject::Ty(ref ty) => {
529                 ty.hash_stable(hcx, hasher);
530             }
531             mir::ClosureOutlivesSubject::Region(ref region) => {
532                 region.hash_stable(hcx, hasher);
533             }
534         }
535     }
536 }
537
538 impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });
539
540 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<'gcx> {
541     fn hash_stable<W: StableHasherResult>(&self,
542                                           hcx: &mut StableHashingContext<'a>,
543                                           hasher: &mut StableHasher<W>) {
544         mem::discriminant(self).hash_stable(hcx, hasher);
545         match *self {
546             mir::UserTypeAnnotation::Ty(ref ty) => {
547                 ty.hash_stable(hcx, hasher);
548             }
549             mir::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => {
550                 def_id.hash_stable(hcx, hasher);
551                 substs.hash_stable(hcx, hasher);
552             }
553         }
554     }
555 }
556
557 impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs });
558 impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents });