@@ -184,6 +184,29 @@ impl LiveAllocs<'_, '_> {
184
184
}
185
185
}
186
186
187
+ fn remove_unreachable_tags < ' tcx > ( this : & mut MiriInterpCx < ' tcx > , tags : FxHashSet < BorTag > ) {
188
+ // Avoid iterating all allocations if there's no borrow tracker anyway.
189
+ if this. machine . borrow_tracker . is_some ( ) {
190
+ this. memory . alloc_map ( ) . iter ( |it| {
191
+ for ( _id, ( _kind, alloc) ) in it {
192
+ alloc. extra . borrow_tracker . as_ref ( ) . unwrap ( ) . remove_unreachable_tags ( & tags) ;
193
+ }
194
+ } ) ;
195
+ }
196
+ }
197
+
198
+ fn remove_unreachable_allocs < ' tcx > ( this : & mut MiriInterpCx < ' tcx > , allocs : FxHashSet < AllocId > ) {
199
+ let allocs = LiveAllocs { ecx : this, collected : allocs } ;
200
+ this. machine . allocation_spans . borrow_mut ( ) . retain ( |id, _| allocs. is_live ( * id) ) ;
201
+ this. machine . symbolic_alignment . borrow_mut ( ) . retain ( |id, _| allocs. is_live ( * id) ) ;
202
+ this. machine . alloc_addresses . borrow_mut ( ) . remove_unreachable_allocs ( & allocs) ;
203
+ if let Some ( borrow_tracker) = & this. machine . borrow_tracker {
204
+ borrow_tracker. borrow_mut ( ) . remove_unreachable_allocs ( & allocs) ;
205
+ }
206
+ // Clean up core (non-Miri-specific) state.
207
+ this. remove_unreachable_allocs ( & allocs. collected ) ;
208
+ }
209
+
187
210
impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
188
211
pub trait EvalContextExt < ' tcx > : MiriInterpCxExt < ' tcx > {
189
212
fn run_provenance_gc ( & mut self ) {
@@ -202,30 +225,7 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> {
202
225
} ) ;
203
226
204
227
// Based on this, clean up the interpreter state.
205
- self . remove_unreachable_tags ( tags) ;
206
- self . remove_unreachable_allocs ( alloc_ids) ;
207
- }
208
-
209
- fn remove_unreachable_tags ( & mut self , tags : FxHashSet < BorTag > ) {
210
- let this = self . eval_context_mut ( ) ;
211
- this. memory . alloc_map ( ) . iter ( |it| {
212
- for ( _id, ( _kind, alloc) ) in it {
213
- if let Some ( bt) = & alloc. extra . borrow_tracker {
214
- bt. remove_unreachable_tags ( & tags) ;
215
- }
216
- }
217
- } ) ;
218
- }
219
-
220
- fn remove_unreachable_allocs ( & mut self , allocs : FxHashSet < AllocId > ) {
221
- let this = self . eval_context_mut ( ) ;
222
- let allocs = LiveAllocs { ecx : this, collected : allocs } ;
223
- this. machine . allocation_spans . borrow_mut ( ) . retain ( |id, _| allocs. is_live ( * id) ) ;
224
- this. machine . symbolic_alignment . borrow_mut ( ) . retain ( |id, _| allocs. is_live ( * id) ) ;
225
- this. machine . alloc_addresses . borrow_mut ( ) . remove_unreachable_allocs ( & allocs) ;
226
- if let Some ( borrow_tracker) = & this. machine . borrow_tracker {
227
- borrow_tracker. borrow_mut ( ) . remove_unreachable_allocs ( & allocs) ;
228
- }
229
- this. remove_unreachable_allocs ( & allocs. collected ) ;
228
+ remove_unreachable_tags ( this, tags) ;
229
+ remove_unreachable_allocs ( this, alloc_ids) ;
230
230
}
231
231
}
0 commit comments