4
4
//! various caches, it's not really advanced at the moment.
5
5
6
6
use hir:: db:: DefDatabase ;
7
- use ide_db:: base_db:: { CrateGraph , CrateId , SourceDatabase , SourceDatabaseExt } ;
7
+ use ide_db:: base_db:: { SourceDatabase , SourceDatabaseExt } ;
8
8
use rustc_hash:: FxHashSet ;
9
9
10
10
use crate :: RootDatabase ;
@@ -20,40 +20,29 @@ pub struct PrimeCachesProgress {
20
20
pub ( crate ) fn prime_caches ( db : & RootDatabase , cb : & ( dyn Fn ( PrimeCachesProgress ) + Sync ) ) {
21
21
let _p = profile:: span ( "prime_caches" ) ;
22
22
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.
24
27
let to_prime: FxHashSet < _ > = graph
25
28
. iter ( )
26
29
. filter ( |& id| {
27
30
let file_id = graph[ id] . root_file_id ;
28
31
let root_id = db. file_source_root ( file_id) ;
29
32
!db. source_root ( root_id) . is_library
30
33
} )
31
- . flat_map ( |id| graph. transitive_deps ( id ) )
34
+ . flat_map ( |id| graph[ id ] . dependencies . iter ( ) . map ( |krate| krate . crate_id ) )
32
35
. collect ( ) ;
33
36
34
- let topo = toposort ( & graph, & to_prime) ;
35
-
36
37
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.
37
38
// Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
38
39
// 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 ( ) {
40
42
let crate_name = graph[ crate_id] . display_name . as_deref ( ) . unwrap_or_default ( ) . to_string ( ) ;
41
43
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
44
46
db. import_map ( crate_id) ;
45
47
}
46
48
}
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