Skip to content

Commit b74cb78

Browse files
committed
Remove conditional use of Sharded from query state
1 parent b60e31b commit b74cb78

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobI
1212
use crate::query::SerializedDepNodeIndex;
1313
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
1414
use crate::HandleCycleError;
15+
#[cfg(parallel_compiler)]
16+
use rustc_data_structures::cold_path;
1517
use rustc_data_structures::fingerprint::Fingerprint;
1618
use rustc_data_structures::fx::FxHashMap;
19+
use rustc_data_structures::sharded::Sharded;
1720
use rustc_data_structures::stack::ensure_sufficient_stack;
1821
use rustc_data_structures::sync::Lock;
19-
#[cfg(parallel_compiler)]
20-
use rustc_data_structures::{cold_path, sharded::Sharded};
2122
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError};
2223
use rustc_span::{Span, DUMMY_SP};
2324
use std::cell::Cell;
@@ -30,10 +31,7 @@ use thin_vec::ThinVec;
3031
use super::QueryConfig;
3132

3233
pub struct QueryState<K, D: DepKind> {
33-
#[cfg(parallel_compiler)]
3434
active: Sharded<FxHashMap<K, QueryResult<D>>>,
35-
#[cfg(not(parallel_compiler))]
36-
active: Lock<FxHashMap<K, QueryResult<D>>>,
3735
}
3836

3937
/// Indicates the state of a query for a given key in a query map.
@@ -52,15 +50,8 @@ where
5250
D: DepKind,
5351
{
5452
pub fn all_inactive(&self) -> bool {
55-
#[cfg(parallel_compiler)]
56-
{
57-
let shards = self.active.lock_shards();
58-
shards.iter().all(|shard| shard.is_empty())
59-
}
60-
#[cfg(not(parallel_compiler))]
61-
{
62-
self.active.lock().is_empty()
63-
}
53+
let shards = self.active.lock_shards();
54+
shards.iter().all(|shard| shard.is_empty())
6455
}
6556

6657
pub fn try_collect_active_jobs<Qcx: Copy>(
@@ -71,26 +62,11 @@ where
7162
) -> Option<()> {
7263
let mut active = Vec::new();
7364

74-
#[cfg(parallel_compiler)]
75-
{
76-
// We use try_lock_shards here since we are called from the
77-
// deadlock handler, and this shouldn't be locked.
78-
let shards = self.active.try_lock_shards()?;
79-
for shard in shards.iter() {
80-
for (k, v) in shard.iter() {
81-
if let QueryResult::Started(ref job) = *v {
82-
active.push((*k, job.clone()));
83-
}
84-
}
85-
}
86-
}
87-
#[cfg(not(parallel_compiler))]
88-
{
89-
// We use try_lock here since we are called from the
90-
// deadlock handler, and this shouldn't be locked.
91-
// (FIXME: Is this relevant for non-parallel compilers? It doesn't
92-
// really hurt much.)
93-
for (k, v) in self.active.try_lock()?.iter() {
65+
// We use try_lock_shards here since we are called from the
66+
// deadlock handler, and this shouldn't be locked.
67+
let shards = self.active.try_lock_shards()?;
68+
for shard in shards.iter() {
69+
for (k, v) in shard.iter() {
9470
if let QueryResult::Started(ref job) = *v {
9571
active.push((*k, job.clone()));
9672
}
@@ -184,10 +160,7 @@ where
184160
cache.complete(key, result, dep_node_index);
185161

186162
let job = {
187-
#[cfg(parallel_compiler)]
188163
let mut lock = state.active.get_shard_by_value(&key).lock();
189-
#[cfg(not(parallel_compiler))]
190-
let mut lock = state.active.lock();
191164
match lock.remove(&key).unwrap() {
192165
QueryResult::Started(job) => job,
193166
QueryResult::Poisoned => panic!(),
@@ -209,10 +182,7 @@ where
209182
// Poison the query so jobs waiting on it panic.
210183
let state = self.state;
211184
let job = {
212-
#[cfg(parallel_compiler)]
213185
let mut shard = state.active.get_shard_by_value(&self.key).lock();
214-
#[cfg(not(parallel_compiler))]
215-
let mut shard = state.active.lock();
216186
let job = match shard.remove(&self.key).unwrap() {
217187
QueryResult::Started(job) => job,
218188
QueryResult::Poisoned => panic!(),
@@ -325,10 +295,7 @@ where
325295
Qcx: QueryContext,
326296
{
327297
let state = query.query_state(qcx);
328-
#[cfg(parallel_compiler)]
329298
let mut state_lock = state.active.get_shard_by_value(&key).lock();
330-
#[cfg(not(parallel_compiler))]
331-
let mut state_lock = state.active.lock();
332299

333300
// For the parallel compiler we need to check both the query cache and query state structures
334301
// while holding the state lock to ensure that 1) the query has not yet completed and 2) the

0 commit comments

Comments
 (0)