From 45a8f37b6ae230db6c30c013f17d8aebac98a5e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Mar 2021 12:49:55 +0300 Subject: Compute more mathematically well-rounded notion of transitive deps 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. --- crates/base_db/src/input.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/base_db') diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index e9e8dfc2e..248ab1de2 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -274,13 +274,15 @@ impl CrateGraph { deps.into_iter() } - /// Returns an iterator over all transitive reverse dependencies of the given crate. + /// Returns all transitive reverse dependencies of the given crate, + /// including the crate itself. pub fn transitive_reverse_dependencies( &self, of: CrateId, ) -> impl Iterator + '_ { let mut worklist = vec![of]; let mut rev_deps = FxHashSet::default(); + rev_deps.insert(of); let mut inverted_graph = FxHashMap::<_, Vec<_>>::default(); self.arena.iter().for_each(|(&krate, data)| { data.dependencies -- cgit v1.2.3