Skip to content

Commit

Permalink
Use find_or_find_insert_slot for query execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Sep 11, 2023
1 parent cfbe4bf commit 936d8ad
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,38 @@ where

let current_job_id = qcx.current_query_job();

match state_lock.raw_entry_mut().from_key_hashed_nocheck(key_hash, &key) {
RawEntryMut::Vacant(entry) => {
match state_lock.raw_table_mut().find_or_find_insert_slot(
key_hash,
|(k, _)| *k == key,
|(k, _)| sharded::make_hash(k),
) {
Err(free_slot) => {
// Nothing has computed or is computing the query, so we start a new job and insert it in the
// state map.
let id = qcx.next_job_id();
let job = QueryJob::new(id, span, current_job_id);
entry.insert_hashed_nocheck(key_hash, key, QueryResult::Started(job));

// SAFETY: The slot is still valid as there's
// been no mutation to the table since we hold the lock.
unsafe {
state_lock.raw_table_mut().insert_in_slot(
key_hash,
free_slot,
(key, QueryResult::Started(job)),
);
}

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

execute_job::<_, _, INCR>(query, qcx, state, key, key_hash, id, dep_node)
}
RawEntryMut::Occupied(mut entry) => {
match entry.get_mut() {
Ok(bucket) => {
// SAFETY: We know this bucket is still valid
// since we just got it from `find_or_find_insert_slot`.
let entry = unsafe { &mut bucket.as_mut().1 };

match entry {
QueryResult::Started(job) => {
#[cfg(parallel_compiler)]
if sync::is_dyn_thread_safe() {
Expand Down

0 comments on commit 936d8ad

Please sign in to comment.