-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Store LiveLoans more densely packed #161850
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ mod liveness_constraints; | |
| use std::collections::BTreeMap; | ||
|
|
||
| use rustc_data_structures::fx::FxHashSet; | ||
| use rustc_index::bit_set::SparseBitMatrix; | ||
| use rustc_index::bit_set::DenseBitSet; | ||
| use rustc_middle::mir::{Body, Local}; | ||
| use rustc_middle::ty::RegionVid; | ||
| use rustc_mir_dataflow::points::PointIndex; | ||
|
|
@@ -55,7 +55,28 @@ use crate::dataflow::BorrowIndex; | |
| use crate::region_infer::values::LivenessValues; | ||
| use crate::universal_regions::UniversalRegions; | ||
|
|
||
| pub(crate) type LiveLoans = SparseBitMatrix<PointIndex, BorrowIndex>; | ||
| #[derive(Clone)] | ||
| pub(crate) struct LiveLoans { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's worth making this a broadly available datastructure or if it's enough to keep it here for now?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think leaving this here for now is fine.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only used in a small part of borrowck, and we will have to tweak it in the future anyways: the current behavior of filling this depends on how the graph is traversed. When traversing multiple loans at a time, the exact iteration and filling behavior will be different, and the best live loans representation will likely need to be reinvestigated. This matches your comment
|
||
| num_points: usize, | ||
| // This matrix always has more rows (PointIndex) than columns (BorrowIndex), | ||
| // and the borrow dimension is usually very low (single digit in 90% of cases in our benchmark suite), | ||
| // so we store it packed in a single bitset. Rows are points, columns are borrows. | ||
| flat_matrix: DenseBitSet<usize>, | ||
| } | ||
|
|
||
| impl LiveLoans { | ||
| pub(crate) fn new(num_points: usize, num_borrows: usize) -> Self { | ||
| Self { num_points, flat_matrix: DenseBitSet::new_empty(num_points * num_borrows) } | ||
| } | ||
| pub(crate) fn insert(&mut self, row: PointIndex, col: BorrowIndex) { | ||
| let bit_index = row.index() + self.num_points * col.index(); | ||
| self.flat_matrix.insert(bit_index); | ||
| } | ||
| pub(crate) fn contains(&self, row: PointIndex, col: BorrowIndex) -> bool { | ||
| let bit_index = row.index() + self.num_points * col.index(); | ||
| self.flat_matrix.contains(bit_index) | ||
| } | ||
| } | ||
|
|
||
| /// This struct holds the necessary | ||
| /// - liveness data, created during MIR typeck, and which will be used to lazily compute the | ||
|
|
@@ -109,6 +130,7 @@ impl PoloniusContext { | |
| universal_regions: &UniversalRegions<'tcx>, | ||
| body: &Body<'tcx>, | ||
| borrow_set: &BorrowSet<'tcx>, | ||
| num_points: usize, | ||
| ) { | ||
| // We don't need to prepare the graph (index NLL constraints, etc.) if we have no loans to | ||
| // trace throughout localized constraints. | ||
|
|
@@ -118,7 +140,7 @@ impl PoloniusContext { | |
| // step in the chain (the NLL loan scope and active loans computations). | ||
| let graph = LocalizedConstraintGraph::new(liveness, outlives_constraints); | ||
|
|
||
| let mut live_loans = LiveLoans::new(borrow_set.len()); | ||
| let mut live_loans = LiveLoans::new(num_points, borrow_set.len()); | ||
| let mut visitor = LoanLivenessVisitor { liveness, live_loans: &mut live_loans }; | ||
| graph.traverse( | ||
| body, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where is the right place to get this information from location_map. The way
location_mapis threaded through the code and the fact that it's inRcmakes it unclear at what point in time it is ready to use.View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. I was realizing too that currently things are all jumbled up and it might make sense to take a cleanup pass at some point.
I end up touching this in #161938 anyways, so not a big deal.