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