X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_data_structures%2Fsrc%2Ftransitive_relation.rs;h=0ff64969b071c9954b5187adf209450124ee75dd;hb=7907385999b4a83d37ed31d334f3ed9ca02983a1;hp=0af571610fe9510c553551e3f599caf4affaf85e;hpb=c0259626b6036a886f10c40b85f2d1b36118aeb9;p=rust.git diff --git a/compiler/rustc_data_structures/src/transitive_relation.rs b/compiler/rustc_data_structures/src/transitive_relation.rs index 0af571610fe..0ff64969b07 100644 --- a/compiler/rustc_data_structures/src/transitive_relation.rs +++ b/compiler/rustc_data_structures/src/transitive_relation.rs @@ -49,7 +49,7 @@ struct Edge { target: Index, } -impl TransitiveRelation { +impl TransitiveRelation { pub fn is_empty(&self) -> bool { self.edges.is_empty() } @@ -58,8 +58,8 @@ pub fn elements(&self) -> impl Iterator { self.elements.iter() } - fn index(&self, a: &T) -> Option { - self.elements.get_index_of(a).map(Index) + fn index(&self, a: T) -> Option { + self.elements.get_index_of(&a).map(Index) } fn add_index(&mut self, a: T) -> Index { @@ -76,12 +76,12 @@ fn add_index(&mut self, a: T) -> Index { /// `None`. pub fn maybe_map(&self, mut f: F) -> Option> where - F: FnMut(&T) -> Option, - U: Clone + Debug + Eq + Hash + Clone, + F: FnMut(T) -> Option, + U: Clone + Debug + Eq + Hash + Copy, { let mut result = TransitiveRelation::default(); for edge in &self.edges { - result.add(f(&self.elements[edge.source.0])?, f(&self.elements[edge.target.0])?); + result.add(f(self.elements[edge.source.0])?, f(self.elements[edge.target.0])?); } Some(result) } @@ -100,7 +100,7 @@ pub fn add(&mut self, a: T, b: T) { } /// Checks whether `a < target` (transitively) - pub fn contains(&self, a: &T, b: &T) -> bool { + pub fn contains(&self, a: T, b: T) -> bool { match (self.index(a), self.index(b)) { (Some(a), Some(b)) => self.with_closure(|closure| closure.contains(a.0, b.0)), (None, _) | (_, None) => false, @@ -113,10 +113,10 @@ pub fn contains(&self, a: &T, b: &T) -> bool { /// Really this probably ought to be `impl Iterator`, but /// I'm too lazy to make that work, and -- given the caching /// strategy -- it'd be a touch tricky anyhow. - pub fn reachable_from(&self, a: &T) -> Vec<&T> { + pub fn reachable_from(&self, a: T) -> Vec { match self.index(a) { Some(a) => { - self.with_closure(|closure| closure.iter(a.0).map(|i| &self.elements[i]).collect()) + self.with_closure(|closure| closure.iter(a.0).map(|i| self.elements[i]).collect()) } None => vec![], } @@ -157,7 +157,7 @@ pub fn reachable_from(&self, a: &T) -> Vec<&T> { /// a -> a1 /// b -> b1 /// ``` - pub fn postdom_upper_bound(&self, a: &T, b: &T) -> Option<&T> { + pub fn postdom_upper_bound(&self, a: T, b: T) -> Option { let mubs = self.minimal_upper_bounds(a, b); self.mutual_immediate_postdominator(mubs) } @@ -165,7 +165,7 @@ pub fn postdom_upper_bound(&self, a: &T, b: &T) -> Option<&T> { /// Viewing the relation as a graph, computes the "mutual /// immediate postdominator" of a set of points (if one /// exists). See `postdom_upper_bound` for details. - pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<&'a T>) -> Option<&'a T> { + pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec) -> Option { loop { match mubs.len() { 0 => return None, @@ -189,7 +189,7 @@ pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<&'a T>) -> Opt /// internal indices). /// /// Note that this set can, in principle, have any size. - pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> { + pub fn minimal_upper_bounds(&self, a: T, b: T) -> Vec { let (Some(mut a), Some(mut b)) = (self.index(a), self.index(b)) else { return vec![]; }; @@ -267,7 +267,7 @@ pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> { lub_indices .into_iter() .rev() // (4) - .map(|i| &self.elements[i]) + .map(|i| self.elements[i]) .collect() } @@ -282,7 +282,7 @@ pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> { /// (where the relation is encoding the `<=` relation for the lattice). /// So e.g., if the relation is `->` and we have /// - /// ``` + /// ```text /// a -> b -> d -> f /// | ^ /// +--> c -> e ---+ @@ -290,7 +290,7 @@ pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> { /// /// then `parents(a)` returns `[b, c]`. The `postdom_parent` function /// would further reduce this to just `f`. - pub fn parents(&self, a: &T) -> Vec<&T> { + pub fn parents(&self, a: T) -> Vec { let Some(a) = self.index(a) else { return vec![]; }; @@ -314,7 +314,7 @@ pub fn parents(&self, a: &T) -> Vec<&T> { ancestors .into_iter() .rev() // (4) - .map(|i| &self.elements[i]) + .map(|i| self.elements[i]) .collect() } @@ -350,10 +350,10 @@ fn compute_closure(&self) -> BitMatrix { /// Lists all the base edges in the graph: the initial _non-transitive_ set of element /// relations, which will be later used as the basis for the transitive closure computation. - pub fn base_edges(&self) -> impl Iterator { + pub fn base_edges(&self) -> impl Iterator + '_ { self.edges .iter() - .map(move |edge| (&self.elements[edge.source.0], &self.elements[edge.target.0])) + .map(move |edge| (self.elements[edge.source.0], self.elements[edge.target.0])) } }