]> git.lizzy.rs Git - rust.git/commitdiff
Improve correctness of `Frame` and `Memory` equality
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 22 Jun 2018 20:31:25 +0000 (13:31 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 4 Jul 2018 21:36:07 +0000 (14:36 -0700)
Incorporate a subset of the suggestions from @oli-obk. More to come.

src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/memory.rs

index 85aeb3c7df51a0bb46f78871ad307b6338242921..e3024e069d9114733bbf45fe9b1951a631e65f21 100644 (file)
@@ -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 @@ fn eq(&self, other: &Self) -> bool {
             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 @@ fn eq(&self, other: &Self) -> bool {
 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 @@ fn hash<H: Hasher>(&self, state: &mut H) {
             stmt,
         } = self;
 
-        (mir as *const _ as usize).hash(state);
+        instance.hash(state);
         return_to_block.hash(state);
         return_place.hash(state);
         locals.hash(state);
index e8994cdac4c2eabf6cdb536d4d45874f7eef1921..ac4d1c74b8cc1296d8e15eab450cc600ebabfa08 100644 (file)
@@ -64,14 +64,13 @@ fn eq(&self, other: &Self) -> bool {
             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 @@ fn hash<H: Hasher>(&self, state: &mut H) {
             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.