Skip to content

Commit e375181

Browse files
committed
Move transitive_rev_deps from db trait away
1 parent 404fbd3 commit e375181

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

crates/base-db/src/input.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,37 @@ impl Crate {
482482
}
483483
deps.into_boxed_slice()
484484
}
485+
486+
/// Returns all transitive reverse dependencies of the given crate,
487+
/// including the crate itself.
488+
///
489+
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
490+
pub fn transitive_rev_deps(self, db: &dyn RootQueryDb) -> Box<[Crate]> {
491+
let mut worklist = vec![self];
492+
let mut rev_deps = FxHashSet::default();
493+
rev_deps.insert(self);
494+
495+
let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
496+
db.all_crates().iter().for_each(|&krate| {
497+
krate
498+
.data(db)
499+
.dependencies
500+
.iter()
501+
.for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
502+
});
503+
504+
while let Some(krate) = worklist.pop() {
505+
if let Some(crate_rev_deps) = inverted_graph.get(&krate) {
506+
crate_rev_deps
507+
.iter()
508+
.copied()
509+
.filter(|&rev_dep| rev_deps.insert(rev_dep))
510+
.for_each(|rev_dep| worklist.push(rev_dep));
511+
}
512+
}
513+
514+
rev_deps.into_iter().collect::<Box<_>>()
515+
}
485516
}
486517

487518
/// The mapping from [`UniqueCrateData`] to their [`Crate`] input.
@@ -826,33 +857,6 @@ impl CrateGraphBuilder {
826857
}
827858
}
828859

829-
pub(crate) fn transitive_rev_deps(db: &dyn RootQueryDb, of: Crate) -> FxHashSet<Crate> {
830-
let mut worklist = vec![of];
831-
let mut rev_deps = FxHashSet::default();
832-
rev_deps.insert(of);
833-
834-
let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
835-
db.all_crates().iter().for_each(|&krate| {
836-
krate
837-
.data(db)
838-
.dependencies
839-
.iter()
840-
.for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
841-
});
842-
843-
while let Some(krate) = worklist.pop() {
844-
if let Some(crate_rev_deps) = inverted_graph.get(&krate) {
845-
crate_rev_deps
846-
.iter()
847-
.copied()
848-
.filter(|&rev_dep| rev_deps.insert(rev_dep))
849-
.for_each(|rev_dep| worklist.push(rev_dep));
850-
}
851-
}
852-
853-
rev_deps
854-
}
855-
856860
impl BuiltCrateData {
857861
pub fn root_file_id(&self, db: &dyn salsa::Database) -> EditionedFileId {
858862
EditionedFileId::new(db, self.root_file_id, self.edition)

crates/base-db/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use crate::{
2626
};
2727
use dashmap::{DashMap, mapref::entry::Entry};
2828
pub use query_group::{self};
29-
use rustc_hash::{FxHashSet, FxHasher};
29+
use rustc_hash::FxHasher;
3030
use salsa::{Durability, Setter};
3131
pub use semver::{BuildMetadata, Prerelease, Version, VersionReq};
3232
use span::Edition;
@@ -256,14 +256,6 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database {
256256
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
257257
#[salsa::input]
258258
fn all_crates(&self) -> Arc<Box<[Crate]>>;
259-
260-
/// Returns all transitive reverse dependencies of the given crate,
261-
/// including the crate itself.
262-
///
263-
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
264-
#[salsa::invoke(input::transitive_rev_deps)]
265-
#[salsa::transparent]
266-
fn transitive_rev_deps(&self, of: Crate) -> FxHashSet<Crate>;
267259
}
268260

269261
#[salsa_macros::db]

crates/hir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Crate {
247247
self,
248248
db: &dyn HirDatabase,
249249
) -> impl Iterator<Item = Crate> {
250-
db.transitive_rev_deps(self.id).into_iter().map(|id| Crate { id })
250+
self.id.transitive_rev_deps(db).into_iter().map(|id| Crate { id })
251251
}
252252

253253
pub fn notable_traits_in_deps(self, db: &dyn HirDatabase) -> impl Iterator<Item = &TraitId> {
@@ -4454,7 +4454,7 @@ impl Impl {
44544454
let mut handle_impls = |impls: &TraitImpls| {
44554455
impls.for_trait(trait_.id, |impls| all.extend(impls.iter().copied().map(Impl::from)));
44564456
};
4457-
for krate in db.transitive_rev_deps(module.krate()) {
4457+
for krate in module.krate().transitive_rev_deps(db) {
44584458
handle_impls(TraitImpls::for_crate(db, krate));
44594459
}
44604460
if let Some(block) = module.containing_block()

crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl Analysis {
642642

643643
/// Returns crates that this file belongs to.
644644
pub fn transitive_rev_deps(&self, crate_id: Crate) -> Cancellable<Vec<Crate>> {
645-
self.with_db(|db| Vec::from_iter(db.transitive_rev_deps(crate_id)))
645+
self.with_db(|db| Vec::from_iter(crate_id.transitive_rev_deps(db)))
646646
}
647647

648648
/// Returns crates that this file *might* belong to.

0 commit comments

Comments
 (0)