@@ -83,9 +83,12 @@ pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>(
8383 Some ( ( ) )
8484}
8585
86- /// A type representing the responsibility to execute the job in the `job` field.
87- /// This will poison the relevant query if dropped.
88- struct JobOwner < ' tcx , K >
86+ /// Guard object representing the responsibility to execute a query job and
87+ /// mark it as completed.
88+ ///
89+ /// This will poison the relevant query key if it is dropped without calling
90+ /// [`Self::complete`].
91+ struct ActiveJobGuard < ' tcx , K >
8992where
9093 K : Eq + Hash + Copy ,
9194{
@@ -139,12 +142,12 @@ where
139142 }
140143}
141144
142- impl < ' tcx , K > JobOwner < ' tcx , K >
145+ impl < ' tcx , K > ActiveJobGuard < ' tcx , K >
143146where
144147 K : Eq + Hash + Copy ,
145148{
146149 /// Completes the query by updating the query cache with the `result`,
147- /// signals the waiter and forgets the JobOwner, so it won't poison the query
150+ /// signals the waiter, and forgets the guard so it won't poison the query.
148151 fn complete < C > ( self , cache : & C , key_hash : u64 , result : C :: Value , dep_node_index : DepNodeIndex )
149152 where
150153 C : QueryCache < Key = K > ,
@@ -176,7 +179,7 @@ where
176179 }
177180}
178181
179- impl < ' tcx , K > Drop for JobOwner < ' tcx , K >
182+ impl < ' tcx , K > Drop for ActiveJobGuard < ' tcx , K >
180183where
181184 K : Eq + Hash + Copy ,
182185{
@@ -356,11 +359,13 @@ fn execute_job<'tcx, Q, const INCR: bool>(
356359where
357360 Q : QueryDispatcher < ' tcx , Qcx = QueryCtxt < ' tcx > > ,
358361{
359- // Use `JobOwner` so the query will be poisoned if executing it panics.
360- let job_owner = JobOwner { state, key } ;
362+ // Set up a guard object that will automatically poison the query if a
363+ // panic occurs while executing the query (or any intermediate plumbing).
364+ let job_guard = ActiveJobGuard { state, key } ;
361365
362366 debug_assert_eq ! ( qcx. tcx. dep_graph. is_fully_enabled( ) , INCR ) ;
363367
368+ // Delegate to another function to actually execute the query job.
364369 let ( result, dep_node_index) = if INCR {
365370 execute_job_incr ( query, qcx, qcx. tcx . dep_graph . data ( ) . unwrap ( ) , key, dep_node, id)
366371 } else {
@@ -402,7 +407,9 @@ where
402407 }
403408 }
404409 }
405- job_owner. complete ( cache, key_hash, result, dep_node_index) ;
410+
411+ // Tell the guard to perform completion bookkeeping, and also to not poison the query.
412+ job_guard. complete ( cache, key_hash, result, dep_node_index) ;
406413
407414 ( result, Some ( dep_node_index) )
408415}
0 commit comments