Skip to content

Commit

Permalink
Address merging MemoryExtra into machine
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Apr 14, 2022
1 parent da6de5f commit c171242
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit c171242

Please sign in to comment.