]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/impls_mir.rs
Auto merge of #42167 - scottmcm:iter-stepby-sizehint, r=alexcrichton
[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
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> { mutability, ty, name, source_info,
26 is_user_variable});
27 impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref });
28 impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
29 impl_stable_hash_for!(struct mir::Terminator<'tcx> { source_info, kind });
30
31 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Local {
32     #[inline]
33     fn hash_stable<W: StableHasherResult>(&self,
34                                           hcx: &mut StableHashingContext<'a, 'tcx>,
35                                           hasher: &mut StableHasher<W>) {
36         use rustc_data_structures::indexed_vec::Idx;
37         self.index().hash_stable(hcx, hasher);
38     }
39 }
40
41 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::BasicBlock {
42     #[inline]
43     fn hash_stable<W: StableHasherResult>(&self,
44                                           hcx: &mut StableHashingContext<'a, 'tcx>,
45                                           hasher: &mut StableHasher<W>) {
46         use rustc_data_structures::indexed_vec::Idx;
47         self.index().hash_stable(hcx, hasher);
48     }
49 }
50
51 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Field {
52     #[inline]
53     fn hash_stable<W: StableHasherResult>(&self,
54                                           hcx: &mut StableHashingContext<'a, 'tcx>,
55                                           hasher: &mut StableHasher<W>) {
56         use rustc_data_structures::indexed_vec::Idx;
57         self.index().hash_stable(hcx, hasher);
58     }
59 }
60
61 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::VisibilityScope {
62     #[inline]
63     fn hash_stable<W: StableHasherResult>(&self,
64                                           hcx: &mut StableHashingContext<'a, 'tcx>,
65                                           hasher: &mut StableHasher<W>) {
66         use rustc_data_structures::indexed_vec::Idx;
67         self.index().hash_stable(hcx, hasher);
68     }
69 }
70
71 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Promoted {
72     #[inline]
73     fn hash_stable<W: StableHasherResult>(&self,
74                                           hcx: &mut StableHashingContext<'a, 'tcx>,
75                                           hasher: &mut StableHasher<W>) {
76         use rustc_data_structures::indexed_vec::Idx;
77         self.index().hash_stable(hcx, hasher);
78     }
79 }
80
81 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::TerminatorKind<'tcx> {
82     fn hash_stable<W: StableHasherResult>(&self,
83                                           hcx: &mut StableHashingContext<'a, 'tcx>,
84                                           hasher: &mut StableHasher<W>) {
85         mem::discriminant(self).hash_stable(hcx, hasher);
86
87         match *self {
88             mir::TerminatorKind::Goto { ref target } => {
89                 target.hash_stable(hcx, hasher);
90             }
91             mir::TerminatorKind::SwitchInt { ref discr,
92                                              switch_ty,
93                                              ref values,
94                                              ref targets } => {
95                 discr.hash_stable(hcx, hasher);
96                 switch_ty.hash_stable(hcx, hasher);
97                 values.hash_stable(hcx, hasher);
98                 targets.hash_stable(hcx, hasher);
99             }
100             mir::TerminatorKind::Resume |
101             mir::TerminatorKind::Return |
102             mir::TerminatorKind::Unreachable => {}
103             mir::TerminatorKind::Drop { ref location, target, unwind } => {
104                 location.hash_stable(hcx, hasher);
105                 target.hash_stable(hcx, hasher);
106                 unwind.hash_stable(hcx, hasher);
107             }
108             mir::TerminatorKind::DropAndReplace { ref location,
109                                                   ref value,
110                                                   target,
111                                                   unwind, } => {
112                 location.hash_stable(hcx, hasher);
113                 value.hash_stable(hcx, hasher);
114                 target.hash_stable(hcx, hasher);
115                 unwind.hash_stable(hcx, hasher);
116             }
117             mir::TerminatorKind::Call { ref func,
118                                         ref args,
119                                         ref destination,
120                                         cleanup } => {
121                 func.hash_stable(hcx, hasher);
122                 args.hash_stable(hcx, hasher);
123                 destination.hash_stable(hcx, hasher);
124                 cleanup.hash_stable(hcx, hasher);
125             }
126             mir::TerminatorKind::Assert { ref cond,
127                                           expected,
128                                           ref msg,
129                                           target,
130                                           cleanup } => {
131                 cond.hash_stable(hcx, hasher);
132                 expected.hash_stable(hcx, hasher);
133                 msg.hash_stable(hcx, hasher);
134                 target.hash_stable(hcx, hasher);
135                 cleanup.hash_stable(hcx, hasher);
136             }
137         }
138     }
139 }
140
141 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::AssertMessage<'tcx> {
142     fn hash_stable<W: StableHasherResult>(&self,
143                                           hcx: &mut StableHashingContext<'a, 'tcx>,
144                                           hasher: &mut StableHasher<W>) {
145         mem::discriminant(self).hash_stable(hcx, hasher);
146
147         match *self {
148             mir::AssertMessage::BoundsCheck { ref len, ref index } => {
149                 len.hash_stable(hcx, hasher);
150                 index.hash_stable(hcx, hasher);
151             }
152             mir::AssertMessage::Math(ref const_math_err) => {
153                 const_math_err.hash_stable(hcx, hasher);
154             }
155         }
156     }
157 }
158
159 impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind });
160
161 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::StatementKind<'tcx> {
162     fn hash_stable<W: StableHasherResult>(&self,
163                                           hcx: &mut StableHashingContext<'a, 'tcx>,
164                                           hasher: &mut StableHasher<W>) {
165         mem::discriminant(self).hash_stable(hcx, hasher);
166
167         match *self {
168             mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
169                 lvalue.hash_stable(hcx, hasher);
170                 rvalue.hash_stable(hcx, hasher);
171             }
172             mir::StatementKind::SetDiscriminant { ref lvalue, variant_index } => {
173                 lvalue.hash_stable(hcx, hasher);
174                 variant_index.hash_stable(hcx, hasher);
175             }
176             mir::StatementKind::StorageLive(ref lvalue) |
177             mir::StatementKind::StorageDead(ref lvalue) => {
178                 lvalue.hash_stable(hcx, hasher);
179             }
180             mir::StatementKind::Nop => {}
181             mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
182                 asm.hash_stable(hcx, hasher);
183                 outputs.hash_stable(hcx, hasher);
184                 inputs.hash_stable(hcx, hasher);
185             }
186         }
187     }
188 }
189
190 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Lvalue<'tcx> {
191     fn hash_stable<W: StableHasherResult>(&self,
192                                           hcx: &mut StableHashingContext<'a, 'tcx>,
193                                           hasher: &mut StableHasher<W>) {
194         mem::discriminant(self).hash_stable(hcx, hasher);
195         match *self {
196             mir::Lvalue::Local(ref local) => {
197                 local.hash_stable(hcx, hasher);
198             }
199             mir::Lvalue::Static(ref statik) => {
200                 statik.hash_stable(hcx, hasher);
201             }
202             mir::Lvalue::Projection(ref lvalue_projection) => {
203                 lvalue_projection.hash_stable(hcx, hasher);
204             }
205         }
206     }
207 }
208
209 impl<'a, 'tcx, B, V> HashStable<StableHashingContext<'a, 'tcx>> for mir::Projection<'tcx, B, V>
210     where B: HashStable<StableHashingContext<'a, 'tcx>>,
211           V: HashStable<StableHashingContext<'a, 'tcx>>
212 {
213     fn hash_stable<W: StableHasherResult>(&self,
214                                           hcx: &mut StableHashingContext<'a, 'tcx>,
215                                           hasher: &mut StableHasher<W>) {
216         let mir::Projection {
217             ref base,
218             ref elem,
219         } = *self;
220
221         base.hash_stable(hcx, hasher);
222         elem.hash_stable(hcx, hasher);
223     }
224 }
225
226 impl<'a, 'tcx, V> HashStable<StableHashingContext<'a, 'tcx>> for mir::ProjectionElem<'tcx, V>
227     where V: HashStable<StableHashingContext<'a, 'tcx>>
228 {
229     fn hash_stable<W: StableHasherResult>(&self,
230                                           hcx: &mut StableHashingContext<'a, 'tcx>,
231                                           hasher: &mut StableHasher<W>) {
232         mem::discriminant(self).hash_stable(hcx, hasher);
233         match *self {
234             mir::ProjectionElem::Deref => {}
235             mir::ProjectionElem::Field(field, ty) => {
236                 field.hash_stable(hcx, hasher);
237                 ty.hash_stable(hcx, hasher);
238             }
239             mir::ProjectionElem::Index(ref value) => {
240                 value.hash_stable(hcx, hasher);
241             }
242             mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
243                 offset.hash_stable(hcx, hasher);
244                 min_length.hash_stable(hcx, hasher);
245                 from_end.hash_stable(hcx, hasher);
246             }
247             mir::ProjectionElem::Subslice { from, to } => {
248                 from.hash_stable(hcx, hasher);
249                 to.hash_stable(hcx, hasher);
250             }
251             mir::ProjectionElem::Downcast(adt_def, variant) => {
252                 adt_def.hash_stable(hcx, hasher);
253                 variant.hash_stable(hcx, hasher);
254             }
255         }
256     }
257 }
258
259 impl_stable_hash_for!(struct mir::VisibilityScopeData { span, parent_scope });
260
261 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Operand<'tcx> {
262     fn hash_stable<W: StableHasherResult>(&self,
263                                           hcx: &mut StableHashingContext<'a, 'tcx>,
264                                           hasher: &mut StableHasher<W>) {
265         mem::discriminant(self).hash_stable(hcx, hasher);
266
267         match *self {
268             mir::Operand::Consume(ref lvalue) => {
269                 lvalue.hash_stable(hcx, hasher);
270             }
271             mir::Operand::Constant(ref constant) => {
272                 constant.hash_stable(hcx, hasher);
273             }
274         }
275     }
276 }
277
278 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Rvalue<'tcx> {
279     fn hash_stable<W: StableHasherResult>(&self,
280                                           hcx: &mut StableHashingContext<'a, 'tcx>,
281                                           hasher: &mut StableHasher<W>) {
282         mem::discriminant(self).hash_stable(hcx, hasher);
283
284         match *self {
285             mir::Rvalue::Use(ref operand) => {
286                 operand.hash_stable(hcx, hasher);
287             }
288             mir::Rvalue::Repeat(ref operand, ref val) => {
289                 operand.hash_stable(hcx, hasher);
290                 val.hash_stable(hcx, hasher);
291             }
292             mir::Rvalue::Ref(region, borrow_kind, ref lvalue) => {
293                 region.hash_stable(hcx, hasher);
294                 borrow_kind.hash_stable(hcx, hasher);
295                 lvalue.hash_stable(hcx, hasher);
296             }
297             mir::Rvalue::Len(ref lvalue) => {
298                 lvalue.hash_stable(hcx, hasher);
299             }
300             mir::Rvalue::Cast(cast_kind, ref operand, ty) => {
301                 cast_kind.hash_stable(hcx, hasher);
302                 operand.hash_stable(hcx, hasher);
303                 ty.hash_stable(hcx, hasher);
304             }
305             mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) |
306             mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => {
307                 op.hash_stable(hcx, hasher);
308                 operand1.hash_stable(hcx, hasher);
309                 operand2.hash_stable(hcx, hasher);
310             }
311             mir::Rvalue::UnaryOp(op, ref operand) => {
312                 op.hash_stable(hcx, hasher);
313                 operand.hash_stable(hcx, hasher);
314             }
315             mir::Rvalue::Discriminant(ref lvalue) => {
316                 lvalue.hash_stable(hcx, hasher);
317             }
318             mir::Rvalue::NullaryOp(op, ty) => {
319                 op.hash_stable(hcx, hasher);
320                 ty.hash_stable(hcx, hasher);
321             }
322             mir::Rvalue::Aggregate(ref kind, ref operands) => {
323                 kind.hash_stable(hcx, hasher);
324                 operands.hash_stable(hcx, hasher);
325             }
326         }
327     }
328 }
329
330 impl_stable_hash_for!(enum mir::CastKind {
331     Misc,
332     ReifyFnPointer,
333     ClosureFnPointer,
334     UnsafeFnPointer,
335     Unsize
336 });
337
338 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::AggregateKind<'tcx> {
339     fn hash_stable<W: StableHasherResult>(&self,
340                                           hcx: &mut StableHashingContext<'a, 'tcx>,
341                                           hasher: &mut StableHasher<W>) {
342         mem::discriminant(self).hash_stable(hcx, hasher);
343         match *self {
344             mir::AggregateKind::Tuple => {}
345             mir::AggregateKind::Array(t) => {
346                 t.hash_stable(hcx, hasher);
347             }
348             mir::AggregateKind::Adt(adt_def, idx, substs, active_field) => {
349                 adt_def.hash_stable(hcx, hasher);
350                 idx.hash_stable(hcx, hasher);
351                 substs.hash_stable(hcx, hasher);
352                 active_field.hash_stable(hcx, hasher);
353             }
354             mir::AggregateKind::Closure(def_id, ref substs) => {
355                 def_id.hash_stable(hcx, hasher);
356                 substs.hash_stable(hcx, hasher);
357             }
358         }
359     }
360 }
361
362 impl_stable_hash_for!(enum mir::BinOp {
363     Add,
364     Sub,
365     Mul,
366     Div,
367     Rem,
368     BitXor,
369     BitAnd,
370     BitOr,
371     Shl,
372     Shr,
373     Eq,
374     Lt,
375     Le,
376     Ne,
377     Ge,
378     Gt,
379     Offset
380 });
381
382 impl_stable_hash_for!(enum mir::UnOp {
383     Not,
384     Neg
385 });
386
387 impl_stable_hash_for!(enum mir::NullOp {
388     Box,
389     SizeOf
390 });
391
392 impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, literal });
393
394 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for mir::Literal<'tcx> {
395     fn hash_stable<W: StableHasherResult>(&self,
396                                           hcx: &mut StableHashingContext<'a, 'tcx>,
397                                           hasher: &mut StableHasher<W>) {
398         mem::discriminant(self).hash_stable(hcx, hasher);
399         match *self {
400             mir::Literal::Item { def_id, substs } => {
401                 def_id.hash_stable(hcx, hasher);
402                 substs.hash_stable(hcx, hasher);
403             }
404             mir::Literal::Value { ref value } => {
405                 value.hash_stable(hcx, hasher);
406             }
407             mir::Literal::Promoted { index } => {
408                 index.hash_stable(hcx, hasher);
409             }
410         }
411     }
412 }
413
414 impl_stable_hash_for!(struct mir::Location { block, statement_index });