1
+ #![ allow( unused_parens) ]
2
+
1
3
use crate :: dep_graph;
2
4
use crate :: infer:: canonical:: { self , Canonical } ;
3
5
use crate :: lint:: LintExpectation ;
@@ -35,13 +37,15 @@ use crate::ty::subst::{GenericArg, SubstsRef};
35
37
use crate :: ty:: util:: AlwaysRequiresDrop ;
36
38
use crate :: ty:: GeneratorDiagnosticData ;
37
39
use crate :: ty:: { self , CrateInherentImpls , ParamEnvAnd , Ty , TyCtxt , UnusedGenericParams } ;
40
+ use rustc_arena:: TypedArena ;
38
41
use rustc_ast as ast;
39
42
use rustc_ast:: expand:: allocator:: AllocatorKind ;
40
43
use rustc_attr as attr;
41
44
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
42
45
use rustc_data_structures:: steal:: Steal ;
43
46
use rustc_data_structures:: svh:: Svh ;
44
47
use rustc_data_structures:: sync:: Lrc ;
48
+ use rustc_data_structures:: sync:: WorkerLocal ;
45
49
use rustc_data_structures:: unord:: UnordSet ;
46
50
use rustc_errors:: ErrorGuaranteed ;
47
51
use rustc_hir as hir;
@@ -67,6 +71,24 @@ use std::sync::Arc;
67
71
pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
68
72
use rustc_query_system:: query:: * ;
69
73
74
+ pub struct QuerySystem < ' tcx > {
75
+ pub local_providers : Box < Providers > ,
76
+ pub extern_providers : Box < ExternProviders > ,
77
+ pub arenas : QueryArenas < ' tcx > ,
78
+ pub caches : QueryCaches < ' tcx > ,
79
+ }
80
+
81
+ impl < ' tcx > QuerySystem < ' tcx > {
82
+ pub fn new ( local_providers : Providers , extern_providers : ExternProviders ) -> Self {
83
+ QuerySystem {
84
+ local_providers : Box :: new ( local_providers) ,
85
+ extern_providers : Box :: new ( extern_providers) ,
86
+ arenas : Default :: default ( ) ,
87
+ caches : Default :: default ( ) ,
88
+ }
89
+ }
90
+ }
91
+
70
92
#[ derive( Copy , Clone ) ]
71
93
pub struct TyCtxtAt < ' tcx > {
72
94
pub tcx : TyCtxt < ' tcx > ,
@@ -115,14 +137,14 @@ fn query_get_at<'tcx, Cache, K>(
115
137
Span ,
116
138
Cache :: Key ,
117
139
QueryMode ,
118
- ) -> Option < Cache :: Stored > ,
140
+ ) -> Option < Cache :: Value > ,
119
141
query_cache : & Cache ,
120
142
span : Span ,
121
143
key : K ,
122
- ) -> Cache :: Stored
144
+ ) -> Cache :: Value
123
145
where
124
146
K : IntoQueryParam < Cache :: Key > ,
125
- Cache :: Stored : Copy ,
147
+ Cache :: Value : Copy ,
126
148
Cache : QueryCache ,
127
149
{
128
150
let key = key. into_query_param ( ) ;
@@ -141,12 +163,12 @@ fn query_ensure<'tcx, Cache, K>(
141
163
Span ,
142
164
Cache :: Key ,
143
165
QueryMode ,
144
- ) -> Option < Cache :: Stored > ,
166
+ ) -> Option < Cache :: Value > ,
145
167
query_cache : & Cache ,
146
168
key : K ,
147
169
) where
148
170
K : IntoQueryParam < Cache :: Key > ,
149
- Cache :: Stored : Copy ,
171
+ Cache :: Value : Copy ,
150
172
Cache : QueryCache ,
151
173
{
152
174
let key = key. into_query_param ( ) ;
@@ -162,10 +184,10 @@ macro_rules! query_helper_param_ty {
162
184
}
163
185
164
186
macro_rules! query_if_arena {
165
- ( [ ] $arena: ty , $no_arena: ty ) => {
187
+ ( [ ] $arena: tt $no_arena: tt ) => {
166
188
$no_arena
167
189
} ;
168
- ( [ ( arena_cache) $( $rest: tt) * ] $arena: ty , $no_arena: ty ) => {
190
+ ( [ ( arena_cache) $( $rest: tt) * ] $arena: tt $no_arena: tt ) => {
169
191
$arena
170
192
} ;
171
193
( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
@@ -181,7 +203,7 @@ macro_rules! separate_provide_extern_decl {
181
203
for <' tcx> fn (
182
204
TyCtxt <' tcx>,
183
205
query_keys:: $name<' tcx>,
184
- ) -> query_values :: $name<' tcx>
206
+ ) -> query_provided :: $name<' tcx>
185
207
} ;
186
208
( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
187
209
separate_provide_extern_decl!( [ $( $modifiers) * ] [ $( $args) * ] )
@@ -233,30 +255,52 @@ macro_rules! define_callbacks {
233
255
234
256
$( pub type $name<' tcx> = $( $K) * ; ) *
235
257
}
236
- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
258
+ #[ allow( nonstandard_style, unused_lifetimes) ]
237
259
pub mod query_values {
238
260
use super :: * ;
239
261
240
- $( pub type $name<' tcx> = query_if_arena! ( [ $ ( $modifiers ) * ] <$V as Deref > :: Target , $V ) ; ) *
262
+ $( pub type $name<' tcx> = $V ; ) *
241
263
}
242
- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
243
- pub mod query_storage {
264
+ #[ allow( nonstandard_style, unused_lifetimes) ]
265
+ pub mod query_provided {
244
266
use super :: * ;
245
267
246
268
$(
247
- pub type $name<' tcx> = query_if_arena!( [ $( $modifiers) * ]
248
- <<$( $K) * as Key >:: CacheSelector
249
- as CacheSelector <' tcx, <$V as Deref >:: Target >>:: ArenaCache ,
250
- <<$( $K) * as Key >:: CacheSelector as CacheSelector <' tcx, $V>>:: Cache
251
- ) ;
269
+ pub type $name<' tcx> = query_if_arena!( [ $( $modifiers) * ] ( <$V as Deref >:: Target ) ( $V) ) ;
252
270
) *
253
271
}
272
+ #[ allow( nonstandard_style, unused_lifetimes) ]
273
+ pub mod query_provided_to_value {
274
+ use super :: * ;
254
275
276
+ $(
277
+ #[ inline]
278
+ pub fn $name<' tcx>(
279
+ _tcx: TyCtxt <' tcx>,
280
+ value: query_provided:: $name<' tcx>,
281
+ ) -> query_values:: $name<' tcx> {
282
+ query_if_arena!( [ $( $modifiers) * ]
283
+ ( & * _tcx. query_system. arenas. $name. alloc( value) )
284
+ ( value)
285
+ )
286
+ }
287
+ ) *
288
+ }
255
289
#[ allow( nonstandard_style, unused_lifetimes) ]
256
- pub mod query_stored {
290
+ pub mod query_storage {
257
291
use super :: * ;
258
292
259
- $( pub type $name<' tcx> = $V; ) *
293
+ $(
294
+ pub type $name<' tcx> = <<$( $K) * as Key >:: CacheSelector as CacheSelector <' tcx, $V>>:: Cache ;
295
+ ) *
296
+ }
297
+
298
+ #[ derive( Default ) ]
299
+ pub struct QueryArenas <' tcx> {
300
+ $( $( #[ $attr] ) * pub $name: query_if_arena!( [ $( $modifiers) * ]
301
+ ( WorkerLocal <TypedArena <<$V as Deref >:: Target >>)
302
+ ( )
303
+ ) , ) *
260
304
}
261
305
262
306
#[ derive( Default ) ]
@@ -271,7 +315,7 @@ macro_rules! define_callbacks {
271
315
query_ensure(
272
316
self . tcx,
273
317
QueryEngine :: $name,
274
- & self . tcx. query_caches . $name,
318
+ & self . tcx. query_system . caches . $name,
275
319
opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
276
320
) ;
277
321
} ) *
@@ -286,7 +330,7 @@ macro_rules! define_callbacks {
286
330
query_get_at(
287
331
self ,
288
332
QueryEngine :: $name,
289
- & self . query_caches . $name,
333
+ & self . query_system . caches . $name,
290
334
DUMMY_SP ,
291
335
opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
292
336
)
@@ -301,7 +345,7 @@ macro_rules! define_callbacks {
301
345
query_get_at(
302
346
self . tcx,
303
347
QueryEngine :: $name,
304
- & self . tcx. query_caches . $name,
348
+ & self . tcx. query_system . caches . $name,
305
349
self . span,
306
350
opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
307
351
)
@@ -312,7 +356,7 @@ macro_rules! define_callbacks {
312
356
$( pub $name: for <' tcx> fn (
313
357
TyCtxt <' tcx>,
314
358
query_keys:: $name<' tcx>,
315
- ) -> query_values :: $name<' tcx>, ) *
359
+ ) -> query_provided :: $name<' tcx>, ) *
316
360
}
317
361
318
362
pub struct ExternProviders {
@@ -389,12 +433,13 @@ macro_rules! define_feedable {
389
433
$( impl <' tcx, K : IntoQueryParam <$( $K) * > + Copy > TyCtxtFeed <' tcx, K > {
390
434
$( #[ $attr] ) *
391
435
#[ inline( always) ]
392
- pub fn $name( self , value: query_values :: $name<' tcx>) -> $V {
436
+ pub fn $name( self , value: query_provided :: $name<' tcx>) -> $V {
393
437
let key = self . key( ) . into_query_param( ) ;
394
438
let key = opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
395
439
396
440
let tcx = self . tcx;
397
- let cache = & tcx. query_caches. $name;
441
+ let value = query_provided_to_value:: $name( tcx, value) ;
442
+ let cache = & tcx. query_system. caches. $name;
398
443
399
444
match try_get_cached( tcx, cache, & key) {
400
445
Some ( old) => {
@@ -412,7 +457,8 @@ macro_rules! define_feedable {
412
457
& value,
413
458
hash_result!( [ $( $modifiers) * ] ) ,
414
459
) ;
415
- cache. complete( key, value, dep_node_index)
460
+ cache. complete( key, value, dep_node_index) ;
461
+ value
416
462
}
417
463
}
418
464
}
0 commit comments