Skip to content

Commit d012a20

Browse files
committed
Only prime direct dependencies of the workspace crates
1 parent 2534b7d commit d012a20

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

crates/ide/src/prime_caches.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! various caches, it's not really advanced at the moment.
55
66
use hir::db::DefDatabase;
7-
use ide_db::base_db::{CrateGraph, CrateId, SourceDatabase, SourceDatabaseExt};
7+
use ide_db::base_db::{SourceDatabase, SourceDatabaseExt};
88
use rustc_hash::FxHashSet;
99

1010
use crate::RootDatabase;
@@ -20,40 +20,29 @@ pub struct PrimeCachesProgress {
2020
pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) + Sync)) {
2121
let _p = profile::span("prime_caches");
2222
let graph = db.crate_graph();
23-
// We're only interested in the transitive dependencies of all workspace crates.
23+
// We're only interested in the workspace crates and the `ImportMap`s of their direct
24+
// dependencies, though in practice the latter also compute the `DefMap`s.
25+
// We don't prime transitive dependencies because they're generally not visible in
26+
// the current workspace.
2427
let to_prime: FxHashSet<_> = graph
2528
.iter()
2629
.filter(|&id| {
2730
let file_id = graph[id].root_file_id;
2831
let root_id = db.file_source_root(file_id);
2932
!db.source_root(root_id).is_library
3033
})
31-
.flat_map(|id| graph.transitive_deps(id))
34+
.flat_map(|id| graph[id].dependencies.iter().map(|krate| krate.crate_id))
3235
.collect();
3336

34-
let topo = toposort(&graph, &to_prime);
35-
3637
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.
3738
// Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
3839
// cancellation, so we cannot use rayon.
39-
for (i, &crate_id) in topo.iter().enumerate() {
40+
let n_total = to_prime.len();
41+
for (n_done, &crate_id) in to_prime.iter().enumerate() {
4042
let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string();
4143

42-
cb(PrimeCachesProgress { on_crate: crate_name, n_done: i, n_total: topo.len() });
43-
db.crate_def_map(crate_id);
44+
cb(PrimeCachesProgress { on_crate: crate_name, n_done, n_total });
45+
// This also computes the DefMap
4446
db.import_map(crate_id);
4547
}
4648
}
47-
48-
fn toposort(graph: &CrateGraph, crates: &FxHashSet<CrateId>) -> Vec<CrateId> {
49-
// Just subset the full topologically sorted set for simplicity.
50-
51-
let all = graph.crates_in_topological_order();
52-
let mut result = Vec::with_capacity(crates.len());
53-
for krate in all {
54-
if crates.contains(&krate) {
55-
result.push(krate);
56-
}
57-
}
58-
result
59-
}

0 commit comments

Comments
 (0)