about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/transitive_relation.rs
diff options
context:
space:
mode:
authorThe Miri Cronjob Bot <miri@cron.bot>2025-05-25 05:01:19 +0000
committerThe Miri Cronjob Bot <miri@cron.bot>2025-05-25 05:01:19 +0000
commitda39cbec739f2da49fa2b403e4e900c302a2c3de (patch)
tree6e8fd448eae0cd2c457d648f654459b0984c9a60 /compiler/rustc_data_structures/src/transitive_relation.rs
parent5c65c35d2626db646faa510481edd4ac59f1bafe (diff)
parent396c5cafe70f735e3d0ea0c8982c6901bcf0023a (diff)
downloadrust-da39cbec739f2da49fa2b403e4e900c302a2c3de.tar.gz
rust-da39cbec739f2da49fa2b403e4e900c302a2c3de.zip
Merge from rustc
Diffstat (limited to 'compiler/rustc_data_structures/src/transitive_relation.rs')
-rw-r--r--compiler/rustc_data_structures/src/transitive_relation.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/transitive_relation.rs b/compiler/rustc_data_structures/src/transitive_relation.rs
index 33ac279f3e0..31abea93819 100644
--- a/compiler/rustc_data_structures/src/transitive_relation.rs
+++ b/compiler/rustc_data_structures/src/transitive_relation.rs
@@ -354,6 +354,20 @@ impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
             .collect()
     }
 
+    /// Given an element A, elements B with the lowest index such that `A R B`
+    /// and `B R A`, or `A` if no such element exists.
+    pub fn minimal_scc_representative(&self, a: T) -> T {
+        match self.index(a) {
+            Some(a_i) => self.with_closure(|closure| {
+                closure
+                    .iter(a_i.0)
+                    .find(|i| closure.contains(*i, a_i.0))
+                    .map_or(a, |i| self.elements[i])
+            }),
+            None => a,
+        }
+    }
+
     fn with_closure<OP, R>(&self, op: OP) -> R
     where
         OP: FnOnce(&BitMatrix<usize, usize>) -> R,