Skip to content

Commit deca8e9

Browse files
committed
Account for weak memory in the tag GC (crudely)
1 parent dcd94ee commit deca8e9

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/concurrency/range_object_map.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ impl<T> RangeObjectMap<T> {
132132
pub fn remove_from_pos(&mut self, pos: Position) {
133133
self.v.remove(pos);
134134
}
135+
136+
pub fn iter(&self) -> impl Iterator<Item = &T> {
137+
self.v.iter().map(|e| &e.data)
138+
}
135139
}
136140

137141
impl<T> Index<Position> for RangeObjectMap<T> {

src/concurrency/weak_memory.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ pub struct StoreBufferAlloc {
108108
store_buffers: RefCell<RangeObjectMap<StoreBuffer>>,
109109
}
110110

111+
impl StoreBufferAlloc {
112+
pub fn iter(&self, mut visitor: impl FnMut(&Scalar<Provenance>)) {
113+
for val in self
114+
.store_buffers
115+
.borrow()
116+
.iter()
117+
.flat_map(|buf| buf.buffer.iter().map(|element| &element.val))
118+
{
119+
visitor(val)
120+
}
121+
}
122+
}
123+
111124
#[derive(Debug, Clone, PartialEq, Eq)]
112125
pub(super) struct StoreBuffer {
113126
// Stores to this location in modification order

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
601601

602602
impl VisitMachineValues for MiriMachine<'_, '_> {
603603
fn visit_machine_values(&self, visit: &mut impl FnMut(&Operand<Provenance>)) {
604-
// FIXME: visit the missing fields: weak mem, DirHandler, Stacked Borrows base pointers(?); maybe more.
604+
// FIXME: visit the missing fields: DirHandler, Stacked Borrows base pointers(?); maybe more.
605605
let MiriMachine { threads, tls, env_vars, argc, argv, cmd_line, extern_statics, .. } = self;
606606

607607
threads.visit_machine_values(visit);

src/tag_gc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
7777
.as_ref()
7878
.expect("we should not even enter the GC if Stacked Borrows is disabled");
7979
tags.extend(&stacks.borrow().exposed_tags);
80+
81+
if let Some(store_buffers) = alloc.extra.weak_memory.as_ref() {
82+
store_buffers.iter(|val| {
83+
if let Scalar::Ptr(ptr, _) = val {
84+
if let Provenance::Concrete { sb, .. } = ptr.provenance {
85+
tags.insert(sb);
86+
}
87+
}
88+
});
89+
}
8090
},
8191
);
8292

0 commit comments

Comments
 (0)