|
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | 11 | use std::fmt::Write; |
12 | | -use std::hash::{Hash, Hasher}; |
13 | 12 | use std::mem; |
14 | 13 |
|
15 | 14 | use rustc::hir::def_id::DefId; |
@@ -40,6 +39,8 @@ use super::{ |
40 | 39 | Memory, Machine |
41 | 40 | }; |
42 | 41 |
|
| 42 | +use super::snapshot::EvalSnapshot; |
| 43 | + |
43 | 44 | pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { |
44 | 45 | /// Stores the `Machine` instance. |
45 | 46 | pub machine: M, |
@@ -207,47 +208,6 @@ impl_stable_hash_for!(enum self::LocalValue { |
207 | 208 | Live(x), |
208 | 209 | }); |
209 | 210 |
|
210 | | -/// The virtual machine state during const-evaluation at a given point in time. |
211 | | -#[derive(Eq, PartialEq)] |
212 | | -struct EvalSnapshot<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { |
213 | | - machine: M, |
214 | | - memory: Memory<'a, 'mir, 'tcx, M>, |
215 | | - stack: Vec<Frame<'mir, 'tcx>>, |
216 | | -} |
217 | | - |
218 | | -impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M> |
219 | | - where M: Machine<'mir, 'tcx>, |
220 | | -{ |
221 | | - fn new<'b>(machine: &M, memory: &Memory<'a, 'mir, 'tcx, M>, stack: &[Frame<'mir, 'tcx>]) -> Self { |
222 | | - EvalSnapshot { |
223 | | - machine: machine.clone(), |
224 | | - memory: memory.clone(), |
225 | | - stack: stack.into(), |
226 | | - } |
227 | | - } |
228 | | -} |
229 | | - |
230 | | -impl<'a, 'mir, 'tcx, M> Hash for EvalSnapshot<'a, 'mir, 'tcx, M> |
231 | | - where M: Machine<'mir, 'tcx>, |
232 | | -{ |
233 | | - fn hash<H: Hasher>(&self, state: &mut H) { |
234 | | - // Implement in terms of hash stable, so that k1 == k2 -> hash(k1) == hash(k2) |
235 | | - let mut hcx = self.memory.tcx.get_stable_hashing_context(); |
236 | | - let mut hasher = StableHasher::<u64>::new(); |
237 | | - self.hash_stable(&mut hcx, &mut hasher); |
238 | | - hasher.finish().hash(state) |
239 | | - } |
240 | | -} |
241 | | - |
242 | | -impl<'a, 'b, 'mir, 'tcx, M> HashStable<StableHashingContext<'b>> for EvalSnapshot<'a, 'mir, 'tcx, M> |
243 | | - where M: Machine<'mir, 'tcx>, |
244 | | -{ |
245 | | - fn hash_stable<W: StableHasherResult>(&self, hcx: &mut StableHashingContext<'b>, hasher: &mut StableHasher<W>) { |
246 | | - let EvalSnapshot{ machine, memory, stack } = self; |
247 | | - (machine, &memory.data, stack).hash_stable(hcx, hasher); |
248 | | - } |
249 | | -} |
250 | | - |
251 | 211 | pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { |
252 | 212 | /// The set of all `EvalSnapshot` *hashes* observed by this detector. |
253 | 213 | /// |
|
0 commit comments