Impl Eq and PartialEq for EvalSnapshot in terms of the Snapshot trait
This commit is contained in:
parent
bf6ba974de
commit
927c709eb9
@ -111,32 +111,6 @@ pub struct Frame<'mir, 'tcx: 'mir> {
|
|||||||
pub stmt: usize,
|
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> {
|
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>) {
|
fn hash_stable<W: StableHasherResult>(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher<W>) {
|
||||||
let Frame {
|
let Frame {
|
||||||
|
@ -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> {
|
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 {
|
pub fn new(tcx: TyCtxtAt<'a, 'tcx, 'tcx>, data: M::MemoryData) -> Self {
|
||||||
Memory {
|
Memory {
|
||||||
|
@ -11,7 +11,7 @@ use syntax::ast::Mutability;
|
|||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
use super::eval_context::{LocalValue, StackPopCleanup};
|
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> {
|
trait SnapshotContext<'a> {
|
||||||
type To;
|
type To;
|
||||||
@ -24,6 +24,20 @@ trait Snapshot<'a, Ctx: SnapshotContext<'a>> {
|
|||||||
fn snapshot(&self, ctx: &'a Ctx) -> Self::Item;
|
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)]
|
#[derive(Eq, PartialEq)]
|
||||||
struct AllocIdSnapshot<'a>(Option<AllocationSnapshot<'a>>);
|
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>>;
|
type ValueSnapshot<'a> = Value<AllocIdSnapshot<'a>>;
|
||||||
|
|
||||||
impl<'a, Ctx> Snapshot<'a, Ctx> for Value
|
impl<'a, Ctx> Snapshot<'a, Ctx> for Value
|
||||||
@ -203,7 +201,7 @@ struct AllocationSnapshot<'a> {
|
|||||||
relocations: RelocationsSnapshot<'a>,
|
relocations: RelocationsSnapshot<'a>,
|
||||||
undef_mask: &'a UndefMask,
|
undef_mask: &'a UndefMask,
|
||||||
align: &'a Align,
|
align: &'a Align,
|
||||||
runtime_mutability: &'a Mutability,
|
mutability: &'a Mutability,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
|
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>;
|
type Item = AllocationSnapshot<'a>;
|
||||||
|
|
||||||
fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
|
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 {
|
AllocationSnapshot {
|
||||||
bytes,
|
bytes,
|
||||||
undef_mask,
|
undef_mask,
|
||||||
align,
|
align,
|
||||||
runtime_mutability,
|
mutability,
|
||||||
relocations: relocations.snapshot(ctx),
|
relocations: relocations.snapshot(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
struct FrameSnapshot<'a, 'tcx> {
|
struct FrameSnapshot<'a, 'tcx: 'a> {
|
||||||
instance: &'a ty::Instance<'tcx>,
|
instance: &'a ty::Instance<'tcx>,
|
||||||
span: &'a Span,
|
span: &'a Span,
|
||||||
return_to_block: &'a StackPopCleanup,
|
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,
|
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>
|
impl<'a, 'b, 'mir, 'tcx, M> SnapshotContext<'b> for Memory<'a, 'mir, 'tcx, M>
|
||||||
where M: Machine<'mir, 'tcx>,
|
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.
|
/// 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>> {
|
pub struct EvalSnapshot<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
|
||||||
machine: M,
|
machine: M,
|
||||||
memory: Memory<'a, 'mir, 'tcx, M>,
|
memory: Memory<'a, 'mir, 'tcx, M>,
|
||||||
@ -297,6 +303,11 @@ impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
|
|||||||
stack: stack.into(),
|
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>
|
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);
|
(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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user