Skip to content

Commit 689171d

Browse files
committed
Uplift rustc_mir_transform::coverage::counters::union_find to rustc_data_structures.
1 parent 040a98a commit 689171d

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub mod thinvec;
7777
pub mod thousands;
7878
pub mod transitive_relation;
7979
pub mod unhash;
80+
pub mod union_find;
8081
pub mod unord;
8182
pub mod vec_cache;
8283
pub mod work_queue;

compiler/rustc_mir_transform/src/coverage/counters/union_find.rs renamed to compiler/rustc_data_structures/src/union_find.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod tests;
99
/// Simple implementation of a union-find data structure, i.e. a disjoint-set
1010
/// forest.
1111
#[derive(Debug)]
12-
pub(crate) struct UnionFind<Key: Idx> {
12+
pub struct UnionFind<Key: Idx> {
1313
table: IndexVec<Key, UnionFindEntry<Key>>,
1414
}
1515

@@ -28,7 +28,7 @@ struct UnionFindEntry<Key> {
2828
impl<Key: Idx> UnionFind<Key> {
2929
/// Creates a new disjoint-set forest containing the keys `0..num_keys`.
3030
/// Initially, every key is part of its own one-element set.
31-
pub(crate) fn new(num_keys: usize) -> Self {
31+
pub fn new(num_keys: usize) -> Self {
3232
// Initially, every key is the root of its own set, so its parent is itself.
3333
Self { table: IndexVec::from_fn_n(|key| UnionFindEntry { parent: key, rank: 0 }, num_keys) }
3434
}
@@ -38,7 +38,7 @@ impl<Key: Idx> UnionFind<Key> {
3838
///
3939
/// Also updates internal data structures to make subsequent `find`
4040
/// operations faster.
41-
pub(crate) fn find(&mut self, key: Key) -> Key {
41+
pub fn find(&mut self, key: Key) -> Key {
4242
// Loop until we find a key that is its own parent.
4343
let mut curr = key;
4444
while let parent = self.table[curr].parent
@@ -60,7 +60,7 @@ impl<Key: Idx> UnionFind<Key> {
6060
/// Merges the set containing `a` and the set containing `b` into one set.
6161
///
6262
/// Returns the common root of both keys, after the merge.
63-
pub(crate) fn unify(&mut self, a: Key, b: Key) -> Key {
63+
pub fn unify(&mut self, a: Key, b: Key) -> Key {
6464
let mut a = self.find(a);
6565
let mut b = self.find(b);
6666

@@ -90,7 +90,7 @@ impl<Key: Idx> UnionFind<Key> {
9090

9191
/// Takes a "snapshot" of the current state of this disjoint-set forest, in
9292
/// the form of a vector that directly maps each key to its current root.
93-
pub(crate) fn snapshot(&mut self) -> IndexVec<Key, Key> {
93+
pub fn snapshot(&mut self) -> IndexVec<Key, Key> {
9494
self.table.indices().map(|key| self.find(key)).collect()
9595
}
9696
}

compiler/rustc_mir_transform/src/coverage/counters.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
1616

1717
mod balanced_flow;
1818
pub(crate) mod node_flow;
19-
mod union_find;
2019

2120
/// Struct containing the results of [`prepare_bcb_counters_data`].
2221
pub(crate) struct BcbCountersData {

compiler/rustc_mir_transform/src/coverage/counters/node_flow.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
//! (Knuth & Stevenson, 1973).
88
99
use rustc_data_structures::graph;
10+
use rustc_data_structures::union_find::UnionFind;
1011
use rustc_index::bit_set::DenseBitSet;
1112
use rustc_index::{Idx, IndexSlice, IndexVec};
1213
pub(crate) use rustc_middle::mir::coverage::NodeFlowData;
1314
use rustc_middle::mir::coverage::Op;
1415

15-
use crate::coverage::counters::union_find::UnionFind;
16-
1716
#[cfg(test)]
1817
mod tests;
1918

0 commit comments

Comments
 (0)