@@ -8,6 +8,7 @@ use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
88use rustc_errors:: Diagnostic ;
99use rustc_hir:: def_id:: DefId ;
1010use rustc_index:: vec:: { Idx , IndexVec } ;
11+ use rustc_session:: Session ;
1112use smallvec:: SmallVec ;
1213use std:: collections:: hash_map:: Entry ;
1314use std:: env;
@@ -338,13 +339,19 @@ impl DepGraph {
338339
339340 ( result, dep_node_index)
340341 } else {
341- ( task ( cx, arg) , self . next_virtual_depnode_index ( ) )
342+ let sess = cx. get_stable_hashing_context ( ) . sess ( ) ;
343+ ( task ( cx, arg) , self . next_virtual_depnode_index ( sess) )
342344 }
343345 }
344346
345347 /// Executes something within an "anonymous" task, that is, a task the
346348 /// `DepNode` of which is determined by the list of inputs it read from.
347- pub fn with_anon_task < OP , R > ( & self , dep_kind : DepKind , op : OP ) -> ( R , DepNodeIndex )
349+ pub fn with_anon_task < OP , R > (
350+ & self ,
351+ sess : & Session ,
352+ dep_kind : DepKind ,
353+ op : OP ,
354+ ) -> ( R , DepNodeIndex )
348355 where
349356 OP : FnOnce ( ) -> R ,
350357 {
@@ -368,7 +375,7 @@ impl DepGraph {
368375 let dep_node_index = data. current . complete_anon_task ( dep_kind, task_deps) ;
369376 ( result, dep_node_index)
370377 } else {
371- ( op ( ) , self . next_virtual_depnode_index ( ) )
378+ ( op ( ) , self . next_virtual_depnode_index ( sess ) )
372379 }
373380 }
374381
@@ -909,9 +916,13 @@ impl DepGraph {
909916 }
910917 }
911918
912- fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
913- let index = self . virtual_dep_node_index . fetch_add ( 1 , Relaxed ) ;
914- DepNodeIndex :: from_u32 ( index)
919+ fn next_virtual_depnode_index ( & self , sess : & Session ) -> DepNodeIndex {
920+ if unlikely ! ( sess. prof. enabled( ) ) {
921+ let index = self . virtual_dep_node_index . fetch_add ( 1 , Relaxed ) ;
922+ DepNodeIndex :: from_u32 ( index)
923+ } else {
924+ DepNodeIndex :: INVALID
925+ }
915926 }
916927}
917928
0 commit comments