@@ -6,10 +6,9 @@ use std::cell::Cell;
66use std:: fmt:: Debug ;
77use std:: hash:: Hash ;
88use std:: mem;
9+ use std:: sync:: Mutex ;
910
10- use hashbrown:: hash_table:: Entry ;
1111use rustc_data_structures:: fingerprint:: Fingerprint ;
12- use rustc_data_structures:: sharded:: { self , ShardedHashMap , make_hash} ;
1312use rustc_data_structures:: stack:: ensure_sufficient_stack;
1413use rustc_data_structures:: { outline, sync} ;
1514use rustc_errors:: { Diag , FatalError , StashKey } ;
@@ -24,13 +23,8 @@ use crate::query::caches::QueryCache;
2423use crate :: query:: job:: { QueryInfo , QueryJob , QueryJobId , QueryJobInfo , QueryLatch , report_cycle} ;
2524use crate :: query:: { QueryContext , QueryMap , QueryStackFrame , SerializedDepNodeIndex } ;
2625
27- #[ inline]
28- fn equivalent_key < K : Eq , V > ( k : & K ) -> impl Fn ( & ( K , V ) ) -> bool + ' _ {
29- move |x| x. 0 == * k
30- }
31-
3226pub struct QueryState < I > {
33- active : ShardedHashMap < usize , QueryResult < I > > ,
27+ active : Mutex < Vec < ( usize , QueryResult < I > ) > > ,
3428}
3529
3630/// Indicates the state of a query for a given key in a query map.
@@ -57,7 +51,7 @@ impl<I> QueryResult<I> {
5751
5852impl < I > QueryState < I > {
5953 pub fn all_inactive ( & self ) -> bool {
60- self . active . lock_shards ( ) . all ( |shard| shard . is_empty ( ) )
54+ self . active . lock ( ) . unwrap ( ) . is_empty ( )
6155 }
6256
6357 pub fn try_collect_active_jobs < Qcx : Copy > (
@@ -70,11 +64,9 @@ impl<I> QueryState<I> {
7064
7165 // We use try_lock_shards here since we are called from the
7266 // deadlock handler, and this shouldn't be locked.
73- for shard in self . active . try_lock_shards ( ) {
74- for ( k, v) in shard?. iter ( ) {
75- if let QueryResult :: Started ( ref job) = * v {
76- active. push ( ( * k, ( * job) . clone ( ) ) ) ;
77- }
67+ for ( k, v) in self . active . try_lock ( ) . ok ( ) ?. iter ( ) {
68+ if let QueryResult :: Started ( ref job) = * v {
69+ active. push ( ( * k, ( * job) . clone ( ) ) ) ;
7870 }
7971 }
8072
@@ -172,19 +164,17 @@ where
172164 // Forget ourself so our destructor won't poison the query
173165 mem:: forget ( self ) ;
174166
175- let idx_hash = sharded:: make_hash ( & unique_idx) ;
176-
177167 // Lock shard before cache.complete as otherwise a distinct index might be assigned to a
178168 // concurrently starting query.
179- let mut shard = state. active . lock_shard_by_hash ( idx_hash ) ;
169+ let mut shard = state. active . lock ( ) . unwrap ( ) ;
180170
181171 // Mark as complete before we remove the job from the active state
182172 // so no other thread can re-execute this query.
183173 cache. complete ( key, result, dep_node_index) ;
184174
185- let job = match shard. entry ( idx_hash , equivalent_key ( & unique_idx ) , | ( k , _ ) | make_hash ( k ) ) {
186- Entry :: Occupied ( e ) => Some ( e . remove ( ) . 0 . 1 ) ,
187- Entry :: Vacant ( _ ) => None ,
175+ let job = match shard. iter ( ) . position ( |x| x . 0 == unique_idx ) {
176+ Some ( idx ) => Some ( shard . swap_remove ( idx ) . 1 ) ,
177+ None => None ,
188178 } ;
189179 let job = job. expect ( "active query job entry" ) . expect_job ( ) ;
190180
@@ -202,15 +192,10 @@ where
202192 // Poison the query so jobs waiting on it panic.
203193 let state = self . state ;
204194 let job = {
205- let idx_hash = sharded:: make_hash ( & self . unique_idx ) ;
206- let mut shard = state. active . lock_shard_by_hash ( idx_hash) ;
207- match shard. find_entry ( idx_hash, equivalent_key ( & self . unique_idx ) ) {
208- Err ( _) => panic ! ( ) ,
209- Ok ( occupied) => {
210- let ( ( key, value) , vacant) = occupied. remove ( ) ;
211- vacant. insert ( ( key, QueryResult :: Poisoned ) ) ;
212- value. expect_job ( )
213- }
195+ let mut shard = state. active . lock ( ) . unwrap ( ) ;
196+ match shard. iter_mut ( ) . find ( |x| x. 0 == self . unique_idx ) {
197+ None => panic ! ( ) ,
198+ Some ( occupied) => mem:: replace ( & mut occupied. 1 , QueryResult :: Poisoned ) . expect_job ( ) ,
214199 }
215200 } ;
216201 // Also signal the completion of the job, so waiters
@@ -304,9 +289,8 @@ where
304289 // We didn't find the query result in the query cache. Check if it was
305290 // poisoned due to a panic instead.
306291 let unique_idx = query. query_cache ( qcx) . to_unique_index ( & key) ;
307- let idx_hash = sharded:: make_hash ( & unique_idx) ;
308- let shard = query. query_state ( qcx) . active . lock_shard_by_hash ( idx_hash) ;
309- match shard. find ( idx_hash, equivalent_key ( & unique_idx) ) {
292+ let shard = query. query_state ( qcx) . active . lock ( ) . unwrap ( ) ;
293+ match shard. iter ( ) . find ( |x| x. 0 == unique_idx) {
310294 // The query we waited on panicked. Continue unwinding here.
311295 Some ( ( _, QueryResult :: Poisoned ) ) => FatalError . raise ( ) ,
312296 _ => panic ! (
@@ -340,8 +324,7 @@ where
340324{
341325 let state = query. query_state ( qcx) ;
342326 let unique_idx = query. query_cache ( qcx) . to_unique_index ( & key) ;
343- let idx_hash = sharded:: make_hash ( & unique_idx) ;
344- let mut state_lock = state. active . lock_shard_by_hash ( idx_hash) ;
327+ let mut state_lock = state. active . lock ( ) . unwrap ( ) ;
345328
346329 // For the parallel compiler we need to check both the query cache and query state structures
347330 // while holding the state lock to ensure that 1) the query has not yet completed and 2) the
@@ -357,21 +340,21 @@ where
357340 }
358341
359342 let current_job_id = qcx. current_query_job ( ) ;
360- match state_lock. entry ( idx_hash , equivalent_key ( & unique_idx ) , | ( k , _ ) | sharded :: make_hash ( k ) ) {
361- Entry :: Vacant ( entry ) => {
343+ match state_lock. iter_mut ( ) . find ( |x| x . 0 == unique_idx ) {
344+ None => {
362345 // Nothing has computed or is computing the query, so we start a new job and insert it in the
363346 // state map.
364347 let id = qcx. next_job_id ( ) ;
365348 let job = QueryJob :: new ( id, span, current_job_id) ;
366- entry . insert ( ( unique_idx, QueryResult :: Started ( job) ) ) ;
349+ state_lock . push ( ( unique_idx, QueryResult :: Started ( job) ) ) ;
367350
368351 // Drop the lock before we start executing the query
369352 drop ( state_lock) ;
370353
371354 execute_job :: < _ , _ , INCR > ( query, qcx, state, key, id, dep_node)
372355 }
373- Entry :: Occupied ( mut entry ) => {
374- match & mut entry . get_mut ( ) . 1 {
356+ Some ( ( _ , occupied ) ) => {
357+ match occupied {
375358 QueryResult :: Started ( job) => {
376359 if sync:: is_dyn_thread_safe ( ) {
377360 // Get the latch out
0 commit comments