9
9
use std:: { fmt, ops, panic:: RefUnwindSafe , str:: FromStr , sync:: Arc } ;
10
10
11
11
use cfg:: CfgOptions ;
12
- use rustc_hash:: { FxHashMap , FxHashSet } ;
12
+ use rustc_hash:: FxHashMap ;
13
+ use stdx:: hash:: { NoHashHashMap , NoHashHashSet } ;
13
14
use syntax:: SmolStr ;
14
15
use tt:: Subtree ;
15
- use vfs:: { file_set:: FileSet , FileId , VfsPath } ;
16
+ use vfs:: { file_set:: FileSet , AnchoredPath , FileId , VfsPath } ;
16
17
17
18
/// Files are grouped into source roots. A source root is a directory on the
18
19
/// file systems which is watched for changes. Typically it corresponds to a
@@ -31,22 +32,30 @@ pub struct SourceRoot {
31
32
/// Libraries are considered mostly immutable, this assumption is used to
32
33
/// optimize salsa's query structure
33
34
pub is_library : bool ,
34
- pub ( crate ) file_set : FileSet ,
35
+ file_set : FileSet ,
35
36
}
36
37
37
38
impl SourceRoot {
38
39
pub fn new_local ( file_set : FileSet ) -> SourceRoot {
39
40
SourceRoot { is_library : false , file_set }
40
41
}
42
+
41
43
pub fn new_library ( file_set : FileSet ) -> SourceRoot {
42
44
SourceRoot { is_library : true , file_set }
43
45
}
46
+
44
47
pub fn path_for_file ( & self , file : & FileId ) -> Option < & VfsPath > {
45
48
self . file_set . path_for_file ( file)
46
49
}
50
+
47
51
pub fn file_for_path ( & self , path : & VfsPath ) -> Option < & FileId > {
48
52
self . file_set . file_for_path ( path)
49
53
}
54
+
55
+ pub fn resolve_path ( & self , path : AnchoredPath < ' _ > ) -> Option < FileId > {
56
+ self . file_set . resolve_path ( path)
57
+ }
58
+
50
59
pub fn iter ( & self ) -> impl Iterator < Item = FileId > + ' _ {
51
60
self . file_set . iter ( )
52
61
}
@@ -72,12 +81,19 @@ impl SourceRoot {
72
81
/// <https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/architecture.md#serialization>
73
82
#[ derive( Debug , Clone , Default /* Serialize, Deserialize */ ) ]
74
83
pub struct CrateGraph {
75
- arena : FxHashMap < CrateId , CrateData > ,
84
+ arena : NoHashHashMap < CrateId , CrateData > ,
76
85
}
77
86
78
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
87
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
79
88
pub struct CrateId ( pub u32 ) ;
80
89
90
+ impl stdx:: hash:: NoHashHashable for CrateId { }
91
+ impl std:: hash:: Hash for CrateId {
92
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
93
+ self . 0 . hash ( state) ;
94
+ }
95
+ }
96
+
81
97
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
82
98
pub struct CrateName ( SmolStr ) ;
83
99
@@ -342,7 +358,7 @@ impl CrateGraph {
342
358
// Check if adding a dep from `from` to `to` creates a cycle. To figure
343
359
// that out, look for a path in the *opposite* direction, from `to` to
344
360
// `from`.
345
- if let Some ( path) = self . find_path ( & mut FxHashSet :: default ( ) , dep. crate_id , from) {
361
+ if let Some ( path) = self . find_path ( & mut NoHashHashSet :: default ( ) , dep. crate_id , from) {
346
362
let path = path. into_iter ( ) . map ( |it| ( it, self [ it] . display_name . clone ( ) ) ) . collect ( ) ;
347
363
let err = CyclicDependenciesError { path } ;
348
364
assert ! ( err. from( ) . 0 == from && err. to( ) . 0 == dep. crate_id) ;
@@ -365,7 +381,7 @@ impl CrateGraph {
365
381
/// including the crate itself.
366
382
pub fn transitive_deps ( & self , of : CrateId ) -> impl Iterator < Item = CrateId > {
367
383
let mut worklist = vec ! [ of] ;
368
- let mut deps = FxHashSet :: default ( ) ;
384
+ let mut deps = NoHashHashSet :: default ( ) ;
369
385
370
386
while let Some ( krate) = worklist. pop ( ) {
371
387
if !deps. insert ( krate) {
@@ -382,10 +398,10 @@ impl CrateGraph {
382
398
/// including the crate itself.
383
399
pub fn transitive_rev_deps ( & self , of : CrateId ) -> impl Iterator < Item = CrateId > {
384
400
let mut worklist = vec ! [ of] ;
385
- let mut rev_deps = FxHashSet :: default ( ) ;
401
+ let mut rev_deps = NoHashHashSet :: default ( ) ;
386
402
rev_deps. insert ( of) ;
387
403
388
- let mut inverted_graph = FxHashMap :: < _ , Vec < _ > > :: default ( ) ;
404
+ let mut inverted_graph = NoHashHashMap :: < _ , Vec < _ > > :: default ( ) ;
389
405
self . arena . iter ( ) . for_each ( |( & krate, data) | {
390
406
data. dependencies
391
407
. iter ( )
@@ -409,7 +425,7 @@ impl CrateGraph {
409
425
/// come before the crate itself).
410
426
pub fn crates_in_topological_order ( & self ) -> Vec < CrateId > {
411
427
let mut res = Vec :: new ( ) ;
412
- let mut visited = FxHashSet :: default ( ) ;
428
+ let mut visited = NoHashHashSet :: default ( ) ;
413
429
414
430
for krate in self . arena . keys ( ) . copied ( ) {
415
431
go ( self , & mut visited, & mut res, krate) ;
@@ -419,7 +435,7 @@ impl CrateGraph {
419
435
420
436
fn go (
421
437
graph : & CrateGraph ,
422
- visited : & mut FxHashSet < CrateId > ,
438
+ visited : & mut NoHashHashSet < CrateId > ,
423
439
res : & mut Vec < CrateId > ,
424
440
source : CrateId ,
425
441
) {
@@ -459,7 +475,7 @@ impl CrateGraph {
459
475
460
476
fn find_path (
461
477
& self ,
462
- visited : & mut FxHashSet < CrateId > ,
478
+ visited : & mut NoHashHashSet < CrateId > ,
463
479
from : CrateId ,
464
480
to : CrateId ,
465
481
) -> Option < Vec < CrateId > > {
0 commit comments