Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC the Stacked Borrows allocation history #3083

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bench-cargo-miri/invalidate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bench-cargo-miri/invalidate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "invalidate"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
4 changes: 4 additions & 0 deletions bench-cargo-miri/invalidate/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
// The end of the range is just chosen to make the benchmark run for a few seconds.
for _ in 0..200_000 {}
}
7 changes: 7 additions & 0 deletions src/borrow_tracker/stacked_borrows/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use smallvec::SmallVec;
use std::fmt;

use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange, InterpError};
use rustc_span::{Span, SpanData};
use rustc_target::abi::Size;
Expand Down Expand Up @@ -233,6 +234,12 @@ impl AllocHistory {
protectors: SmallVec::new(),
}
}

pub fn retain(&mut self, live_tags: &FxHashSet<BorTag>) {
self.invalidations.retain(|event| live_tags.contains(&event.tag));
self.creations.retain(|event| live_tags.contains(&event.retag.new_tag));
self.protectors.retain(|event| live_tags.contains(&event.tag));
}
}

impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
Expand Down
1 change: 1 addition & 0 deletions src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl Stacks {
stack.retain(live_tags);
}
}
self.history.retain(live_tags);
self.modified_since_last_gc = false;
}
}
Expand Down