1+ #![ allow( unused_parens) ]
2+
13use crate :: dep_graph;
24use crate :: infer:: canonical:: { self , Canonical } ;
35use crate :: lint:: LintExpectation ;
@@ -35,13 +37,15 @@ use crate::ty::subst::{GenericArg, SubstsRef};
3537use crate :: ty:: util:: AlwaysRequiresDrop ;
3638use crate :: ty:: GeneratorDiagnosticData ;
3739use crate :: ty:: { self , CrateInherentImpls , ParamEnvAnd , Ty , TyCtxt , UnusedGenericParams } ;
40+ use rustc_arena:: TypedArena ;
3841use rustc_ast as ast;
3942use rustc_ast:: expand:: allocator:: AllocatorKind ;
4043use rustc_attr as attr;
4144use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
4245use rustc_data_structures:: steal:: Steal ;
4346use rustc_data_structures:: svh:: Svh ;
4447use rustc_data_structures:: sync:: Lrc ;
48+ use rustc_data_structures:: sync:: WorkerLocal ;
4549use rustc_data_structures:: unord:: UnordSet ;
4650use rustc_errors:: ErrorGuaranteed ;
4751use rustc_hir as hir;
@@ -67,6 +71,24 @@ use std::sync::Arc;
6771pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
6872use rustc_query_system:: query:: * ;
6973
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+
7092#[ derive( Copy , Clone ) ]
7193pub struct TyCtxtAt < ' tcx > {
7294 pub tcx : TyCtxt < ' tcx > ,
@@ -115,14 +137,14 @@ fn query_get_at<'tcx, Cache, K>(
115137 Span ,
116138 Cache :: Key ,
117139 QueryMode ,
118- ) -> Option < Cache :: Stored > ,
140+ ) -> Option < Cache :: Value > ,
119141 query_cache : & Cache ,
120142 span : Span ,
121143 key : K ,
122- ) -> Cache :: Stored
144+ ) -> Cache :: Value
123145where
124146 K : IntoQueryParam < Cache :: Key > ,
125- Cache :: Stored : Copy ,
147+ Cache :: Value : Copy ,
126148 Cache : QueryCache ,
127149{
128150 let key = key. into_query_param ( ) ;
@@ -141,12 +163,12 @@ fn query_ensure<'tcx, Cache, K>(
141163 Span ,
142164 Cache :: Key ,
143165 QueryMode ,
144- ) -> Option < Cache :: Stored > ,
166+ ) -> Option < Cache :: Value > ,
145167 query_cache : & Cache ,
146168 key : K ,
147169) where
148170 K : IntoQueryParam < Cache :: Key > ,
149- Cache :: Stored : Copy ,
171+ Cache :: Value : Copy ,
150172 Cache : QueryCache ,
151173{
152174 let key = key. into_query_param ( ) ;
@@ -162,10 +184,10 @@ macro_rules! query_helper_param_ty {
162184}
163185
164186macro_rules! query_if_arena {
165- ( [ ] $arena: ty , $no_arena: ty ) => {
187+ ( [ ] $arena: tt $no_arena: tt ) => {
166188 $no_arena
167189 } ;
168- ( [ ( arena_cache) $( $rest: tt) * ] $arena: ty , $no_arena: ty ) => {
190+ ( [ ( arena_cache) $( $rest: tt) * ] $arena: tt $no_arena: tt ) => {
169191 $arena
170192 } ;
171193 ( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
@@ -181,7 +203,7 @@ macro_rules! separate_provide_extern_decl {
181203 for <' tcx> fn (
182204 TyCtxt <' tcx>,
183205 query_keys:: $name<' tcx>,
184- ) -> query_values :: $name<' tcx>
206+ ) -> query_provided :: $name<' tcx>
185207 } ;
186208 ( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
187209 separate_provide_extern_decl!( [ $( $modifiers) * ] [ $( $args) * ] )
@@ -233,30 +255,52 @@ macro_rules! define_callbacks {
233255
234256 $( pub type $name<' tcx> = $( $K) * ; ) *
235257 }
236- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
258+ #[ allow( nonstandard_style, unused_lifetimes) ]
237259 pub mod query_values {
238260 use super :: * ;
239261
240- $( pub type $name<' tcx> = query_if_arena! ( [ $ ( $modifiers ) * ] <$V as Deref > :: Target , $V ) ; ) *
262+ $( pub type $name<' tcx> = $V ; ) *
241263 }
242- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
243- pub mod query_storage {
264+ #[ allow( nonstandard_style, unused_lifetimes) ]
265+ pub mod query_provided {
244266 use super :: * ;
245267
246268 $(
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) ) ;
252270 ) *
253271 }
272+ #[ allow( nonstandard_style, unused_lifetimes) ]
273+ pub mod query_provided_to_value {
274+ use super :: * ;
254275
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+ }
255289 #[ allow( nonstandard_style, unused_lifetimes) ]
256- pub mod query_stored {
290+ pub mod query_storage {
257291 use super :: * ;
258292
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+ ) , ) *
260304 }
261305
262306 #[ derive( Default ) ]
@@ -271,7 +315,7 @@ macro_rules! define_callbacks {
271315 query_ensure(
272316 self . tcx,
273317 QueryEngine :: $name,
274- & self . tcx. query_caches . $name,
318+ & self . tcx. query_system . caches . $name,
275319 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
276320 ) ;
277321 } ) *
@@ -286,7 +330,7 @@ macro_rules! define_callbacks {
286330 query_get_at(
287331 self ,
288332 QueryEngine :: $name,
289- & self . query_caches . $name,
333+ & self . query_system . caches . $name,
290334 DUMMY_SP ,
291335 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
292336 )
@@ -301,7 +345,7 @@ macro_rules! define_callbacks {
301345 query_get_at(
302346 self . tcx,
303347 QueryEngine :: $name,
304- & self . tcx. query_caches . $name,
348+ & self . tcx. query_system . caches . $name,
305349 self . span,
306350 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
307351 )
@@ -312,7 +356,7 @@ macro_rules! define_callbacks {
312356 $( pub $name: for <' tcx> fn (
313357 TyCtxt <' tcx>,
314358 query_keys:: $name<' tcx>,
315- ) -> query_values :: $name<' tcx>, ) *
359+ ) -> query_provided :: $name<' tcx>, ) *
316360 }
317361
318362 pub struct ExternProviders {
@@ -389,12 +433,13 @@ macro_rules! define_feedable {
389433 $( impl <' tcx, K : IntoQueryParam <$( $K) * > + Copy > TyCtxtFeed <' tcx, K > {
390434 $( #[ $attr] ) *
391435 #[ inline( always) ]
392- pub fn $name( self , value: query_values :: $name<' tcx>) -> $V {
436+ pub fn $name( self , value: query_provided :: $name<' tcx>) -> $V {
393437 let key = self . key( ) . into_query_param( ) ;
394438 let key = opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
395439
396440 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;
398443
399444 match try_get_cached( tcx, cache, & key) {
400445 Some ( old) => {
@@ -412,7 +457,8 @@ macro_rules! define_feedable {
412457 & value,
413458 hash_result!( [ $( $modifiers) * ] ) ,
414459 ) ;
415- cache. complete( key, value, dep_node_index)
460+ cache. complete( key, value, dep_node_index) ;
461+ value
416462 }
417463 }
418464 }
0 commit comments