Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b21acc

Browse files
committedNov 21, 2023
Miri: GC the dead_alloc_map too
1 parent 0ff8610 commit 6b21acc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎compiler/rustc_const_eval/src/interpret/memory.rs

+10
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
501501
}
502502
}
503503

504+
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
505+
/// This function is used by Miri's provenance GC to remove unreachable entries from the dead_alloc_map.
506+
pub fn remove_unreachable_allocs(&mut self, reachable_allocs: &FxHashSet<AllocId>) {
507+
// Unlike all the other GC helpers where we check if an `AllocId` is found in the interpreter or
508+
// is live, here all the IDs in the map are for dead allocations.
509+
#[allow(rustc::potential_query_instability)] // Only used from Miri, not queries.
510+
self.memory.dead_alloc_map.retain(|id, _| reachable_allocs.contains(id));
511+
}
512+
}
513+
504514
/// Allocation accessors
505515
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
506516
/// Helper function to obtain a global (tcx) allocation.

‎src/tools/miri/src/provenance_gc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
195195
}
196196

197197
fn remove_unreachable_allocs(&mut self, allocs: FxHashSet<AllocId>) {
198-
let this = self.eval_context_ref();
198+
let this = self.eval_context_mut();
199199
let allocs = LiveAllocs {
200200
ecx: this,
201201
collected: allocs,
@@ -205,5 +205,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
205205
if let Some(borrow_tracker) = &this.machine.borrow_tracker {
206206
borrow_tracker.borrow_mut().remove_unreachable_allocs(&allocs);
207207
}
208+
this.remove_unreachable_allocs(&allocs.collected);
208209
}
209210
}

0 commit comments

Comments
 (0)
Please sign in to comment.