Skip to content

Commit c475bda

Browse files
committed
Include key_hash in ActiveJobGuard
This value is a previously-computed hash of the key, so it makes sense to bundle it with the key inside the guard, since the guard will need it on completion anyway.
1 parent e04ae80 commit c475bda

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

compiler/rustc_query_impl/src/execution.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ where
9494
{
9595
state: &'tcx QueryState<'tcx, K>,
9696
key: K,
97+
key_hash: u64,
9798
}
9899

99100
#[cold]
@@ -146,14 +147,13 @@ where
146147
{
147148
/// Completes the query by updating the query cache with the `result`,
148149
/// 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)
150151
where
151152
C: QueryCache<Key = K>,
152153
{
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;
157157
mem::forget(self);
158158

159159
// Mark as complete before we remove the job from the active state
@@ -185,11 +185,10 @@ where
185185
#[cold]
186186
fn drop(&mut self) {
187187
// Poison the query so jobs waiting on it panic.
188-
let state = self.state;
188+
let Self { state, key, key_hash } = *self;
189189
let job = {
190-
let key_hash = sharded::make_hash(&self.key);
191190
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)) {
193192
Err(_) => panic!(),
194193
Ok(occupied) => {
195194
let ((key, value), vacant) = occupied.remove();
@@ -347,7 +346,7 @@ fn execute_job<'tcx, C: QueryCache, const FLAGS: QueryFlags, const INCR: bool>(
347346
) -> (C::Value, Option<DepNodeIndex>) {
348347
// Set up a guard object that will automatically poison the query if a
349348
// 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 };
351350

352351
debug_assert_eq!(qcx.tcx.dep_graph.is_fully_enabled(), INCR);
353352

@@ -395,7 +394,7 @@ fn execute_job<'tcx, C: QueryCache, const FLAGS: QueryFlags, const INCR: bool>(
395394
}
396395

397396
// 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);
399398

400399
(result, Some(dep_node_index))
401400
}

0 commit comments

Comments
 (0)