diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-23 10:20:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-23 10:20:47 +0000 |
commit | 1efd220f2f844596dd22bfd73a8a0c596354be38 (patch) | |
tree | eeba1d8e0e89d6d40ad4802f32dc72af0dfa3e15 /crates/base_db | |
parent | bf3a8eb40a1c684ffc9cb40477558ec276253c3b (diff) | |
parent | fa9c6eb4560c3c72a726dba4210af2edbb3dd4bb (diff) |
Merge #8162
8162: Compute more mathematically well-rounded notion of transitive deps r=Veykril a=matklad
By including the crate itself, we make the resulting set closed with
respect to `transitve_reveres_dependencies` operation, as it becomes a
proper transitive closure. This just feels more proper and mathy.
And, indeed, this actually allows us to simplify call sites somewhat.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/base_db')
-rw-r--r-- | crates/base_db/src/input.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index e9e8dfc2e..07628935f 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs | |||
@@ -257,7 +257,8 @@ impl CrateGraph { | |||
257 | self.arena.keys().copied() | 257 | self.arena.keys().copied() |
258 | } | 258 | } |
259 | 259 | ||
260 | /// Returns an iterator over all transitive dependencies of the given crate. | 260 | /// Returns an iterator over all transitive dependencies of the given crate, |
261 | /// including the crate itself. | ||
261 | pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ { | 262 | pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ { |
262 | let mut worklist = vec![of]; | 263 | let mut worklist = vec![of]; |
263 | let mut deps = FxHashSet::default(); | 264 | let mut deps = FxHashSet::default(); |
@@ -270,17 +271,16 @@ impl CrateGraph { | |||
270 | worklist.extend(self[krate].dependencies.iter().map(|dep| dep.crate_id)); | 271 | worklist.extend(self[krate].dependencies.iter().map(|dep| dep.crate_id)); |
271 | } | 272 | } |
272 | 273 | ||
273 | deps.remove(&of); | ||
274 | deps.into_iter() | 274 | deps.into_iter() |
275 | } | 275 | } |
276 | 276 | ||
277 | /// Returns an iterator over all transitive reverse dependencies of the given crate. | 277 | /// Returns all transitive reverse dependencies of the given crate, |
278 | pub fn transitive_reverse_dependencies( | 278 | /// including the crate itself. |
279 | &self, | 279 | pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ { |
280 | of: CrateId, | ||
281 | ) -> impl Iterator<Item = CrateId> + '_ { | ||
282 | let mut worklist = vec![of]; | 280 | let mut worklist = vec![of]; |
283 | let mut rev_deps = FxHashSet::default(); | 281 | let mut rev_deps = FxHashSet::default(); |
282 | rev_deps.insert(of); | ||
283 | |||
284 | let mut inverted_graph = FxHashMap::<_, Vec<_>>::default(); | 284 | let mut inverted_graph = FxHashMap::<_, Vec<_>>::default(); |
285 | self.arena.iter().for_each(|(&krate, data)| { | 285 | self.arena.iter().for_each(|(&krate, data)| { |
286 | data.dependencies | 286 | data.dependencies |