From d73a169f93748e963be068201b5c4eee1fe6c982 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 26 Aug 2021 11:39:13 -0700 Subject: [PATCH] Fix sparse intersect bug, add more sparse / dense tests --- compiler/rustc_index/src/bit_set.rs | 2 +- compiler/rustc_index/src/bit_set/tests.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 230a551f3c5..989d56b0528 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -272,7 +272,7 @@ fn dense_sparse_intersect( sparse: &SparseBitSet, ) -> (SparseBitSet, bool) { let mut sparse_copy = sparse.clone(); - sparse_intersect(&mut sparse_copy, |el| !dense.contains(*el)); + sparse_intersect(&mut sparse_copy, |el| dense.contains(*el)); let n = sparse_copy.len(); (sparse_copy, n != dense.count()) } diff --git a/compiler/rustc_index/src/bit_set/tests.rs b/compiler/rustc_index/src/bit_set/tests.rs index 352a0c7a1b4..6f633f3b9cb 100644 --- a/compiler/rustc_index/src/bit_set/tests.rs +++ b/compiler/rustc_index/src/bit_set/tests.rs @@ -108,14 +108,25 @@ fn hybrid_bitset() { assert!(!sparse01358.union(&hybrid)); // no change assert!(hybrid.union(&sparse01358)); assert!(hybrid.superset(&sparse01358) && sparse01358.superset(&hybrid)); - assert!(!dense10.union(&sparse01358)); assert!(!dense256.union(&dense10)); + // dense / sparse where dense superset sparse + assert!(!dense10.clone().union(&sparse01358)); + assert!(sparse01358.clone().union(&dense10)); assert!(dense10.clone().intersect(&sparse01358)); assert!(!sparse01358.clone().intersect(&dense10)); assert!(dense10.clone().subtract(&sparse01358)); assert!(sparse01358.clone().subtract(&dense10)); + // dense / sparse where sparse superset dense + let dense038 = sparse038.to_dense(); + assert!(!sparse0381.clone().union(&dense038)); + assert!(dense038.clone().union(&sparse0381)); + assert!(sparse0381.clone().intersect(&dense038)); + assert!(!dense038.clone().intersect(&sparse0381)); + assert!(sparse0381.clone().subtract(&dense038)); + assert!(dense038.clone().subtract(&sparse0381)); + let mut dense = dense10.clone(); assert!(dense.union(&dense256)); assert!(dense.superset(&dense256) && dense256.superset(&dense));