|
94 | 94 | { |
95 | 95 | state: &'tcx QueryState<'tcx, K>, |
96 | 96 | key: K, |
| 97 | + key_hash: u64, |
97 | 98 | } |
98 | 99 |
|
99 | 100 | #[cold] |
@@ -148,14 +149,13 @@ where |
148 | 149 | { |
149 | 150 | /// Completes the query by updating the query cache with the `result`, |
150 | 151 | /// signals the waiter, and forgets the guard so it won't poison the query. |
151 | | - fn complete<C>(self, cache: &C, key_hash: u64, result: C::Value, dep_node_index: DepNodeIndex) |
| 152 | + fn complete<C>(self, cache: &C, result: C::Value, dep_node_index: DepNodeIndex) |
152 | 153 | where |
153 | 154 | C: QueryCache<Key = K>, |
154 | 155 | { |
155 | | - let key = self.key; |
156 | | - let state = self.state; |
157 | | - |
158 | | - // Forget ourself so our destructor won't poison the query |
| 156 | + // Forget ourself so our destructor won't poison the query. |
| 157 | + // (Extract fields by value first to make sure we don't leak anything.) |
| 158 | + let Self { state, key, key_hash }: Self = self; |
159 | 159 | mem::forget(self); |
160 | 160 |
|
161 | 161 | // Mark as complete before we remove the job from the active state |
@@ -187,11 +187,10 @@ where |
187 | 187 | #[cold] |
188 | 188 | fn drop(&mut self) { |
189 | 189 | // Poison the query so jobs waiting on it panic. |
190 | | - let state = self.state; |
| 190 | + let Self { state, key, key_hash } = *self; |
191 | 191 | let job = { |
192 | | - let key_hash = sharded::make_hash(&self.key); |
193 | 192 | let mut shard = state.active.lock_shard_by_hash(key_hash); |
194 | | - match shard.find_entry(key_hash, equivalent_key(&self.key)) { |
| 193 | + match shard.find_entry(key_hash, equivalent_key(&key)) { |
195 | 194 | Err(_) => panic!(), |
196 | 195 | Ok(occupied) => { |
197 | 196 | let ((key, value), vacant) = occupied.remove(); |
@@ -361,7 +360,7 @@ where |
361 | 360 | { |
362 | 361 | // Set up a guard object that will automatically poison the query if a |
363 | 362 | // panic occurs while executing the query (or any intermediate plumbing). |
364 | | - let job_guard = ActiveJobGuard { state, key }; |
| 363 | + let job_guard = ActiveJobGuard { state, key, key_hash }; |
365 | 364 |
|
366 | 365 | debug_assert_eq!(qcx.tcx.dep_graph.is_fully_enabled(), INCR); |
367 | 366 |
|
@@ -409,7 +408,7 @@ where |
409 | 408 | } |
410 | 409 |
|
411 | 410 | // 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); |
| 411 | + job_guard.complete(cache, result, dep_node_index); |
413 | 412 |
|
414 | 413 | (result, Some(dep_node_index)) |
415 | 414 | } |
|
0 commit comments