Skip to content

Commit 3f0fb4f

Browse files
committed
split into two matrices
1 parent 40498ba commit 3f0fb4f

File tree

4 files changed

+245
-147
lines changed

4 files changed

+245
-147
lines changed

src/librustc_data_structures/bitvec.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,27 @@ impl<C: Idx> BitVector<C> {
4343
self.data.iter().map(|e| e.count_ones() as usize).sum()
4444
}
4545

46+
/// True if `self` contains the bit `bit`.
4647
#[inline]
4748
pub fn contains(&self, bit: C) -> bool {
4849
let (word, mask) = word_mask(bit);
4950
(self.data[word] & mask) != 0
5051
}
5152

53+
/// True if `self` contains all the bits in `other`.
54+
///
55+
/// The two vectors must have the same length.
56+
#[inline]
57+
pub fn contains_all(&self, other: &BitVector<C>) -> bool {
58+
assert_eq!(self.data.len(), other.data.len());
59+
self.data.iter().zip(&other.data).all(|(a, b)| (a & b) == *b)
60+
}
61+
62+
#[inline]
63+
pub fn is_empty(&self) -> bool {
64+
self.data.iter().all(|a| *a == 0)
65+
}
66+
5267
/// Returns true if the bit has changed.
5368
#[inline]
5469
pub fn insert(&mut self, bit: C) -> bool {
@@ -349,6 +364,10 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
349364
self.vector.len()
350365
}
351366

367+
pub fn rows(&self) -> impl Iterator<Item = R> {
368+
self.vector.indices()
369+
}
370+
352371
/// Iterates through all the columns set to true in a given row of
353372
/// the matrix.
354373
pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
@@ -522,3 +541,45 @@ fn matrix_iter() {
522541
}
523542
assert!(iter.next().is_none());
524543
}
544+
545+
#[test]
546+
fn sparse_matrix_iter() {
547+
let mut matrix = SparseBitMatrix::new(64, 100);
548+
matrix.add(3, 22);
549+
matrix.add(3, 75);
550+
matrix.add(2, 99);
551+
matrix.add(4, 0);
552+
matrix.merge(3, 5);
553+
554+
let expected = [99];
555+
let mut iter = expected.iter();
556+
for i in matrix.iter(2) {
557+
let j = *iter.next().unwrap();
558+
assert_eq!(i, j);
559+
}
560+
assert!(iter.next().is_none());
561+
562+
let expected = [22, 75];
563+
let mut iter = expected.iter();
564+
for i in matrix.iter(3) {
565+
let j = *iter.next().unwrap();
566+
assert_eq!(i, j);
567+
}
568+
assert!(iter.next().is_none());
569+
570+
let expected = [0];
571+
let mut iter = expected.iter();
572+
for i in matrix.iter(4) {
573+
let j = *iter.next().unwrap();
574+
assert_eq!(i, j);
575+
}
576+
assert!(iter.next().is_none());
577+
578+
let expected = [22, 75];
579+
let mut iter = expected.iter();
580+
for i in matrix.iter(5) {
581+
let j = *iter.next().unwrap();
582+
assert_eq!(i, j);
583+
}
584+
assert!(iter.next().is_none());
585+
}

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ pub struct RegionInferenceContext<'tcx> {
4848
/// from as well as its final inferred value.
4949
definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
5050

51-
/// Maps from points/universal-regions to a `RegionElementIndex`.
52-
elements: Rc<RegionValueElements>,
53-
5451
/// The liveness constraints added to each region. For most
5552
/// regions, these start out empty and steadily grow, though for
5653
/// each universally quantified region R they start out containing
@@ -219,14 +216,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
219216

220217
let mut scc_values = RegionValues::new(elements);
221218

222-
for (region, location_set) in liveness_constraints.iter_enumerated() {
219+
for region in liveness_constraints.regions_with_points() {
223220
let scc = constraint_sccs.scc(region);
224-
scc_values.merge_into(scc, location_set);
221+
scc_values.merge_row(scc, region, &liveness_constraints);
225222
}
226223

227224
let mut result = Self {
228225
definitions,
229-
elements: elements.clone(),
230226
liveness_constraints,
231227
constraints,
232228
constraint_graph,
@@ -273,7 +269,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
273269
}
274270

275271
// For each universally quantified region X:
276-
let elements = self.elements.clone();
277272
let universal_regions = self.universal_regions.clone();
278273
for variable in universal_regions.universal_regions() {
279274
// These should be free-region variables.
@@ -283,9 +278,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
283278
});
284279

285280
// Add all nodes in the CFG to liveness constraints
286-
for point_index in elements.all_point_indices() {
287-
self.add_live_element(variable, point_index);
288-
}
281+
let variable_scc = self.constraint_sccs.scc(variable);
282+
self.liveness_constraints.add_all_points(variable);
283+
self.scc_values.add_all_points(variable_scc);
289284

290285
// Add `end(X)` into the set for X.
291286
self.add_live_element(variable, variable);
@@ -782,7 +777,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
782777
// now). Therefore, the sup-region outlives the sub-region if,
783778
// for each universal region R1 in the sub-region, there
784779
// exists some region R2 in the sup-region that outlives R1.
785-
let universal_outlives = self.scc_values
780+
let universal_outlives = self
781+
.scc_values
786782
.universal_regions_outlived_by(sub_region_scc)
787783
.all(|r1| {
788784
self.scc_values

0 commit comments

Comments
 (0)