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,35 @@ 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
+ pub ( super ) fn try_collect_active_jobs (
116
+ & self ,
117
+ kind : DepKind ,
118
+ make_query : fn ( K ) -> Query < ' tcx > ,
119
+ jobs : & mut FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ,
120
+ ) -> Option < ( ) >
121
+ where
122
+ K : Clone ,
123
+ {
124
+ // We use try_lock_shards here since we are called from the
125
+ // deadlock handler, and this shouldn't be locked.
126
+ let shards = self . shards . try_lock_shards ( ) ?;
127
+ let shards = shards. iter ( ) . enumerate ( ) ;
128
+ jobs. extend ( shards. flat_map ( |( shard_id, shard) | {
129
+ shard. active . iter ( ) . filter_map ( move |( k, v) | {
130
+ if let QueryResult :: Started ( ref job) = * v {
131
+ let id =
132
+ QueryJobId { job : job. id , shard : u16:: try_from ( shard_id) . unwrap ( ) , kind } ;
133
+ let info = QueryInfo { span : job. span , query : make_query ( k. clone ( ) ) } ;
134
+ Some ( ( id, QueryJobInfo { info, job : job. clone ( ) } ) )
135
+ } else {
136
+ None
137
+ }
138
+ } )
139
+ } ) ) ;
140
+
141
+ Some ( ( ) )
142
+ }
113
143
}
114
144
115
145
impl < ' tcx , K , V , C : QueryCache < K , V > > Default for QueryStateImpl < ' tcx , K , V , C > {
@@ -1135,29 +1165,11 @@ macro_rules! define_queries_struct {
1135
1165
let mut jobs = FxHashMap :: default ( ) ;
1136
1166
1137
1167
$(
1138
- // We use try_lock_shards here since we are called from the
1139
- // deadlock handler, and this shouldn't be locked.
1140
- let shards = self . $name. shards. try_lock_shards( ) ?;
1141
- let shards = shards. iter( ) . enumerate( ) ;
1142
- jobs. extend( shards. flat_map( |( shard_id, shard) | {
1143
- shard. active. iter( ) . filter_map( move |( k, v) | {
1144
- if let QueryResult :: Started ( ref job) = * v {
1145
- let id = QueryJobId {
1146
- job: job. id,
1147
- shard: u16 :: try_from( shard_id) . unwrap( ) ,
1148
- kind:
1149
- <queries:: $name<' tcx> as QueryAccessors <' tcx>>:: DEP_KIND ,
1150
- } ;
1151
- let info = QueryInfo {
1152
- span: job. span,
1153
- query: Query :: $name( k. clone( ) )
1154
- } ;
1155
- Some ( ( id, QueryJobInfo { info, job: job. clone( ) } ) )
1156
- } else {
1157
- None
1158
- }
1159
- } )
1160
- } ) ) ;
1168
+ self . $name. try_collect_active_jobs(
1169
+ <queries:: $name<' tcx> as QueryAccessors <' tcx>>:: DEP_KIND ,
1170
+ Query :: $name,
1171
+ & mut jobs,
1172
+ ) ?;
1161
1173
) *
1162
1174
1163
1175
Some ( jobs)
0 commit comments