about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBruno Dutra <brunocodutra@gmail.com>2018-08-04 17:41:03 +0200
committerBruno Dutra <brunocodutra@gmail.com>2018-09-03 20:02:35 +0200
commit015f470daa3020ebe92abf61fa4010b56bde006d (patch)
tree20c70850490079eb58291084255e087c3f2204fb
parenta083aa02edf0a3cb963dc71aea1509afe6e179a0 (diff)
downloadrust-015f470daa3020ebe92abf61fa4010b56bde006d.tar.gz
rust-015f470daa3020ebe92abf61fa4010b56bde006d.zip
Move EvalSnapshot into its own module
-rw-r--r--src/librustc_mir/interpret/eval_context.rs44
-rw-r--r--src/librustc_mir/interpret/mod.rs1
-rw-r--r--src/librustc_mir/interpret/snapshot.rs47
3 files changed, 50 insertions, 42 deletions
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 8d4f3baf3a9..b6a84ed8404 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use std::fmt::Write;
-use std::hash::{Hash, Hasher};
 use std::mem;
 
 use rustc::hir::def_id::DefId;
@@ -40,6 +39,8 @@ use super::{
     Memory, Machine
 };
 
+use super::snapshot::EvalSnapshot;
+
 pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
     /// Stores the `Machine` instance.
     pub machine: M,
@@ -207,47 +208,6 @@ impl_stable_hash_for!(enum self::LocalValue {
     Live(x),
 });
 
-/// The virtual machine state during const-evaluation at a given point in time.
-#[derive(Eq, PartialEq)]
-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(),
-        }
-    }
-}
-
-impl<'a, 'mir, 'tcx, M> Hash for EvalSnapshot<'a, 'mir, 'tcx, M>
-    where M: Machine<'mir, 'tcx>,
-{
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        // Implement in terms of hash stable, so that k1 == k2 -> hash(k1) == hash(k2)
-        let mut hcx = self.memory.tcx.get_stable_hashing_context();
-        let mut hasher = StableHasher::<u64>::new();
-        self.hash_stable(&mut hcx, &mut hasher);
-        hasher.finish().hash(state)
-    }
-}
-
-impl<'a, 'b, 'mir, 'tcx, M> HashStable<StableHashingContext<'b>> for EvalSnapshot<'a, 'mir, 'tcx, M>
-    where M: Machine<'mir, 'tcx>,
-{
-    fn hash_stable<W: StableHasherResult>(&self, hcx: &mut StableHashingContext<'b>, hasher: &mut StableHasher<W>) {
-        let EvalSnapshot{ machine, memory, stack } = self;
-        (machine, &memory.data, stack).hash_stable(hcx, hasher);
-    }
-}
-
 pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
     /// The set of all `EvalSnapshot` *hashes* observed by this detector.
     ///
diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs
index 462c4b8889d..1e8de029232 100644
--- a/src/librustc_mir/interpret/mod.rs
+++ b/src/librustc_mir/interpret/mod.rs
@@ -17,6 +17,7 @@ mod operand;
 mod machine;
 mod memory;
 mod operator;
+mod snapshot;
 mod step;
 mod terminator;
 mod traits;
diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs
new file mode 100644
index 00000000000..45574da7410
--- /dev/null
+++ b/src/librustc_mir/interpret/snapshot.rs
@@ -0,0 +1,47 @@
+use std::hash::{Hash, Hasher};
+
+use rustc::ich::{StableHashingContext, StableHashingContextProvider};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
+
+use super::{Frame, Memory, Machine};
+
+/// The virtual machine state during const-evaluation at a given point in time.
+#[derive(Eq, PartialEq)]
+pub 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>,
+{
+    pub fn new(machine: &M, memory: &Memory<'a, 'mir, 'tcx, M>, stack: &[Frame<'mir, 'tcx>]) -> Self {
+        EvalSnapshot {
+            machine: machine.clone(),
+            memory: memory.clone(),
+            stack: stack.into(),
+        }
+    }
+}
+
+impl<'a, 'mir, 'tcx, M> Hash for EvalSnapshot<'a, 'mir, 'tcx, M>
+    where M: Machine<'mir, 'tcx>,
+{
+    fn hash<H: Hasher>(&self, state: &mut H) {
+        // Implement in terms of hash stable, so that k1 == k2 -> hash(k1) == hash(k2)
+        let mut hcx = self.memory.tcx.get_stable_hashing_context();
+        let mut hasher = StableHasher::<u64>::new();
+        self.hash_stable(&mut hcx, &mut hasher);
+        hasher.finish().hash(state)
+    }
+}
+
+impl<'a, 'b, 'mir, 'tcx, M> HashStable<StableHashingContext<'b>> for EvalSnapshot<'a, 'mir, 'tcx, M>
+    where M: Machine<'mir, 'tcx>,
+{
+    fn hash_stable<W: StableHasherResult>(&self, hcx: &mut StableHashingContext<'b>, hasher: &mut StableHasher<W>) {
+        let EvalSnapshot{ machine, memory, stack } = self;
+        (machine, &memory.data, stack).hash_stable(hcx, hasher);
+    }
+}