Skip to content

Commit a5c8caa

Browse files
committed
Use find_or_find_insert_slot for query execution
1 parent bde1066 commit a5c8caa

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
@@ -326,21 +326,38 @@ where
326326

327327
let current_job_id = qcx.current_query_job();
328328

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

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

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

0 commit comments

Comments
 (0)