11use std:: hash:: Hash ;
2- use std:: mem:: ManuallyDrop ;
32
43use rustc_data_structures:: hash_table:: { Entry , HashTable } ;
54use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -135,6 +134,7 @@ where
135134 state : & ' tcx QueryState < ' tcx , K > ,
136135 key : K ,
137136 key_hash : u64 ,
137+ poison_on_drop : bool ,
138138}
139139
140140impl < ' tcx , K > ActiveJobGuard < ' tcx , K >
@@ -143,21 +143,27 @@ where
143143{
144144 /// Completes the query by updating the query cache with the `result`,
145145 /// signals the waiter, and forgets the guard so it won't poison the query.
146- fn complete < C > ( self , cache : & C , value : C :: Value , dep_node_index : DepNodeIndex )
146+ #[ inline]
147+ fn complete < C > ( mut self , cache : & C , value : C :: Value , dep_node_index : DepNodeIndex )
147148 where
148149 C : QueryCache < Key = K > ,
149150 {
150151 // Mark as complete before we remove the job from the active state
151152 // so no other thread can re-execute this query.
152153 cache. complete ( self . key , value, dep_node_index) ;
153154
154- let mut this = ManuallyDrop :: new ( self ) ;
155-
156155 // Drop everything without poisoning the query.
157- this. drop_and_maybe_poison ( /* poison */ false ) ;
156+ self . poison_on_drop = false ;
157+
158+ // `drop` is now called because this method consumes `self`.
158159 }
160+ }
159161
160- fn drop_and_maybe_poison ( & mut self , poison : bool ) {
162+ impl < ' tcx , K > Drop for ActiveJobGuard < ' tcx , K >
163+ where
164+ K : Eq + Hash + Copy ,
165+ {
166+ fn drop ( & mut self ) {
161167 let status = {
162168 let mut shard = self . state . active . lock_shard_by_hash ( self . key_hash ) ;
163169 match shard. find_entry ( self . key_hash , equivalent_key ( self . key ) ) {
@@ -169,7 +175,7 @@ where
169175 }
170176 Ok ( occupied) => {
171177 let ( ( key, status) , vacant) = occupied. remove ( ) ;
172- if poison {
178+ if self . poison_on_drop {
173179 vacant. insert ( ( key, ActiveKeyStatus :: Poisoned ) ) ;
174180 }
175181 status
@@ -185,18 +191,6 @@ where
185191 }
186192}
187193
188- impl < ' tcx , K > Drop for ActiveJobGuard < ' tcx , K >
189- where
190- K : Eq + Hash + Copy ,
191- {
192- #[ inline( never) ]
193- #[ cold]
194- fn drop ( & mut self ) {
195- // Poison the query so jobs waiting on it panic.
196- self . drop_and_maybe_poison ( /* poison */ true ) ;
197- }
198- }
199-
200194#[ cold]
201195#[ inline( never) ]
202196fn cycle_error < ' tcx , C : QueryCache > (
@@ -340,7 +334,7 @@ fn execute_job<'tcx, C: QueryCache, const INCR: bool>(
340334) -> ( C :: Value , Option < DepNodeIndex > ) {
341335 // Set up a guard object that will automatically poison the query if a
342336 // panic occurs while executing the query (or any intermediate plumbing).
343- let job_guard = ActiveJobGuard { state : & query. state , key, key_hash } ;
337+ let job_guard = ActiveJobGuard { state : & query. state , key, key_hash, poison_on_drop : true } ;
344338
345339 debug_assert_eq ! ( tcx. dep_graph. is_fully_enabled( ) , INCR ) ;
346340
0 commit comments