1+ #![ allow( unused_parens) ]
2+
13use crate :: dep_graph;
24use crate :: infer:: canonical:: { self , Canonical } ;
35use crate :: lint:: LintExpectation ;
@@ -34,13 +36,15 @@ use crate::ty::subst::{GenericArg, SubstsRef};
3436use crate :: ty:: util:: AlwaysRequiresDrop ;
3537use crate :: ty:: GeneratorDiagnosticData ;
3638use crate :: ty:: { self , CrateInherentImpls , ParamEnvAnd , Ty , TyCtxt , UnusedGenericParams } ;
39+ use rustc_arena:: TypedArena ;
3740use rustc_ast as ast;
3841use rustc_ast:: expand:: allocator:: AllocatorKind ;
3942use rustc_attr as attr;
4043use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
4144use rustc_data_structures:: steal:: Steal ;
4245use rustc_data_structures:: svh:: Svh ;
4346use rustc_data_structures:: sync:: Lrc ;
47+ use rustc_data_structures:: sync:: WorkerLocal ;
4448use rustc_data_structures:: unord:: UnordSet ;
4549use rustc_errors:: ErrorGuaranteed ;
4650use rustc_hir as hir;
@@ -66,6 +70,24 @@ use std::sync::Arc;
6670pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
6771use rustc_query_system:: query:: * ;
6872
73+ pub struct QuerySystem < ' tcx > {
74+ pub local_providers : Box < Providers > ,
75+ pub extern_providers : Box < ExternProviders > ,
76+ pub arenas : QueryArenas < ' tcx > ,
77+ pub caches : QueryCaches < ' tcx > ,
78+ }
79+
80+ impl < ' tcx > QuerySystem < ' tcx > {
81+ pub fn new ( local_providers : Providers , extern_providers : ExternProviders ) -> Self {
82+ QuerySystem {
83+ local_providers : Box :: new ( local_providers) ,
84+ extern_providers : Box :: new ( extern_providers) ,
85+ arenas : Default :: default ( ) ,
86+ caches : Default :: default ( ) ,
87+ }
88+ }
89+ }
90+
6991#[ derive( Copy , Clone ) ]
7092pub struct TyCtxtAt < ' tcx > {
7193 pub tcx : TyCtxt < ' tcx > ,
@@ -112,10 +134,10 @@ macro_rules! query_helper_param_ty {
112134}
113135
114136macro_rules! query_if_arena {
115- ( [ ] $arena: ty , $no_arena: ty ) => {
137+ ( [ ] $arena: tt $no_arena: tt ) => {
116138 $no_arena
117139 } ;
118- ( [ ( arena_cache) $( $rest: tt) * ] $arena: ty , $no_arena: ty ) => {
140+ ( [ ( arena_cache) $( $rest: tt) * ] $arena: tt $no_arena: tt ) => {
119141 $arena
120142 } ;
121143 ( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
@@ -131,7 +153,7 @@ macro_rules! separate_provide_extern_decl {
131153 for <' tcx> fn (
132154 TyCtxt <' tcx>,
133155 query_keys:: $name<' tcx>,
134- ) -> query_values :: $name<' tcx>
156+ ) -> query_provided :: $name<' tcx>
135157 } ;
136158 ( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
137159 separate_provide_extern_decl!( [ $( $modifiers) * ] [ $( $args) * ] )
@@ -183,30 +205,62 @@ macro_rules! define_callbacks {
183205
184206 $( pub type $name<' tcx> = $( $K) * ; ) *
185207 }
186- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
208+ #[ allow( nonstandard_style, unused_lifetimes) ]
187209 pub mod query_values {
188210 use super :: * ;
189211
190- $( pub type $name<' tcx> = query_if_arena! ( [ $ ( $modifiers ) * ] <$V as Deref > :: Target , $V ) ; ) *
212+ $( pub type $name<' tcx> = $V ; ) *
191213 }
192- #[ allow( nonstandard_style, unused_lifetimes, unused_parens ) ]
193- pub mod query_storage {
214+ #[ allow( nonstandard_style, unused_lifetimes) ]
215+ pub mod query_provided {
194216 use super :: * ;
195217
196218 $(
197- pub type $name<' tcx> = query_if_arena!( [ $( $modifiers) * ]
198- <<$( $K) * as Key >:: CacheSelector
199- as CacheSelector <' tcx, <$V as Deref >:: Target >>:: ArenaCache ,
200- <<$( $K) * as Key >:: CacheSelector as CacheSelector <' tcx, $V>>:: Cache
201- ) ;
219+ pub type $name<' tcx> = query_if_arena!( [ $( $modifiers) * ] ( <$V as Deref >:: Target ) ( $V) ) ;
202220 ) *
203221 }
222+ #[ allow( nonstandard_style, unused_lifetimes) ]
223+ pub mod query_provided_to_value {
224+ use super :: * ;
204225
226+ $(
227+ #[ inline]
228+ pub fn $name<' tcx>(
229+ _tcx: TyCtxt <' tcx>,
230+ value: query_provided:: $name<' tcx>,
231+ ) -> query_values:: $name<' tcx> {
232+ query_if_arena!( [ $( $modifiers) * ]
233+ ( & * _tcx. query_system. arenas. $name. alloc( value) )
234+ ( value)
235+ )
236+ }
237+ ) *
238+ }
205239 #[ allow( nonstandard_style, unused_lifetimes) ]
206- pub mod query_stored {
240+ pub mod query_storage {
207241 use super :: * ;
208242
209- $( pub type $name<' tcx> = $V; ) *
243+ $(
244+ pub type $name<' tcx> = <<$( $K) * as Key >:: CacheSelector as CacheSelector <' tcx, $V>>:: Cache ;
245+ ) *
246+ }
247+
248+ pub struct QueryArenas <' tcx> {
249+ $( $( #[ $attr] ) * pub $name: query_if_arena!( [ $( $modifiers) * ]
250+ ( WorkerLocal <TypedArena <<$V as Deref >:: Target >>)
251+ ( )
252+ ) , ) *
253+ }
254+
255+ impl Default for QueryArenas <' _> {
256+ fn default ( ) -> Self {
257+ Self {
258+ $( $name: query_if_arena!( [ $( $modifiers) * ]
259+ ( WorkerLocal :: new( |_| Default :: default ( ) ) )
260+ ( )
261+ ) , ) *
262+ }
263+ }
210264 }
211265
212266 #[ derive( Default ) ]
@@ -221,7 +275,7 @@ macro_rules! define_callbacks {
221275 let key = key. into_query_param( ) ;
222276 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
223277
224- match try_get_cached( self . tcx, & self . tcx. query_caches . $name, & key) {
278+ match try_get_cached( self . tcx, & self . tcx. query_system . caches . $name, & key) {
225279 Some ( _) => return ,
226280 None => self . tcx. queries. $name( self . tcx, DUMMY_SP , key, QueryMode :: Ensure ) ,
227281 } ;
@@ -246,7 +300,7 @@ macro_rules! define_callbacks {
246300 let key = key. into_query_param( ) ;
247301 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
248302
249- match try_get_cached( self . tcx, & self . tcx. query_caches . $name, & key) {
303+ match try_get_cached( self . tcx, & self . tcx. query_system . caches . $name, & key) {
250304 Some ( value) => value,
251305 None => self . tcx. queries. $name( self . tcx, self . span, key, QueryMode :: Get ) . unwrap( ) ,
252306 }
@@ -257,7 +311,7 @@ macro_rules! define_callbacks {
257311 $( pub $name: for <' tcx> fn (
258312 TyCtxt <' tcx>,
259313 query_keys:: $name<' tcx>,
260- ) -> query_values :: $name<' tcx>, ) *
314+ ) -> query_provided :: $name<' tcx>, ) *
261315 }
262316
263317 pub struct ExternProviders {
@@ -334,12 +388,13 @@ macro_rules! define_feedable {
334388 $( impl <' tcx, K : IntoQueryParam <$( $K) * > + Copy > TyCtxtFeed <' tcx, K > {
335389 $( #[ $attr] ) *
336390 #[ inline( always) ]
337- pub fn $name( self , value: query_values :: $name<' tcx>) -> $V {
391+ pub fn $name( self , value: query_provided :: $name<' tcx>) -> $V {
338392 let key = self . key( ) . into_query_param( ) ;
339393 opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
340394
341395 let tcx = self . tcx;
342- let cache = & tcx. query_caches. $name;
396+ let value = query_provided_to_value:: $name( tcx, value) ;
397+ let cache = & tcx. query_system. caches. $name;
343398
344399 match try_get_cached( tcx, cache, & key) {
345400 Some ( old) => {
@@ -357,7 +412,8 @@ macro_rules! define_feedable {
357412 & value,
358413 hash_result!( [ $( $modifiers) * ] ) ,
359414 ) ;
360- cache. complete( key, value, dep_node_index)
415+ cache. complete( key, value, dep_node_index) ;
416+ value
361417 }
362418 }
363419 }
0 commit comments