33#![ doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/" ) ]
44// this shouldn't be necessary, but the check for `&mut _` is too naive and denies returning a function pointer that takes a mut ref
55#![ feature( const_mut_refs) ]
6+ #![ feature( const_refs_to_cell) ]
67#![ feature( min_specialization) ]
78#![ feature( never_type) ]
89#![ feature( once_cell) ]
910#![ feature( rustc_attrs) ]
1011#![ recursion_limit = "256" ]
11- #![ allow( rustc:: potential_query_instability) ]
12+ #![ allow( rustc:: potential_query_instability, unused_parens ) ]
1213#![ deny( rustc:: untranslatable_diagnostic) ]
1314#![ deny( rustc:: diagnostic_outside_of_impl) ]
1415
@@ -17,37 +18,211 @@ extern crate rustc_macros;
1718#[ macro_use]
1819extern crate rustc_middle;
1920
20- use rustc_data_structures:: sync:: AtomicU64 ;
21+ use memoffset:: offset_of;
22+ use rustc_data_structures:: fingerprint:: Fingerprint ;
23+ use rustc_data_structures:: stable_hasher:: HashStable ;
2124use rustc_middle:: arena:: Arena ;
2225use rustc_middle:: dep_graph:: { self , DepKindStruct } ;
2326use rustc_middle:: query:: Key ;
27+ use rustc_middle:: ty:: query:: QueryCaches ;
2428use rustc_middle:: ty:: query:: {
2529 query_keys, query_provided, query_provided_to_value, query_storage, query_values,
2630} ;
27- use rustc_middle:: ty:: query:: { ExternProviders , Providers , QueryEngine } ;
31+ use rustc_middle:: ty:: query:: { Providers , QueryEngine } ;
2832use rustc_middle:: ty:: TyCtxt ;
33+ use rustc_query_system:: dep_graph:: DepNodeParams ;
34+ use rustc_query_system:: ich:: StableHashingContext ;
2935use rustc_span:: Span ;
36+ use std:: fmt;
37+ use std:: marker:: PhantomData ;
3038
3139#[ macro_use]
3240mod plumbing;
33- pub use plumbing:: QueryCtxt ;
41+ pub use plumbing:: { Queries , QueryCtxt } ;
3442use rustc_query_system:: query:: * ;
3543#[ cfg( parallel_compiler) ]
3644pub use rustc_query_system:: query:: { deadlock, QueryContext } ;
3745
3846pub use rustc_query_system:: query:: QueryConfig ;
47+ use rustc_query_system:: HandleCycleError ;
3948
4049mod on_disk_cache;
4150pub use on_disk_cache:: OnDiskCache ;
4251
4352mod profiling_support;
4453pub use self :: profiling_support:: alloc_self_profile_query_strings;
4554
46- rustc_query_append ! { define_queries! }
55+ trait Bool {
56+ fn value ( ) -> bool ;
57+ }
58+
59+ struct True ;
60+
61+ impl Bool for True {
62+ fn value ( ) -> bool {
63+ true
64+ }
65+ }
66+ struct False ;
67+
68+ impl Bool for False {
69+ fn value ( ) -> bool {
70+ false
71+ }
72+ }
73+ struct DynamicQuery < ' tcx , C : QueryCache > {
74+ name : & ' static str ,
75+ cache_on_disk : fn ( tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> bool ,
76+ execute_query : fn ( tcx : TyCtxt < ' tcx > , k : C :: Key ) -> C :: Value ,
77+ compute : fn ( tcx : TyCtxt < ' tcx > , key : C :: Key ) -> C :: Value ,
78+ try_load_from_disk :
79+ fn ( qcx : QueryCtxt < ' tcx > , idx : & C :: Key ) -> TryLoadFromDisk < QueryCtxt < ' tcx > , C :: Value > ,
80+ query_state : usize ,
81+ query_cache : usize ,
82+ eval_always : bool ,
83+ dep_kind : rustc_middle:: dep_graph:: DepKind ,
84+ handle_cycle_error : HandleCycleError ,
85+ hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & C :: Value ) -> Fingerprint > ,
86+ }
87+
88+ struct DynamicConfig < ' tcx , C : QueryCache , Anon , DepthLimit , Feedable > {
89+ dynamic : & ' tcx DynamicQuery < ' tcx , C > ,
90+ data : PhantomData < ( Anon , DepthLimit , Feedable ) > ,
91+ }
92+
93+ impl < ' tcx , C : QueryCache , Anon , DepthLimit , Feedable > Copy
94+ for DynamicConfig < ' tcx , C , Anon , DepthLimit , Feedable >
95+ {
96+ }
97+ impl < ' tcx , C : QueryCache , Anon , DepthLimit , Feedable > Clone
98+ for DynamicConfig < ' tcx , C , Anon , DepthLimit , Feedable >
99+ {
100+ fn clone ( & self ) -> Self {
101+ DynamicConfig { dynamic : self . dynamic , data : PhantomData }
102+ }
103+ }
104+
105+ impl < ' tcx , C : QueryCache , Anon , DepthLimit , Feedable > fmt:: Debug
106+ for DynamicConfig < ' tcx , C , Anon , DepthLimit , Feedable >
107+ {
108+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
109+ write ! ( f, "DynamicConfig<{}>" , self . dynamic. name)
110+ }
111+ }
112+
113+ impl < ' tcx , C : QueryCache , Anon : Bool , DepthLimit : Bool , Feedable : Bool > QueryConfig < QueryCtxt < ' tcx > >
114+ for DynamicConfig < ' tcx , C , Anon , DepthLimit , Feedable >
115+ where
116+ for < ' a > C :: Key : HashStable < StableHashingContext < ' a > > ,
117+ {
118+ type Key = C :: Key ;
119+ type Value = C :: Value ;
120+ type Cache = C ;
121+
122+ #[ inline( always) ]
123+ fn name ( self ) -> & ' static str {
124+ self . dynamic . name
125+ }
126+
127+ #[ inline( always) ]
128+ fn cache_on_disk ( self , tcx : TyCtxt < ' tcx > , key : & Self :: Key ) -> bool {
129+ ( self . dynamic . cache_on_disk ) ( tcx, key)
130+ }
131+
132+ #[ inline( always) ]
133+ fn query_state < ' a > (
134+ self ,
135+ tcx : QueryCtxt < ' tcx > ,
136+ ) -> & ' a QueryState < Self :: Key , crate :: dep_graph:: DepKind >
137+ where
138+ QueryCtxt < ' tcx > : ' a ,
139+ {
140+ unsafe {
141+ & * ( ( & tcx. queries . query_states as * const QueryStates < ' tcx > as * const u8 )
142+ . offset ( self . dynamic . query_state as isize ) as * const _ )
143+ }
144+ }
47145
48- impl < ' tcx > Queries < ' tcx > {
49- // Force codegen in the dyn-trait transformation in this crate.
50- pub fn as_dyn ( & ' tcx self ) -> & ' tcx dyn QueryEngine < ' tcx > {
51- self
146+ #[ inline( always) ]
147+ fn query_cache < ' a > ( self , tcx : QueryCtxt < ' tcx > ) -> & ' a Self :: Cache
148+ where
149+ ' tcx : ' a ,
150+ {
151+ unsafe {
152+ & * ( ( & tcx. query_system . caches as * const QueryCaches < ' tcx > as * const u8 )
153+ . offset ( self . dynamic . query_cache as isize ) as * const _ )
154+ }
155+ }
156+
157+ #[ inline( always) ]
158+ fn execute_query ( self , tcx : TyCtxt < ' tcx > , key : Self :: Key ) -> Self :: Value {
159+ ( self . dynamic . execute_query ) ( tcx, key)
160+ }
161+
162+ #[ inline( always) ]
163+ fn compute ( self , tcx : TyCtxt < ' tcx > , key : Self :: Key ) -> Self :: Value {
164+ ( self . dynamic . compute ) ( tcx, key)
165+ }
166+
167+ #[ inline( always) ]
168+ fn try_load_from_disk (
169+ self ,
170+ qcx : QueryCtxt < ' tcx > ,
171+ key : & Self :: Key ,
172+ ) -> rustc_query_system:: query:: TryLoadFromDisk < QueryCtxt < ' tcx > , Self :: Value > {
173+ ( self . dynamic . try_load_from_disk ) ( qcx, key)
174+ }
175+
176+ #[ inline( always) ]
177+ fn anon ( self ) -> bool {
178+ Anon :: value ( )
179+ }
180+
181+ #[ inline( always) ]
182+ fn eval_always ( self ) -> bool {
183+ self . dynamic . eval_always
184+ }
185+
186+ #[ inline( always) ]
187+ fn depth_limit ( self ) -> bool {
188+ DepthLimit :: value ( )
189+ }
190+
191+ #[ inline( always) ]
192+ fn feedable ( self ) -> bool {
193+ Feedable :: value ( )
194+ }
195+
196+ #[ inline( always) ]
197+ fn dep_kind ( self ) -> rustc_middle:: dep_graph:: DepKind {
198+ self . dynamic . dep_kind
199+ }
200+
201+ #[ inline( always) ]
202+ fn handle_cycle_error ( self ) -> rustc_query_system:: HandleCycleError {
203+ self . dynamic . handle_cycle_error
204+ }
205+
206+ #[ inline( always) ]
207+ fn hash_result ( self ) -> rustc_query_system:: query:: HashResult < Self :: Value > {
208+ self . dynamic . hash_result
52209 }
53210}
211+
212+ trait QueryToConfig < ' tcx > : ' tcx
213+ where
214+ for < ' a > <Self :: Cache as QueryCache >:: Key : HashStable < StableHashingContext < ' a > > ,
215+ {
216+ type Cache : QueryCache ;
217+ type Key : DepNodeParams < TyCtxt < ' tcx > > ;
218+
219+ type Anon : Bool ;
220+ type DepthLimit : Bool ;
221+ type Feedable : Bool ;
222+
223+ fn config (
224+ qcx : QueryCtxt < ' tcx > ,
225+ ) -> DynamicConfig < ' tcx , Self :: Cache , Self :: Anon , Self :: DepthLimit , Self :: Feedable > ;
226+ }
227+
228+ rustc_query_append ! { define_queries! }
0 commit comments