@@ -79,14 +79,14 @@ struct DepGraphData {
7979 loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
8080}
8181
82- pub fn hash_result < R > ( hcx : & mut StableHashingContext < ' _ > , result : & R ) -> Option < Fingerprint >
82+ pub fn hash_result < R > ( hcx : & mut StableHashingContext < ' _ > , result : & R ) -> Fingerprint
8383where
8484 R : for < ' a > HashStable < StableHashingContext < ' a > > ,
8585{
8686 let mut stable_hasher = StableHasher :: new ( ) ;
8787 result. hash_stable ( hcx, & mut stable_hasher) ;
8888
89- Some ( stable_hasher. finish ( ) )
89+ stable_hasher. finish ( )
9090}
9191
9292impl DepGraph {
@@ -194,7 +194,7 @@ impl DepGraph {
194194 cx : C ,
195195 arg : A ,
196196 task : fn ( C , A ) -> R ,
197- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
197+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
198198 ) -> ( R , DepNodeIndex )
199199 where
200200 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
@@ -230,7 +230,8 @@ impl DepGraph {
230230 |data, key, fingerprint, _| {
231231 data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
232232 } ,
233- hash_result :: < R > )
233+ Some ( hash_result :: < R > )
234+ )
234235 }
235236
236237 fn with_task_impl < ' a , C , A , R > (
@@ -245,24 +246,21 @@ impl DepGraph {
245246 DepNode ,
246247 Fingerprint ,
247248 Option < TaskDeps > ) -> DepNodeIndex ,
248- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
249+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
249250 ) -> ( R , DepNodeIndex )
250251 where
251252 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
252253 {
253254 if let Some ( ref data) = self . data {
254255 let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
255256
256- // In incremental mode, hash the result of the task. We don't
257- // do anything with the hash yet, but we are computing it
258- // anyway so that
259- // - we make sure that the infrastructure works and
260- // - we can get an idea of the runtime cost.
261- let mut hcx = cx. get_stable_hashing_context ( ) ;
262-
263- if cfg ! ( debug_assertions) {
264- profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskBegin ( key. clone ( ) ) )
265- } ;
257+ let hcx = hash_result. as_ref ( ) . map ( |_| {
258+ let hcx = cx. get_stable_hashing_context ( ) ;
259+ if cfg ! ( debug_assertions) {
260+ profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskBegin ( key. clone ( ) ) )
261+ } ;
262+ hcx
263+ } ) ;
266264
267265 let result = if no_tcx {
268266 task ( cx, arg)
@@ -280,10 +278,12 @@ impl DepGraph {
280278 } ;
281279
282280 if cfg ! ( debug_assertions) {
283- profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
281+ hcx . as_ref ( ) . map ( |hcx| profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd ) ) ;
284282 } ;
285283
286- let current_fingerprint = hash_result ( & mut hcx, & result) ;
284+ let current_fingerprint = hash_result. map ( |hash_result| {
285+ hash_result ( & mut hcx. unwrap ( ) , & result)
286+ } ) ;
287287
288288 let dep_node_index = finish_task_and_alloc_depnode (
289289 & data. current ,
@@ -292,7 +292,9 @@ impl DepGraph {
292292 task_deps. map ( |lock| lock. into_inner ( ) ) ,
293293 ) ;
294294
295- let print_status = cfg ! ( debug_assertions) && hcx. sess ( ) . opts . debugging_opts . dep_tasks ;
295+ let print_status = cfg ! ( debug_assertions) && ty:: tls:: with_opt ( |tcx| {
296+ tcx. map ( |tcx| tcx. sess . opts . debugging_opts . dep_tasks ) . unwrap_or ( false )
297+ } ) ;
296298
297299 // Determine the color of the new DepNode.
298300 if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
@@ -379,7 +381,7 @@ impl DepGraph {
379381 cx : C ,
380382 arg : A ,
381383 task : fn ( C , A ) -> R ,
382- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
384+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
383385 ) -> ( R , DepNodeIndex )
384386 where
385387 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
0 commit comments