Skip to content

Commit d2dbd38

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 701b11a commit d2dbd38

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

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]
@@ -148,14 +149,13 @@ where
148149
{
149150
/// Completes the query by updating the query cache with the `result`,
150151
/// 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)
152153
where
153154
C: QueryCache<Key = K>,
154155
{
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;
159159
mem::forget(self);
160160

161161
// Mark as complete before we remove the job from the active state
@@ -187,11 +187,10 @@ where
187187
#[cold]
188188
fn drop(&mut self) {
189189
// Poison the query so jobs waiting on it panic.
190-
let state = self.state;
190+
let Self { state, key, key_hash } = *self;
191191
let job = {
192-
let key_hash = sharded::make_hash(&self.key);
193192
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)) {
195194
Err(_) => panic!(),
196195
Ok(occupied) => {
197196
let ((key, value), vacant) = occupied.remove();
@@ -361,7 +360,7 @@ where
361360
{
362361
// Set up a guard object that will automatically poison the query if a
363362
// 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 };
365364

366365
debug_assert_eq!(qcx.tcx.dep_graph.is_fully_enabled(), INCR);
367366

@@ -409,7 +408,7 @@ where
409408
}
410409

411410
// 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);
413412

414413
(result, Some(dep_node_index))
415414
}

0 commit comments

Comments
 (0)