Move transitive_rev_deps from db trait away
This commit is contained in:
parent
277dffe9d6
commit
e796bd41f1
4 changed files with 35 additions and 39 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue