Skip to content

Commit 7ebb4a6

Browse files
committed
Auto merge of #153747 - nnethercote:ActiveJobGuard-perf, r=<try>
Inline `ActiveGuardDrop::drop_and_maybe_poison`.
2 parents 4efe3dc + 01c8446 commit 7ebb4a6

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

compiler/rustc_query_impl/src/execution.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::hash::Hash;
2-
use std::mem::ManuallyDrop;
32

43
use rustc_data_structures::hash_table::{Entry, HashTable};
54
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -153,6 +152,7 @@ where
153152
state: &'tcx QueryState<'tcx, K>,
154153
key: K,
155154
key_hash: u64,
155+
poison_on_drop: bool,
156156
}
157157

158158
impl<'tcx, K> ActiveJobGuard<'tcx, K>
@@ -161,21 +161,27 @@ where
161161
{
162162
/// Completes the query by updating the query cache with the `result`,
163163
/// signals the waiter, and forgets the guard so it won't poison the query.
164-
fn complete<C>(self, cache: &C, value: C::Value, dep_node_index: DepNodeIndex)
164+
#[inline]
165+
fn complete<C>(mut self, cache: &C, value: C::Value, dep_node_index: DepNodeIndex)
165166
where
166167
C: QueryCache<Key = K>,
167168
{
168169
// Mark as complete before we remove the job from the active state
169170
// so no other thread can re-execute this query.
170171
cache.complete(self.key, value, dep_node_index);
171172

172-
let mut this = ManuallyDrop::new(self);
173-
174173
// Drop everything without poisoning the query.
175-
this.drop_and_maybe_poison(/* poison */ false);
174+
self.poison_on_drop = false;
175+
176+
// `drop` is now called because this method consumes `self`.
176177
}
178+
}
177179

178-
fn drop_and_maybe_poison(&mut self, poison: bool) {
180+
impl<'tcx, K> Drop for ActiveJobGuard<'tcx, K>
181+
where
182+
K: Eq + Hash + Copy,
183+
{
184+
fn drop(&mut self) {
179185
let status = {
180186
let mut shard = self.state.active.lock_shard_by_hash(self.key_hash);
181187
match shard.find_entry(self.key_hash, equivalent_key(self.key)) {
@@ -187,7 +193,7 @@ where
187193
}
188194
Ok(occupied) => {
189195
let ((key, status), vacant) = occupied.remove();
190-
if poison {
196+
if self.poison_on_drop {
191197
vacant.insert((key, ActiveKeyStatus::Poisoned));
192198
}
193199
status
@@ -203,18 +209,6 @@ where
203209
}
204210
}
205211

206-
impl<'tcx, K> Drop for ActiveJobGuard<'tcx, K>
207-
where
208-
K: Eq + Hash + Copy,
209-
{
210-
#[inline(never)]
211-
#[cold]
212-
fn drop(&mut self) {
213-
// Poison the query so jobs waiting on it panic.
214-
self.drop_and_maybe_poison(/* poison */ true);
215-
}
216-
}
217-
218212
#[cold]
219213
#[inline(never)]
220214
fn cycle_error<'tcx, C: QueryCache>(
@@ -359,7 +353,7 @@ fn execute_job<'tcx, C: QueryCache, const INCR: bool>(
359353
) -> (C::Value, Option<DepNodeIndex>) {
360354
// Set up a guard object that will automatically poison the query if a
361355
// panic occurs while executing the query (or any intermediate plumbing).
362-
let job_guard = ActiveJobGuard { state: &query.state, key, key_hash };
356+
let job_guard = ActiveJobGuard { state: &query.state, key, key_hash, poison_on_drop: true };
363357

364358
debug_assert_eq!(tcx.dep_graph.is_fully_enabled(), INCR);
365359

0 commit comments

Comments
 (0)