Unnamed repository; edit this file 'description' to name the repository.
Move transitive_rev_deps from db trait away
| -rw-r--r-- | crates/base-db/src/input.rs | 58 | ||||
| -rw-r--r-- | crates/base-db/src/lib.rs | 10 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 4 | ||||
| -rw-r--r-- | crates/ide/src/lib.rs | 2 |
4 files changed, 35 insertions, 39 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index ffb7f78be6..5149d2d005 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -482,6 +482,37 @@ impl Crate { } deps.into_boxed_slice() } + + /// Returns all transitive reverse dependencies of the given crate, + /// including the crate itself. + /// + /// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications. + pub fn transitive_rev_deps(self, db: &dyn RootQueryDb) -> Box<[Crate]> { + let mut worklist = vec![self]; + let mut rev_deps = FxHashSet::default(); + rev_deps.insert(self); + + let mut inverted_graph = FxHashMap::<_, Vec<_>>::default(); + db.all_crates().iter().for_each(|&krate| { + krate + .data(db) + .dependencies + .iter() + .for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate)) + }); + + while let Some(krate) = worklist.pop() { + if let Some(crate_rev_deps) = inverted_graph.get(&krate) { + crate_rev_deps + .iter() + .copied() + .filter(|&rev_dep| rev_deps.insert(rev_dep)) + .for_each(|rev_dep| worklist.push(rev_dep)); + } + } + + rev_deps.into_iter().collect::<Box<_>>() + } } /// The mapping from [`UniqueCrateData`] to their [`Crate`] input. @@ -826,33 +857,6 @@ impl CrateGraphBuilder { } } -pub(crate) fn transitive_rev_deps(db: &dyn RootQueryDb, of: Crate) -> FxHashSet<Crate> { - let mut worklist = vec![of]; - let mut rev_deps = FxHashSet::default(); - rev_deps.insert(of); - - let mut inverted_graph = FxHashMap::<_, Vec<_>>::default(); - db.all_crates().iter().for_each(|&krate| { - krate - .data(db) - .dependencies - .iter() - .for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate)) - }); - - while let Some(krate) = worklist.pop() { - if let Some(crate_rev_deps) = inverted_graph.get(&krate) { - crate_rev_deps - .iter() - .copied() - .filter(|&rev_dep| rev_deps.insert(rev_dep)) - .for_each(|rev_dep| worklist.push(rev_dep)); - } - } - - rev_deps -} - impl BuiltCrateData { pub fn root_file_id(&self, db: &dyn salsa::Database) -> EditionedFileId { EditionedFileId::new(db, self.root_file_id, self.edition) diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index 4d226f5cbf..3629a001b8 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -26,7 +26,7 @@ pub use crate::{ }; use dashmap::{DashMap, mapref::entry::Entry}; pub use query_group::{self}; -use rustc_hash::{FxHashSet, FxHasher}; +use rustc_hash::FxHasher; use salsa::{Durability, Setter}; pub use semver::{BuildMetadata, Prerelease, Version, VersionReq}; use span::Edition; @@ -256,14 +256,6 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database { /// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications. #[salsa::input] fn all_crates(&self) -> Arc<Box<[Crate]>>; - - /// Returns all transitive reverse dependencies of the given crate, - /// including the crate itself. - /// - /// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications. - #[salsa::invoke(input::transitive_rev_deps)] - #[salsa::transparent] - fn transitive_rev_deps(&self, of: Crate) -> FxHashSet<Crate>; } #[salsa_macros::db] diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index aec90deca9..5400003f59 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -247,7 +247,7 @@ impl Crate { self, db: &dyn HirDatabase, ) -> impl Iterator<Item = Crate> { - db.transitive_rev_deps(self.id).into_iter().map(|id| Crate { id }) + self.id.transitive_rev_deps(db).into_iter().map(|id| Crate { id }) } pub fn notable_traits_in_deps(self, db: &dyn HirDatabase) -> impl Iterator<Item = &TraitId> { @@ -4454,7 +4454,7 @@ impl Impl { let mut handle_impls = |impls: &TraitImpls| { impls.for_trait(trait_.id, |impls| all.extend(impls.iter().copied().map(Impl::from))); }; - for krate in db.transitive_rev_deps(module.krate()) { + for krate in module.krate().transitive_rev_deps(db) { handle_impls(TraitImpls::for_crate(db, krate)); } if let Some(block) = module.containing_block() diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 2609457573..113cb83d17 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -642,7 +642,7 @@ impl Analysis { /// Returns crates that this file belongs to. pub fn transitive_rev_deps(&self, crate_id: Crate) -> Cancellable<Vec<Crate>> { - self.with_db(|db| Vec::from_iter(db.transitive_rev_deps(crate_id))) + self.with_db(|db| Vec::from_iter(crate_id.transitive_rev_deps(db))) } /// Returns crates that this file *might* belong to. |