22//! generate the actual methods on tcx which find and execute the provider,
33//! manage the caches, and so forth.
44
5- use crate :: dep_graph:: { DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
5+ use crate :: dep_graph:: { DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
66use crate :: ty:: query:: caches:: QueryCache ;
77use crate :: ty:: query:: config:: { QueryAccessors , QueryConfig , QueryDescription } ;
8- use crate :: ty:: query:: job:: { QueryInfo , QueryJob , QueryJobId , QueryShardJobId } ;
8+ use crate :: ty:: query:: job:: { QueryInfo , QueryJob , QueryJobId , QueryJobInfo , QueryShardJobId } ;
99use crate :: ty:: query:: Query ;
1010use crate :: ty:: tls;
1111use crate :: ty:: { self , TyCtxt } ;
@@ -20,6 +20,7 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
2020use rustc_span:: source_map:: DUMMY_SP ;
2121use rustc_span:: Span ;
2222use std:: collections:: hash_map:: Entry ;
23+ use std:: convert:: TryFrom ;
2324use std:: fmt:: Debug ;
2425use std:: hash:: { Hash , Hasher } ;
2526use std:: mem;
@@ -110,6 +111,36 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
110111 let shards = self . shards . lock_shards ( ) ;
111112 shards. iter ( ) . all ( |shard| shard. active . is_empty ( ) )
112113 }
114+
115+ #[ inline]
116+ pub ( super ) fn try_collect_active_jobs (
117+ & self ,
118+ kind : DepKind ,
119+ make_query : impl Fn ( K ) -> Query < ' tcx > + Copy ,
120+ jobs : & mut FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ,
121+ ) -> Option < ( ) >
122+ where
123+ K : Clone ,
124+ {
125+ // We use try_lock_shards here since we are called from the
126+ // deadlock handler, and this shouldn't be locked.
127+ let shards = self . shards . try_lock_shards ( ) ?;
128+ let shards = shards. iter ( ) . enumerate ( ) ;
129+ jobs. extend ( shards. flat_map ( |( shard_id, shard) | {
130+ shard. active . iter ( ) . filter_map ( move |( k, v) | {
131+ if let QueryResult :: Started ( ref job) = * v {
132+ let id =
133+ QueryJobId { job : job. id , shard : u16:: try_from ( shard_id) . unwrap ( ) , kind } ;
134+ let info = QueryInfo { span : job. span , query : make_query ( k. clone ( ) ) } ;
135+ Some ( ( id, QueryJobInfo { info, job : job. clone ( ) } ) )
136+ } else {
137+ None
138+ }
139+ } )
140+ } ) ) ;
141+
142+ Some ( ( ) )
143+ }
113144}
114145
115146impl < ' tcx , K , V , C : QueryCache < K , V > > Default for QueryStateImpl < ' tcx , K , V , C > {
@@ -1147,29 +1178,11 @@ macro_rules! define_queries_struct {
11471178 let mut jobs = FxHashMap :: default ( ) ;
11481179
11491180 $(
1150- // We use try_lock_shards here since we are called from the
1151- // deadlock handler, and this shouldn't be locked.
1152- let shards = self . $name. shards. try_lock_shards( ) ?;
1153- let shards = shards. iter( ) . enumerate( ) ;
1154- jobs. extend( shards. flat_map( |( shard_id, shard) | {
1155- shard. active. iter( ) . filter_map( move |( k, v) | {
1156- if let QueryResult :: Started ( ref job) = * v {
1157- let id = QueryJobId {
1158- job: job. id,
1159- shard: u16 :: try_from( shard_id) . unwrap( ) ,
1160- kind:
1161- <queries:: $name<' tcx> as QueryAccessors <' tcx>>:: DEP_KIND ,
1162- } ;
1163- let info = QueryInfo {
1164- span: job. span,
1165- query: Query :: $name( k. clone( ) )
1166- } ;
1167- Some ( ( id, QueryJobInfo { info, job: job. clone( ) } ) )
1168- } else {
1169- None
1170- }
1171- } )
1172- } ) ) ;
1181+ self . $name. try_collect_active_jobs(
1182+ <queries:: $name<' tcx> as QueryAccessors <' tcx>>:: DEP_KIND ,
1183+ Query :: $name,
1184+ & mut jobs,
1185+ ) ?;
11731186 ) *
11741187
11751188 Some ( jobs)
0 commit comments