Skip to content

Commit 8443816

Browse files
Inline QueryStateShard into QueryState
1 parent 75ef068 commit 8443816

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,8 @@ fn hash_for_shard<K: Hash>(key: &K) -> u64 {
3333
hasher.finish()
3434
}
3535

36-
struct QueryStateShard<K> {
37-
active: FxHashMap<K, QueryResult>,
38-
}
39-
40-
impl<K> Default for QueryStateShard<K> {
41-
fn default() -> QueryStateShard<K> {
42-
QueryStateShard { active: Default::default() }
43-
}
44-
}
45-
4636
pub struct QueryState<K> {
47-
shards: Sharded<QueryStateShard<K>>,
37+
shards: Sharded<FxHashMap<K, QueryResult>>,
4838
}
4939

5040
/// Indicates the state of a query for a given key in a query map.
@@ -63,7 +53,7 @@ where
6353
{
6454
pub fn all_inactive(&self) -> bool {
6555
let shards = self.shards.lock_shards();
66-
shards.iter().all(|shard| shard.active.is_empty())
56+
shards.iter().all(|shard| shard.is_empty())
6757
}
6858

6959
pub fn try_collect_active_jobs<CTX: Copy>(
@@ -76,7 +66,7 @@ where
7666
// deadlock handler, and this shouldn't be locked.
7767
let shards = self.shards.try_lock_shards()?;
7868
for shard in shards.iter() {
79-
for (k, v) in shard.active.iter() {
69+
for (k, v) in shard.iter() {
8070
if let QueryResult::Started(ref job) = *v {
8171
let query = make_query(tcx, k.clone());
8272
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
@@ -148,7 +138,7 @@ where
148138
let mut state_lock = state.shards.get_shard_by_value(&key).lock();
149139
let lock = &mut *state_lock;
150140

151-
match lock.active.entry(key) {
141+
match lock.entry(key) {
152142
Entry::Vacant(entry) => {
153143
let id = tcx.next_job_id();
154144
let job = tcx.current_query_job();
@@ -220,7 +210,7 @@ where
220210
let shard = get_shard_index_by_hash(key_hash);
221211
let job = {
222212
let mut lock = state.shards.get_shard_by_index(shard).lock();
223-
match lock.active.remove(&key).unwrap() {
213+
match lock.remove(&key).unwrap() {
224214
QueryResult::Started(job) => job,
225215
QueryResult::Poisoned => panic!(),
226216
}
@@ -246,11 +236,11 @@ where
246236
let shard = state.shards.get_shard_by_value(&self.key);
247237
let job = {
248238
let mut shard = shard.lock();
249-
let job = match shard.active.remove(&self.key).unwrap() {
239+
let job = match shard.remove(&self.key).unwrap() {
250240
QueryResult::Started(job) => job,
251241
QueryResult::Poisoned => panic!(),
252242
};
253-
shard.active.insert(self.key.clone(), QueryResult::Poisoned);
243+
shard.insert(self.key.clone(), QueryResult::Poisoned);
254244
job
255245
};
256246
// Also signal the completion of the job, so waiters

0 commit comments

Comments
 (0)