Skip to content

Commit 32c0afb

Browse files
committed
Auto merge of #3083 - saethlin:gc-history, r=oli-obk
GC the Stacked Borrows allocation history This handles the biggest contributor to rust-lang/miri#3080 The benchmark that this adds demonstrates the memory improvement here, but our benchmark setup doesn't record memory usage, and `hyperfine` doesn't support emitting memory usage stats. I ran this benchmark manually with `/usr/bin/time -v cargo +miri miri run` 🤷
2 parents b4dc4f3 + 5f440dd commit 32c0afb

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "invalidate"
7+
version = "0.1.0"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "invalidate"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
// The end of the range is just chosen to make the benchmark run for a few seconds.
3+
for _ in 0..200_000 {}
4+
}

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use smallvec::SmallVec;
22
use std::fmt;
33

4+
use rustc_data_structures::fx::FxHashSet;
45
use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange, InterpError};
56
use rustc_span::{Span, SpanData};
67
use rustc_target::abi::Size;
@@ -233,6 +234,12 @@ impl AllocHistory {
233234
protectors: SmallVec::new(),
234235
}
235236
}
237+
238+
pub fn retain(&mut self, live_tags: &FxHashSet<BorTag>) {
239+
self.invalidations.retain(|event| live_tags.contains(&event.tag));
240+
self.creations.retain(|event| live_tags.contains(&event.retag.new_tag));
241+
self.protectors.retain(|event| live_tags.contains(&event.tag));
242+
}
236243
}
237244

238245
impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl Stacks {
456456
stack.retain(live_tags);
457457
}
458458
}
459+
self.history.retain(live_tags);
459460
self.modified_since_last_gc = false;
460461
}
461462
}

0 commit comments

Comments
 (0)