about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBruno Dutra <brunocodutra@gmail.com>2018-08-18 14:10:46 +0200
committerBruno Dutra <brunocodutra@gmail.com>2018-09-03 20:02:35 +0200
commit927c709eb99e5243975db2ddc6c40cb06a6f472c (patch)
tree482cd97e477ca07b6c5f54b19f0249be1e9d3314 /src
parentbf6ba974dede851b59afb9aa031ce0c548b754c4 (diff)
downloadrust-927c709eb99e5243975db2ddc6c40cb06a6f472c.tar.gz
rust-927c709eb99e5243975db2ddc6c40cb06a6f472c.zip
Impl Eq and PartialEq for EvalSnapshot in terms of the Snapshot trait
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/interpret/eval_context.rs26
-rw-r--r--src/librustc_mir/interpret/memory.rs21
-rw-r--r--src/librustc_mir/interpret/snapshot.rs67
3 files changed, 45 insertions, 69 deletions
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 02d87bdb7dc..cc6d6d433f8 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -111,32 +111,6 @@ pub struct Frame<'mir, 'tcx: 'mir> {
     pub stmt: usize,
 }
 
-impl<'mir, 'tcx: 'mir> Eq for Frame<'mir, 'tcx> {}
-
-impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
-    fn eq(&self, other: &Self) -> bool {
-        let Frame {
-            mir: _,
-            instance,
-            span: _,
-            return_to_block,
-            return_place,
-            locals,
-            block,
-            stmt,
-        } = self;
-
-        // Some of these are constant during evaluation, but are included
-        // anyways for correctness.
-        *instance == other.instance
-            && *return_to_block == other.return_to_block
-            && *return_place == other.return_place
-            && *locals == other.locals
-            && *block == other.block
-            && *stmt == other.stmt
-    }
-}
-
 impl<'a, 'mir, 'tcx: 'mir> HashStable<StableHashingContext<'a>> for Frame<'mir, 'tcx> {
     fn hash_stable<W: StableHasherResult>(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher<W>) {
         let Frame {
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index 4a291f164cc..9e61de92936 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -69,27 +69,6 @@ impl<'a, 'b, 'c, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout
     }
 }
 
-impl<'a, 'mir, 'tcx, M> Eq for Memory<'a, 'mir, 'tcx, M>
-    where M: Machine<'mir, 'tcx>,
-          'tcx: 'a + 'mir,
-{}
-
-impl<'a, 'mir, 'tcx, M> PartialEq for Memory<'a, 'mir, 'tcx, M>
-    where M: Machine<'mir, 'tcx>,
-          'tcx: 'a + 'mir,
-{
-    fn eq(&self, other: &Self) -> bool {
-        let Memory {
-            data,
-            alloc_map,
-            tcx: _,
-        } = self;
-
-        *data == other.data
-            && *alloc_map == other.alloc_map
-    }
-}
-
 impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
     pub fn new(tcx: TyCtxtAt<'a, 'tcx, 'tcx>, data: M::MemoryData) -> Self {
         Memory {
diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs
index d23122825aa..66364a7390c 100644
--- a/src/librustc_mir/interpret/snapshot.rs
+++ b/src/librustc_mir/interpret/snapshot.rs
@@ -11,7 +11,7 @@ use syntax::ast::Mutability;
 use syntax::source_map::Span;
 
 use super::eval_context::{LocalValue, StackPopCleanup};
-use super::{Frame, Memory, Machine, Operand, MemPlace, Place, PlaceExtra, Value};
+use super::{Frame, Memory, Machine, Operand, MemPlace, Place, Value};
 
 trait SnapshotContext<'a> {
     type To;
@@ -24,6 +24,20 @@ trait Snapshot<'a, Ctx: SnapshotContext<'a>> {
     fn snapshot(&self, ctx: &'a Ctx) -> Self::Item;
 }
 
+impl<'a, Ctx, T> Snapshot<'a, Ctx> for Option<T>
+    where Ctx: SnapshotContext<'a>,
+          T: Snapshot<'a, Ctx>
+{
+    type Item = Option<<T as Snapshot<'a, Ctx>>::Item>;
+
+    fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
+        match self {
+            Some(x) => Some(x.snapshot(ctx)),
+            None => None,
+        }
+    }
+}
+
 #[derive(Eq, PartialEq)]
 struct AllocIdSnapshot<'a>(Option<AllocationSnapshot<'a>>);
 
@@ -124,22 +138,6 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Place
     }
 }
 
-type PlaceExtraSnapshot<'a> = PlaceExtra<AllocIdSnapshot<'a>>;
-
-impl<'a, Ctx> Snapshot<'a, Ctx> for PlaceExtra
-    where Ctx: SnapshotContext<'a, To=Allocation, From=AllocId>,
-{
-    type Item = PlaceExtraSnapshot<'a>;
-
-    fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
-        match self {
-            PlaceExtra::Vtable(p) => PlaceExtra::Vtable(p.snapshot(ctx)),
-            PlaceExtra::Length(l) => PlaceExtra::Length(*l),
-            PlaceExtra::None => PlaceExtra::None,
-        }
-    }
-}
-
 type ValueSnapshot<'a> = Value<AllocIdSnapshot<'a>>;
 
 impl<'a, Ctx> Snapshot<'a, Ctx> for Value
@@ -203,7 +201,7 @@ struct AllocationSnapshot<'a> {
     relocations: RelocationsSnapshot<'a>,
     undef_mask: &'a UndefMask,
     align: &'a Align,
-    runtime_mutability: &'a Mutability,
+    mutability: &'a Mutability,
 }
 
 impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
@@ -212,20 +210,20 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
     type Item = AllocationSnapshot<'a>;
 
     fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
-        let Allocation { bytes, relocations, undef_mask, align, runtime_mutability } = self;
+        let Allocation { bytes, relocations, undef_mask, align, mutability } = self;
 
         AllocationSnapshot {
             bytes,
             undef_mask,
             align,
-            runtime_mutability,
+            mutability,
             relocations: relocations.snapshot(ctx),
         }
     }
 }
 
 #[derive(Eq, PartialEq)]
-struct FrameSnapshot<'a, 'tcx> {
+struct FrameSnapshot<'a, 'tcx: 'a> {
     instance: &'a ty::Instance<'tcx>,
     span: &'a Span,
     return_to_block: &'a StackPopCleanup,
@@ -269,6 +267,15 @@ struct MemorySnapshot<'a, 'mir: 'a, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx> + 'a
     data: &'a M::MemoryData,
 }
 
+impl<'a, 'mir, 'tcx, M> Memory<'a, 'mir, 'tcx, M>
+    where M: Machine<'mir, 'tcx>,
+{
+    fn snapshot<'b: 'a>(&'b self) -> MemorySnapshot<'b, 'mir, 'tcx, M> {
+        let Memory { data, .. } = self;
+        MemorySnapshot { data }
+    }
+}
+
 impl<'a, 'b, 'mir, 'tcx, M> SnapshotContext<'b> for Memory<'a, 'mir, 'tcx, M>
     where M: Machine<'mir, 'tcx>,
 {
@@ -280,7 +287,6 @@ impl<'a, 'b, 'mir, 'tcx, M> SnapshotContext<'b> for Memory<'a, 'mir, 'tcx, M>
 }
 
 /// 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>,
@@ -297,6 +303,11 @@ impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
             stack: stack.into(),
         }
     }
+
+    fn snapshot<'b: 'a>(&'b self) -> (&'b M, MemorySnapshot<'b, 'mir, 'tcx, M>, Vec<FrameSnapshot<'a, 'tcx>>) {
+        let EvalSnapshot{ machine, memory, stack } = self;
+        (&machine, memory.snapshot(), stack.iter().map(|frame| frame.snapshot(memory)).collect())
+    }
 }
 
 impl<'a, 'mir, 'tcx, M> Hash for EvalSnapshot<'a, 'mir, 'tcx, M>
@@ -319,3 +330,15 @@ impl<'a, 'b, 'mir, 'tcx, M> HashStable<StableHashingContext<'b>> for EvalSnapsho
         (machine, &memory.data, stack).hash_stable(hcx, hasher);
     }
 }
+
+impl<'a, 'mir, 'tcx, M> Eq for EvalSnapshot<'a, 'mir, 'tcx, M>
+    where M: Machine<'mir, 'tcx>,
+{}
+
+impl<'a, 'mir, 'tcx, M> PartialEq for EvalSnapshot<'a, 'mir, 'tcx, M>
+    where M: Machine<'mir, 'tcx>,
+{
+    fn eq(&self, other: &Self) -> bool {
+        self.snapshot() == other.snapshot()
+    }
+}