Skip to content

Commit

Permalink
Extend the BorTag GC to AllocIds
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 8, 2023
1 parent b02a8a9 commit aadf935
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 55 deletions.
8 changes: 4 additions & 4 deletions src/borrow_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct FrameState {
}

impl VisitTags for FrameState {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
// `protected_tags` are already recorded by `GlobalStateInner`.
}
}
Expand Down Expand Up @@ -111,9 +111,9 @@ pub struct GlobalStateInner {
}

impl VisitTags for GlobalStateInner {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
for &tag in self.protected_tags.keys() {
visit(tag);
visit(None, Some(tag));
}
// The only other candidate is base_ptr_tags, and that does not need visiting since we don't ever
// GC the bottommost/root tag.
Expand Down Expand Up @@ -472,7 +472,7 @@ impl AllocState {
}

impl VisitTags for AllocState {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
match self {
AllocState::StackedBorrows(sb) => sb.visit_tags(visit),
AllocState::TreeBorrows(tb) => tb.visit_tags(visit),
Expand Down
4 changes: 2 additions & 2 deletions src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ impl Stacks {
}

impl VisitTags for Stacks {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
for tag in self.exposed_tags.iter().copied() {
visit(tag);
visit(None, Some(tag));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/borrow_tracker/tree_borrows/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,10 @@ impl Tree {
}

impl VisitTags for Tree {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
// To ensure that the root never gets removed, we visit it
// (the `root` node of `Tree` is not an `Option<_>`)
visit(self.nodes.get(self.root).unwrap().tag)
visit(None, Some(self.nodes.get(self.root).unwrap().tag))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ pub struct VClockAlloc {
}

impl VisitTags for VClockAlloc {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
// No tags here.
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
// No tags or allocIds here.
}
}

Expand Down Expand Up @@ -1275,7 +1275,7 @@ pub struct GlobalState {
}

impl VisitTags for GlobalState {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
// We don't have any tags.
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/init_once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(super) struct InitOnce<'mir, 'tcx> {
}

impl<'mir, 'tcx> VisitTags for InitOnce<'mir, 'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
for waiter in self.waiters.iter() {
waiter.callback.visit_tags(visit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub(crate) struct SynchronizationState<'mir, 'tcx> {
}

impl<'mir, 'tcx> VisitTags for SynchronizationState<'mir, 'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
for init_once in self.init_onces.iter() {
init_once.visit_tags(visit);
}
Expand Down
6 changes: 3 additions & 3 deletions src/concurrency/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'mir, 'tcx> Thread<'mir, 'tcx> {
}

impl VisitTags for Thread<'_, '_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Thread {
panic_payloads: panic_payload,
last_error,
Expand All @@ -243,7 +243,7 @@ impl VisitTags for Thread<'_, '_> {
}

impl VisitTags for Frame<'_, '_, Provenance, FrameExtra<'_>> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Frame {
return_place,
locals,
Expand Down Expand Up @@ -333,7 +333,7 @@ pub struct ThreadManager<'mir, 'tcx> {
}

impl VisitTags for ThreadManager<'_, '_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let ThreadManager {
threads,
thread_local_alloc_ids,
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/weak_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub struct StoreBufferAlloc {
}

impl VisitTags for StoreBufferAlloc {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Self { store_buffers } = self;
for val in store_buffers
.borrow()
Expand Down
11 changes: 9 additions & 2 deletions src/intptrcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ pub struct GlobalStateInner {
}

impl VisitTags for GlobalStateInner {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
// Nothing to visit here.
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
for id in &self.exposed {
id.visit_tags(visit)
}
}
}

Expand All @@ -63,6 +65,11 @@ impl GlobalStateInner {
}

impl<'mir, 'tcx> GlobalStateInner {
pub fn remove_unreachable_allocs(&mut self, live_allocs: &FxHashSet<AllocId>) {
self.int_to_ptr_map.retain(|(_, id)| live_allocs.contains(id));
self.base_addr.retain(|id, _| live_allocs.contains(id));
}

// Returns the exposed `AllocId` that corresponds to the specified addr,
// or `None` if the addr is out of bounds
fn alloc_id_from_addr(ecx: &MiriInterpCx<'mir, 'tcx>, addr: u64) -> Option<AllocId> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub use crate::machine::{
pub use crate::mono_hash_map::MonoHashMap;
pub use crate::operator::EvalContextExt as _;
pub use crate::range_map::RangeMap;
pub use crate::tag_gc::{EvalContextExt as _, VisitTags};
pub use crate::tag_gc::{EvalContextExt as _, TagVisitor, VisitTags};

/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
/// set per default, for maximal validation power.
Expand Down
6 changes: 3 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'tcx> std::fmt::Debug for FrameExtra<'tcx> {
}

impl VisitTags for FrameExtra<'_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let FrameExtra { catch_unwind, borrow_tracker, timing: _, is_user_relevant: _ } = self;

catch_unwind.visit_tags(visit);
Expand Down Expand Up @@ -295,7 +295,7 @@ pub struct AllocExtra<'tcx> {
}

impl VisitTags for AllocExtra<'_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let AllocExtra { borrow_tracker, data_race, weak_memory, backtrace: _ } = self;

borrow_tracker.visit_tags(visit);
Expand Down Expand Up @@ -777,7 +777,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
}

impl VisitTags for MiriMachine<'_, '_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
#[rustfmt::skip]
let MiriMachine {
threads,
Expand Down
2 changes: 1 addition & 1 deletion src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct EnvVars<'tcx> {
}

impl VisitTags for EnvVars<'_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let EnvVars { map, environ } = self;

environ.visit_tags(visit);
Expand Down
2 changes: 1 addition & 1 deletion src/shims/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct CatchUnwindData<'tcx> {
}

impl VisitTags for CatchUnwindData<'_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let CatchUnwindData { catch_fn, data, dest, ret: _ } = self;
catch_fn.visit_tags(visit);
data.visit_tags(visit);
Expand Down
2 changes: 1 addition & 1 deletion src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ struct UnblockCallback {
}

impl VisitTags for UnblockCallback {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {}
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {}
}

impl<'mir, 'tcx: 'mir> MachineCallback<'mir, 'tcx> for UnblockCallback {
Expand Down
2 changes: 1 addition & 1 deletion src/shims/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<'tcx> TlsData<'tcx> {
}

impl VisitTags for TlsData<'_> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let TlsData { keys, macos_thread_dtors, next_key: _ } = self;

for scalar in keys.values().flat_map(|v| v.data.values()) {
Expand Down
4 changes: 2 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub struct FileHandler {
}

impl VisitTags for FileHandler {
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
// All our FileDescriptor do not have any tags.
}
}
Expand Down Expand Up @@ -491,7 +491,7 @@ impl Default for DirHandler {
}

impl VisitTags for DirHandler {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let DirHandler { streams, next_id: _ } = self;

for dir in streams.values() {
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn futex<'tcx>(
}

impl<'tcx> VisitTags for Callback<'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Callback { thread: _, addr_usize: _, dest } = self;
dest.visit_tags(visit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

impl<'tcx> VisitTags for Callback<'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Callback { active_thread: _, mutex_id: _, id: _, dest } = self;
dest.visit_tags(visit);
}
Expand Down
6 changes: 3 additions & 3 deletions src/shims/windows/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

impl<'tcx> VisitTags for Callback<'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Callback { init_once_id: _, pending_place } = self;
pending_place.visit_tags(visit);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

impl<'tcx> VisitTags for Callback<'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Callback { thread: _, addr: _, dest } = self;
dest.visit_tags(visit);
}
Expand Down Expand Up @@ -442,7 +442,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

impl<'tcx> VisitTags for Callback<'tcx> {
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
let Callback { thread: _, condvar_id: _, lock_id: _, mode: _, dest } = self;
dest.visit_tags(visit);
}
Expand Down
Loading

0 comments on commit aadf935

Please sign in to comment.