diff options
| author | Bruno Dutra <brunocodutra@gmail.com> | 2018-07-28 19:11:47 +0200 |
|---|---|---|
| committer | Bruno Dutra <brunocodutra@gmail.com> | 2018-09-03 20:02:35 +0200 |
| commit | 030077401d6b7c2f923b24271dc5dc80044b089a (patch) | |
| tree | 5c3b16df096b5f67a5e765093c0dc3f0451b5ece /src | |
| parent | 7fa42beef8d385e5eccf7ad86dcf022dfca1c0ac (diff) | |
| download | rust-030077401d6b7c2f923b24271dc5dc80044b089a.tar.gz rust-030077401d6b7c2f923b24271dc5dc80044b089a.zip | |
Promote EvalSnapshot to newtype
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/eval_context.rs | 27 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/step.rs | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 6e144ba7ed2..467634f2896 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -196,8 +196,24 @@ impl<'tcx> LocalValue { } /// The virtual machine state during const-evaluation at a given point in time. -type EvalSnapshot<'a, 'mir, 'tcx, M> - = (M, Vec<Frame<'mir, 'tcx>>, Memory<'a, 'mir, 'tcx, M>); +#[derive(Eq, PartialEq, Hash)] +pub(crate) struct EvalSnapshot<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { + machine: M, + memory: Memory<'a, 'mir, 'tcx, M>, + stack: Vec<Frame<'mir, 'tcx>>, +} + +impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M> + where M: Machine<'mir, 'tcx>, +{ + fn new<'b>(machine: &M, memory: &Memory<'a, 'mir, 'tcx, M>, stack: &[Frame<'mir, 'tcx>]) -> Self { + EvalSnapshot { + machine: machine.clone(), + memory: memory.clone(), + stack: stack.into(), + } + } +} pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { /// The set of all `EvalSnapshot` *hashes* observed by this detector. @@ -238,13 +254,12 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M> pub fn observe_and_analyze( &mut self, machine: &M, - stack: &Vec<Frame<'mir, 'tcx>>, memory: &Memory<'a, 'mir, 'tcx, M>, + stack: &[Frame<'mir, 'tcx>], ) -> EvalResult<'tcx, ()> { - let snapshot = (machine, stack, memory); let mut fx = FxHasher::default(); - snapshot.hash(&mut fx); + (machine, memory, stack).hash(&mut fx); let hash = fx.finish(); if self.hashes.insert(hash) { @@ -252,7 +267,7 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M> return Ok(()) } - if self.snapshots.insert((machine.clone(), stack.clone(), memory.clone())) { + if self.snapshots.insert(EvalSnapshot::new(machine, memory, stack)) { // Spurious collision or first cycle return Ok(()) } diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 114ef093ec2..f3d655c2651 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -73,7 +73,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { "Constant evaluating a complex constant, this might take some time"); } - self.loop_detector.observe_and_analyze(&self.machine, &self.stack, &self.memory) + self.loop_detector.observe_and_analyze(&self.machine, &self.memory, &self.stack[..]) } pub fn run(&mut self) -> EvalResult<'tcx> { |
