|
94 | 94 | { |
95 | 95 | state: &'tcx QueryState<'tcx, K>, |
96 | 96 | key: K, |
| 97 | + key_hash: u64, |
97 | 98 | } |
98 | 99 |
|
99 | 100 | #[cold] |
@@ -146,14 +147,13 @@ where |
146 | 147 | { |
147 | 148 | /// Completes the query by updating the query cache with the `result`, |
148 | 149 | /// signals the waiter, and forgets the guard so it won't poison the query. |
149 | | - fn complete<C>(self, cache: &C, key_hash: u64, result: C::Value, dep_node_index: DepNodeIndex) |
| 150 | + fn complete<C>(self, cache: &C, result: C::Value, dep_node_index: DepNodeIndex) |
150 | 151 | where |
151 | 152 | C: QueryCache<Key = K>, |
152 | 153 | { |
153 | | - let key = self.key; |
154 | | - let state = self.state; |
155 | | - |
156 | | - // Forget ourself so our destructor won't poison the query |
| 154 | + // Forget ourself so our destructor won't poison the query. |
| 155 | + // (Extract fields by value first to make sure we don't leak anything.) |
| 156 | + let Self { state, key, key_hash }: Self = self; |
157 | 157 | mem::forget(self); |
158 | 158 |
|
159 | 159 | // Mark as complete before we remove the job from the active state |
@@ -185,11 +185,10 @@ where |
185 | 185 | #[cold] |
186 | 186 | fn drop(&mut self) { |
187 | 187 | // Poison the query so jobs waiting on it panic. |
188 | | - let state = self.state; |
| 188 | + let Self { state, key, key_hash } = *self; |
189 | 189 | let job = { |
190 | | - let key_hash = sharded::make_hash(&self.key); |
191 | 190 | let mut shard = state.active.lock_shard_by_hash(key_hash); |
192 | | - match shard.find_entry(key_hash, equivalent_key(&self.key)) { |
| 191 | + match shard.find_entry(key_hash, equivalent_key(&key)) { |
193 | 192 | Err(_) => panic!(), |
194 | 193 | Ok(occupied) => { |
195 | 194 | let ((key, value), vacant) = occupied.remove(); |
@@ -347,7 +346,7 @@ fn execute_job<'tcx, C: QueryCache, const FLAGS: QueryFlags, const INCR: bool>( |
347 | 346 | ) -> (C::Value, Option<DepNodeIndex>) { |
348 | 347 | // Set up a guard object that will automatically poison the query if a |
349 | 348 | // panic occurs while executing the query (or any intermediate plumbing). |
350 | | - let job_guard = ActiveJobGuard { state, key }; |
| 349 | + let job_guard = ActiveJobGuard { state, key, key_hash }; |
351 | 350 |
|
352 | 351 | debug_assert_eq!(qcx.tcx.dep_graph.is_fully_enabled(), INCR); |
353 | 352 |
|
@@ -395,7 +394,7 @@ fn execute_job<'tcx, C: QueryCache, const FLAGS: QueryFlags, const INCR: bool>( |
395 | 394 | } |
396 | 395 |
|
397 | 396 | // Tell the guard to perform completion bookkeeping, and also to not poison the query. |
398 | | - job_guard.complete(cache, key_hash, result, dep_node_index); |
| 397 | + job_guard.complete(cache, result, dep_node_index); |
399 | 398 |
|
400 | 399 | (result, Some(dep_node_index)) |
401 | 400 | } |
|
0 commit comments