2
2
//! generate the actual methods on tcx which find and execute the provider,
3
3
//! manage the caches, and so forth.
4
4
5
- use crate :: dep_graph:: { DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
5
+ use crate :: dep_graph:: { DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
6
6
use crate :: ty:: query:: caches:: QueryCache ;
7
7
use 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 } ;
9
9
use crate :: ty:: query:: Query ;
10
10
use crate :: ty:: tls;
11
11
use crate :: ty:: { self , TyCtxt } ;
@@ -20,6 +20,7 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
20
20
use rustc_span:: source_map:: DUMMY_SP ;
21
21
use rustc_span:: Span ;
22
22
use std:: collections:: hash_map:: Entry ;
23
+ use std:: convert:: TryFrom ;
23
24
use std:: fmt:: Debug ;
24
25
use std:: hash:: { Hash , Hasher } ;
25
26
use std:: mem;
@@ -110,6 +111,36 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
110
111
let shards = self . shards . lock_shards ( ) ;
111
112
shards. iter ( ) . all ( |shard| shard. active . is_empty ( ) )
112
113
}
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
+ }
113
144
}
114
145
115
146
impl < ' tcx , K , V , C : QueryCache < K , V > > Default for QueryStateImpl < ' tcx , K , V , C > {
@@ -1147,29 +1178,11 @@ macro_rules! define_queries_struct {
1147
1178
let mut jobs = FxHashMap :: default ( ) ;
1148
1179
1149
1180
$(
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
+ ) ?;
1173
1186
) *
1174
1187
1175
1188
Some ( jobs)
0 commit comments