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