about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2018-06-22 13:31:25 -0700
committerDylan MacKenzie <ecstaticmorse@gmail.com>2018-07-04 14:36:07 -0700
commit0f1c61cb7f20d8600e334bdd13e39c0eeb313d15 (patch)
tree70b429fe88196f87773af80f60f3ebe8993a8912
parent788c5f3c8b1453d5c7815bc345b8b7e7f79ebf80 (diff)
downloadrust-0f1c61cb7f20d8600e334bdd13e39c0eeb313d15.tar.gz
rust-0f1c61cb7f20d8600e334bdd13e39c0eeb313d15.zip
Improve correctness of `Frame` and `Memory` equality
Incorporate a subset of the suggestions from @oli-obk. More to come.
-rw-r--r--src/librustc_mir/interpret/eval_context.rs18
-rw-r--r--src/librustc_mir/interpret/memory.rs6
2 files changed, 12 insertions, 12 deletions
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 85aeb3c7df5..e3024e069d9 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -1,6 +1,6 @@
 use std::fmt::Write;
 use std::hash::{Hash, Hasher};
-use std::{mem, ptr};
+use std::mem;
 
 use rustc::hir::def_id::DefId;
 use rustc::hir::def::Def;
@@ -98,8 +98,8 @@ 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: _,
+            mir: _,
+            instance,
             span: _,
             return_to_block,
             return_place,
@@ -108,8 +108,10 @@ impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
             stmt,
         } = self;
 
-        ptr::eq(mir, &other.mir)
-            && *return_to_block == other.return_to_block // TODO: Are these two necessary?
+        // 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
@@ -120,8 +122,8 @@ impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
 impl<'mir, 'tcx: 'mir> Hash for Frame<'mir, 'tcx> {
     fn hash<H: Hasher>(&self, state: &mut H) {
         let Frame {
-            mir,
-            instance: _,
+            mir: _,
+            instance,
             span: _,
             return_to_block,
             return_place,
@@ -130,7 +132,7 @@ impl<'mir, 'tcx: 'mir> Hash for Frame<'mir, 'tcx> {
             stmt,
         } = self;
 
-        (mir as *const _ as usize).hash(state);
+        instance.hash(state);
         return_to_block.hash(state);
         return_place.hash(state);
         locals.hash(state);
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index e8994cdac4c..ac4d1c74b8c 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -64,14 +64,13 @@ impl<'a, 'mir, 'tcx, M> PartialEq for Memory<'a, 'mir, 'tcx, M>
             alloc_kind,
             alloc_map,
             cur_frame,
-            tcx,
+            tcx: _,
         } = self;
 
         *data == other.data
             && *alloc_kind == other.alloc_kind
             && *alloc_map == other.alloc_map
             && *cur_frame == other.cur_frame
-            && ptr::eq(tcx, &other.tcx)
     }
 }
 
@@ -85,12 +84,11 @@ impl<'a, 'mir, 'tcx, M> Hash for Memory<'a, 'mir, 'tcx, M>
             alloc_kind: _,
             alloc_map: _,
             cur_frame,
-            tcx,
+            tcx: _,
         } = self;
 
         data.hash(state);
         cur_frame.hash(state);
-        (tcx as *const _ as usize).hash(state);
 
         // We ignore some fields which don't change between evaluation steps.