From c17124255d5512bfa801dadeb5f340edaad12752 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 14 Apr 2022 21:47:56 +0100 Subject: [PATCH] Address merging MemoryExtra into machine --- src/data_race.rs | 28 ++++++++++++++-------------- src/machine.rs | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index 8f2451b99d..82a09afef8 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -482,14 +482,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { // Only metadata on the location itself is used. let scalar = this.allow_data_races_ref(move |this| this.read_scalar(&place.into()))?; - if let Some(global) = &this.memory.extra.data_race { - let (alloc_id, base_offset, ..) = this.memory.ptr_get_alloc(place.ptr)?; - if let Some(alloc_buffers) = this.memory.get_alloc_extra(alloc_id)?.weak_memory.as_ref() + if let Some(global) = &this.machine.data_race { + let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr)?; + if let Some(alloc_buffers) = this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() { if atomic == AtomicReadOp::SeqCst { global.sc_read(); } - let mut rng = this.memory.extra.rng.borrow_mut(); + let mut rng = this.machine.rng.borrow_mut(); let loaded = alloc_buffers.buffered_read( alloc_range(base_offset, place.layout.size), global, @@ -517,11 +517,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { this.allow_data_races_mut(move |this| this.write_scalar(val, &(*dest).into()))?; this.validate_atomic_store(dest, atomic)?; - let (alloc_id, base_offset, ..) = this.memory.ptr_get_alloc(dest.ptr)?; + let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(dest.ptr)?; if let ( crate::AllocExtra { weak_memory: Some(alloc_buffers), .. }, - crate::MemoryExtra { data_race: Some(global), .. }, - ) = this.memory.get_alloc_extra_mut(alloc_id)? + crate::Evaluator { data_race: Some(global), .. }, + ) = this.get_alloc_extra_mut(alloc_id)? { if atomic == AtomicWriteOp::SeqCst { global.sc_write(); @@ -659,14 +659,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { // in the modification order. // Since `old` is only a value and not the store element, we need to separately // find it in our store buffer and perform load_impl on it. - if let Some(global) = &this.memory.extra.data_race { + if let Some(global) = &this.machine.data_race { if fail == AtomicReadOp::SeqCst { global.sc_read(); } let size = place.layout.size; - let (alloc_id, base_offset, ..) = this.memory.ptr_get_alloc(place.ptr)?; + let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr)?; if let Some(alloc_buffers) = - this.memory.get_alloc_extra(alloc_id)?.weak_memory.as_ref() + this.get_alloc_extra(alloc_id)?.weak_memory.as_ref() { if global.multi_threaded.get() { alloc_buffers.read_from_last_store(alloc_range(base_offset, size), global); @@ -686,11 +686,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { atomic: AtomicRwOp, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - let (alloc_id, base_offset, ..) = this.memory.ptr_get_alloc(place.ptr)?; + let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr)?; if let ( crate::AllocExtra { weak_memory: Some(alloc_buffers), .. }, - crate::MemoryExtra { data_race: Some(global), .. }, - ) = this.memory.get_alloc_extra_mut(alloc_id)? + crate::Evaluator { data_race: Some(global), .. }, + ) = this.get_alloc_extra_mut(alloc_id)? { if atomic == AtomicRwOp::SeqCst { global.sc_read(); @@ -777,7 +777,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { fn validate_atomic_fence(&mut self, atomic: AtomicFenceOp) -> InterpResult<'tcx> { let this = self.eval_context_mut(); if let Some(data_race) = &mut this.machine.data_race { - data_race.maybe_perform_sync_operation(move |index, mut clocks| { + data_race.maybe_perform_sync_operation(|index, mut clocks| { log::trace!("Atomic fence on {:?} with ordering {:?}", index, atomic); // Apply data-race detection for the current fences diff --git a/src/machine.rs b/src/machine.rs index d237315bac..2b0443c60d 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -571,7 +571,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { } else { None }; - let buffer_alloc = if mem.extra.weak_memory { + let buffer_alloc = if ecx.machine.weak_memory { // FIXME: if this is an atomic obejct, we want to supply its initial value // while allocating the store buffer here. Some(weak_memory::AllocExtra::new_allocation(alloc.size()))