@@ -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 {
@@ -193,7 +193,7 @@ impl DepGraph {
193193 cx : C ,
194194 arg : A ,
195195 task : fn ( C , A ) -> R ,
196- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
196+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
197197 ) -> ( R , DepNodeIndex )
198198 where
199199 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
@@ -229,7 +229,8 @@ impl DepGraph {
229229 |data, key, fingerprint, _| {
230230 data. borrow_mut ( ) . alloc_node ( key, SmallVec :: new ( ) , fingerprint)
231231 } ,
232- hash_result :: < R > )
232+ Some ( hash_result :: < R > )
233+ )
233234 }
234235
235236 fn with_task_impl < ' a , C , A , R > (
@@ -244,24 +245,21 @@ impl DepGraph {
244245 DepNode ,
245246 Fingerprint ,
246247 Option < TaskDeps > ) -> DepNodeIndex ,
247- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
248+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
248249 ) -> ( R , DepNodeIndex )
249250 where
250251 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
251252 {
252253 if let Some ( ref data) = self . data {
253254 let task_deps = create_task ( key) . map ( |deps| Lock :: new ( deps) ) ;
254255
255- // In incremental mode, hash the result of the task. We don't
256- // do anything with the hash yet, but we are computing it
257- // anyway so that
258- // - we make sure that the infrastructure works and
259- // - we can get an idea of the runtime cost.
260- let mut hcx = cx. get_stable_hashing_context ( ) ;
261-
262- if cfg ! ( debug_assertions) {
263- profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskBegin ( key. clone ( ) ) )
264- } ;
256+ let hcx = hash_result. as_ref ( ) . map ( |_| {
257+ let hcx = cx. get_stable_hashing_context ( ) ;
258+ if cfg ! ( debug_assertions) {
259+ profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskBegin ( key. clone ( ) ) )
260+ } ;
261+ hcx
262+ } ) ;
265263
266264 let result = if no_tcx {
267265 task ( cx, arg)
@@ -279,10 +277,12 @@ impl DepGraph {
279277 } ;
280278
281279 if cfg ! ( debug_assertions) {
282- profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd )
280+ hcx . as_ref ( ) . map ( |hcx| profq_msg ( hcx. sess ( ) , ProfileQueriesMsg :: TaskEnd ) ) ;
283281 } ;
284282
285- let current_fingerprint = hash_result ( & mut hcx, & result) ;
283+ let current_fingerprint = hash_result. map ( |hash_result| {
284+ hash_result ( & mut hcx. unwrap ( ) , & result)
285+ } ) ;
286286
287287 let dep_node_index = finish_task_and_alloc_depnode (
288288 & data. current ,
@@ -291,7 +291,9 @@ impl DepGraph {
291291 task_deps. map ( |lock| lock. into_inner ( ) ) ,
292292 ) ;
293293
294- let print_status = cfg ! ( debug_assertions) && hcx. sess ( ) . opts . debugging_opts . dep_tasks ;
294+ let print_status = cfg ! ( debug_assertions) && ty:: tls:: with_opt ( |tcx| {
295+ tcx. map ( |tcx| tcx. sess . opts . debugging_opts . dep_tasks ) . unwrap_or ( false )
296+ } ) ;
295297
296298 // Determine the color of the new DepNode.
297299 if let Some ( prev_index) = data. previous . node_to_index_opt ( & key) {
@@ -378,7 +380,7 @@ impl DepGraph {
378380 cx : C ,
379381 arg : A ,
380382 task : fn ( C , A ) -> R ,
381- hash_result : impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Option < Fingerprint > ,
383+ hash_result : Option < impl FnOnce ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
382384 ) -> ( R , DepNodeIndex )
383385 where
384386 C : DepGraphSafe + StableHashingContextProvider < ' a > ,
0 commit comments