@@ -3,7 +3,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3
3
use rustc_data_structures:: profiling:: QueryInvocationId ;
4
4
use rustc_data_structures:: sharded:: { self , Sharded } ;
5
5
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
6
- use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
6
+ use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , LockGuard , Lrc , Ordering } ;
7
7
use rustc_data_structures:: unlikely;
8
8
use rustc_errors:: Diagnostic ;
9
9
use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -135,16 +135,14 @@ impl<K: DepKind> DepGraph<K> {
135
135
}
136
136
137
137
pub fn query ( & self ) -> DepGraphQuery < K > {
138
- // We call this before acquiring locks, since it also acquires them.
139
- // The extra locking is not a big deal, as this gets called rarely.
140
- let edge_count = self . edge_count ( ) ;
141
138
let data = self . data . as_ref ( ) . unwrap ( ) ;
142
139
let previous = & data. previous ;
143
140
144
141
// Note locking order: `prev_index_to_index`, then `data`.
145
142
let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
146
143
let data = data. current . data . lock ( ) ;
147
144
let node_count = data. hybrid_indices . len ( ) ;
145
+ let edge_count = self . edge_count ( & data) ;
148
146
149
147
let mut nodes = Vec :: with_capacity ( node_count) ;
150
148
let mut edge_list_indices = Vec :: with_capacity ( node_count) ;
@@ -566,14 +564,13 @@ impl<K: DepKind> DepGraph<K> {
566
564
}
567
565
}
568
566
569
- fn edge_count ( & self ) -> usize {
567
+ fn edge_count ( & self , node_data : & LockGuard < ' _ , DepNodeData < K > > ) -> usize {
570
568
let data = self . data . as_ref ( ) . unwrap ( ) ;
571
569
let previous = & data. previous ;
572
- let data = data. current . data . lock ( ) ;
573
570
574
- let mut edge_count = data . unshared_edges . len ( ) ;
571
+ let mut edge_count = node_data . unshared_edges . len ( ) ;
575
572
576
- for & hybrid_index in data . hybrid_indices . iter ( ) {
573
+ for & hybrid_index in node_data . hybrid_indices . iter ( ) {
577
574
if let HybridIndex :: DarkGreen ( prev_index) = hybrid_index. into ( ) {
578
575
edge_count += previous. edge_targets_from ( prev_index) . len ( )
579
576
}
@@ -585,16 +582,14 @@ impl<K: DepKind> DepGraph<K> {
585
582
pub fn serialize ( & self ) -> SerializedDepGraph < K > {
586
583
type SDNI = SerializedDepNodeIndex ;
587
584
588
- // We call this before acquiring locks, since it also acquires them.
589
- // The extra locking is not a big deal, as this only gets called once.
590
- let edge_count = self . edge_count ( ) ;
591
585
let data = self . data . as_ref ( ) . unwrap ( ) ;
592
586
let previous = & data. previous ;
593
587
594
588
// Note locking order: `prev_index_to_index`, then `data`.
595
589
let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
596
590
let data = data. current . data . lock ( ) ;
597
591
let node_count = data. hybrid_indices . len ( ) ;
592
+ let edge_count = self . edge_count ( & data) ;
598
593
599
594
let mut nodes = IndexVec :: with_capacity ( node_count) ;
600
595
let mut fingerprints = IndexVec :: with_capacity ( node_count) ;
0 commit comments