Skip to content

Commit 0f1c61c

Browse files
Improve correctness of Frame and Memory equality
Incorporate a subset of the suggestions from @oli-obk. More to come.
1 parent 788c5f3 commit 0f1c61c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt::Write;
22
use std::hash::{Hash, Hasher};
3-
use std::{mem, ptr};
3+
use std::mem;
44

55
use rustc::hir::def_id::DefId;
66
use rustc::hir::def::Def;
@@ -98,8 +98,8 @@ impl<'mir, 'tcx: 'mir> Eq for Frame<'mir, 'tcx> {}
9898
impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
9999
fn eq(&self, other: &Self) -> bool {
100100
let Frame {
101-
mir,
102-
instance: _,
101+
mir: _,
102+
instance,
103103
span: _,
104104
return_to_block,
105105
return_place,
@@ -108,8 +108,10 @@ impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
108108
stmt,
109109
} = self;
110110

111-
ptr::eq(mir, &other.mir)
112-
&& *return_to_block == other.return_to_block // TODO: Are these two necessary?
111+
// Some of these are constant during evaluation, but are included
112+
// anyways for correctness.
113+
*instance == other.instance
114+
&& *return_to_block == other.return_to_block
113115
&& *return_place == other.return_place
114116
&& *locals == other.locals
115117
&& *block == other.block
@@ -120,8 +122,8 @@ impl<'mir, 'tcx: 'mir> PartialEq for Frame<'mir, 'tcx> {
120122
impl<'mir, 'tcx: 'mir> Hash for Frame<'mir, 'tcx> {
121123
fn hash<H: Hasher>(&self, state: &mut H) {
122124
let Frame {
123-
mir,
124-
instance: _,
125+
mir: _,
126+
instance,
125127
span: _,
126128
return_to_block,
127129
return_place,
@@ -130,7 +132,7 @@ impl<'mir, 'tcx: 'mir> Hash for Frame<'mir, 'tcx> {
130132
stmt,
131133
} = self;
132134

133-
(mir as *const _ as usize).hash(state);
135+
instance.hash(state);
134136
return_to_block.hash(state);
135137
return_place.hash(state);
136138
locals.hash(state);

src/librustc_mir/interpret/memory.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ impl<'a, 'mir, 'tcx, M> PartialEq for Memory<'a, 'mir, 'tcx, M>
6464
alloc_kind,
6565
alloc_map,
6666
cur_frame,
67-
tcx,
67+
tcx: _,
6868
} = self;
6969

7070
*data == other.data
7171
&& *alloc_kind == other.alloc_kind
7272
&& *alloc_map == other.alloc_map
7373
&& *cur_frame == other.cur_frame
74-
&& ptr::eq(tcx, &other.tcx)
7574
}
7675
}
7776

@@ -85,12 +84,11 @@ impl<'a, 'mir, 'tcx, M> Hash for Memory<'a, 'mir, 'tcx, M>
8584
alloc_kind: _,
8685
alloc_map: _,
8786
cur_frame,
88-
tcx,
87+
tcx: _,
8988
} = self;
9089

9190
data.hash(state);
9291
cur_frame.hash(state);
93-
(tcx as *const _ as usize).hash(state);
9492

9593
// We ignore some fields which don't change between evaluation steps.
9694

0 commit comments

Comments
 (0)