@@ -4,6 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4
4
use rustc_index:: vec:: { Idx , IndexVec } ;
5
5
use smallvec:: SmallVec ;
6
6
use rustc_data_structures:: sync:: { Lrc , Lock , AtomicU32 , AtomicU64 , Ordering } ;
7
+ use rustc_data_structures:: sharded:: { self , Sharded } ;
7
8
use std:: sync:: atomic:: Ordering :: SeqCst ;
8
9
use std:: env;
9
10
use std:: hash:: Hash ;
@@ -381,7 +382,7 @@ impl DepGraph {
381
382
#[ inline]
382
383
pub fn read ( & self , v : DepNode ) {
383
384
if let Some ( ref data) = self . data {
384
- let map = data. current . node_to_node_index . lock ( ) ;
385
+ let map = data. current . node_to_node_index . get_shard_by_value ( & v ) . lock ( ) ;
385
386
if let Some ( dep_node_index) = map. get ( & v) . copied ( ) {
386
387
std:: mem:: drop ( map) ;
387
388
data. read_index ( dep_node_index) ;
@@ -405,6 +406,7 @@ impl DepGraph {
405
406
. unwrap ( )
406
407
. current
407
408
. node_to_node_index
409
+ . get_shard_by_value ( dep_node)
408
410
. lock ( )
409
411
. get ( dep_node)
410
412
. cloned ( )
@@ -414,7 +416,11 @@ impl DepGraph {
414
416
#[ inline]
415
417
pub fn dep_node_exists ( & self , dep_node : & DepNode ) -> bool {
416
418
if let Some ( ref data) = self . data {
417
- data. current . node_to_node_index . lock ( ) . contains_key ( dep_node)
419
+ data. current
420
+ . node_to_node_index
421
+ . get_shard_by_value ( & dep_node)
422
+ . lock ( )
423
+ . contains_key ( dep_node)
418
424
} else {
419
425
false
420
426
}
@@ -595,7 +601,11 @@ impl DepGraph {
595
601
596
602
#[ cfg( not( parallel_compiler) ) ]
597
603
{
598
- debug_assert ! ( !data. current. node_to_node_index. lock( ) . contains_key( dep_node) ) ;
604
+ debug_assert ! ( !data. current
605
+ . node_to_node_index
606
+ . get_shard_by_value( dep_node)
607
+ . lock( )
608
+ . contains_key( dep_node) ) ;
599
609
debug_assert ! ( data. colors. get( prev_dep_node_index) . is_none( ) ) ;
600
610
}
601
611
@@ -927,7 +937,7 @@ struct DepNodeData {
927
937
/// acquire the lock on `data.`
928
938
pub ( super ) struct CurrentDepGraph {
929
939
data : Lock < IndexVec < DepNodeIndex , DepNodeData > > ,
930
- node_to_node_index : Lock < FxHashMap < DepNode , DepNodeIndex > > ,
940
+ node_to_node_index : Sharded < FxHashMap < DepNode , DepNodeIndex > > ,
931
941
932
942
/// Used to trap when a specific edge is added to the graph.
933
943
/// This is used for debug purposes and is only active with `debug_assertions`.
@@ -985,8 +995,8 @@ impl CurrentDepGraph {
985
995
986
996
CurrentDepGraph {
987
997
data : Lock :: new ( IndexVec :: with_capacity ( new_node_count_estimate) ) ,
988
- node_to_node_index : Lock :: new ( FxHashMap :: with_capacity_and_hasher (
989
- new_node_count_estimate,
998
+ node_to_node_index : Sharded :: new ( || FxHashMap :: with_capacity_and_hasher (
999
+ new_node_count_estimate / sharded :: SHARDS ,
990
1000
Default :: default ( ) ,
991
1001
) ) ,
992
1002
anon_id_seed : stable_hasher. finish ( ) ,
@@ -1035,7 +1045,10 @@ impl CurrentDepGraph {
1035
1045
edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
1036
1046
fingerprint : Fingerprint
1037
1047
) -> DepNodeIndex {
1038
- debug_assert ! ( !self . node_to_node_index. lock( ) . contains_key( & dep_node) ) ;
1048
+ debug_assert ! ( !self . node_to_node_index
1049
+ . get_shard_by_value( & dep_node)
1050
+ . lock( )
1051
+ . contains_key( & dep_node) ) ;
1039
1052
self . intern_node ( dep_node, edges, fingerprint)
1040
1053
}
1041
1054
@@ -1045,7 +1058,7 @@ impl CurrentDepGraph {
1045
1058
edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
1046
1059
fingerprint : Fingerprint
1047
1060
) -> DepNodeIndex {
1048
- match self . node_to_node_index . lock ( ) . entry ( dep_node) {
1061
+ match self . node_to_node_index . get_shard_by_value ( & dep_node ) . lock ( ) . entry ( dep_node) {
1049
1062
Entry :: Occupied ( entry) => * entry. get ( ) ,
1050
1063
Entry :: Vacant ( entry) => {
1051
1064
let mut data = self . data . lock ( ) ;
0 commit comments