Skip to content

Commit 936d8ad

Browse files
committed
Use find_or_find_insert_slot for query execution
1 parent cfbe4bf commit 936d8ad

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,38 @@ where
328328

329329
let current_job_id = qcx.current_query_job();
330330

331-
match state_lock.raw_entry_mut().from_key_hashed_nocheck(key_hash, &key) {
332-
RawEntryMut::Vacant(entry) => {
331+
match state_lock.raw_table_mut().find_or_find_insert_slot(
332+
key_hash,
333+
|(k, _)| *k == key,
334+
|(k, _)| sharded::make_hash(k),
335+
) {
336+
Err(free_slot) => {
333337
// Nothing has computed or is computing the query, so we start a new job and insert it in the
334338
// state map.
335339
let id = qcx.next_job_id();
336340
let job = QueryJob::new(id, span, current_job_id);
337-
entry.insert_hashed_nocheck(key_hash, key, QueryResult::Started(job));
341+
342+
// SAFETY: The slot is still valid as there's
343+
// been no mutation to the table since we hold the lock.
344+
unsafe {
345+
state_lock.raw_table_mut().insert_in_slot(
346+
key_hash,
347+
free_slot,
348+
(key, QueryResult::Started(job)),
349+
);
350+
}
338351

339352
// Drop the lock before we start executing the query
340353
drop(state_lock);
341354

342355
execute_job::<_, _, INCR>(query, qcx, state, key, key_hash, id, dep_node)
343356
}
344-
RawEntryMut::Occupied(mut entry) => {
345-
match entry.get_mut() {
357+
Ok(bucket) => {
358+
// SAFETY: We know this bucket is still valid
359+
// since we just got it from `find_or_find_insert_slot`.
360+
let entry = unsafe { &mut bucket.as_mut().1 };
361+
362+
match entry {
346363
QueryResult::Started(job) => {
347364
#[cfg(parallel_compiler)]
348365
if sync::is_dyn_thread_safe() {

0 commit comments

Comments
 (0)