3
3
#![ doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/" ) ]
4
4
// this shouldn't be necessary, but the check for `&mut _` is too naive and denies returning a function pointer that takes a mut ref
5
5
#![ feature( const_mut_refs) ]
6
+ #![ feature( const_refs_to_cell) ]
6
7
#![ feature( min_specialization) ]
7
8
#![ feature( never_type) ]
8
9
#![ feature( once_cell) ]
9
10
#![ feature( rustc_attrs) ]
10
11
#![ recursion_limit = "256" ]
11
- #![ allow( rustc:: potential_query_instability) ]
12
+ #![ allow( rustc:: potential_query_instability, unused_parens ) ]
12
13
#![ deny( rustc:: untranslatable_diagnostic) ]
13
14
#![ deny( rustc:: diagnostic_outside_of_impl) ]
14
15
@@ -17,37 +18,211 @@ extern crate rustc_macros;
17
18
#[ macro_use]
18
19
extern crate rustc_middle;
19
20
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 ;
21
24
use rustc_middle:: arena:: Arena ;
22
25
use rustc_middle:: dep_graph:: { self , DepKindStruct } ;
23
26
use rustc_middle:: query:: Key ;
27
+ use rustc_middle:: ty:: query:: QueryCaches ;
24
28
use rustc_middle:: ty:: query:: {
25
29
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
26
30
} ;
27
- use rustc_middle:: ty:: query:: { ExternProviders , Providers , QueryEngine } ;
31
+ use rustc_middle:: ty:: query:: { Providers , QueryEngine } ;
28
32
use rustc_middle:: ty:: TyCtxt ;
33
+ use rustc_query_system:: dep_graph:: DepNodeParams ;
34
+ use rustc_query_system:: ich:: StableHashingContext ;
29
35
use rustc_span:: Span ;
36
+ use std:: fmt;
37
+ use std:: marker:: PhantomData ;
30
38
31
39
#[ macro_use]
32
40
mod plumbing;
33
- pub use plumbing:: QueryCtxt ;
41
+ pub use plumbing:: { Queries , QueryCtxt } ;
34
42
use rustc_query_system:: query:: * ;
35
43
#[ cfg( parallel_compiler) ]
36
44
pub use rustc_query_system:: query:: { deadlock, QueryContext } ;
37
45
38
46
pub use rustc_query_system:: query:: QueryConfig ;
47
+ use rustc_query_system:: HandleCycleError ;
39
48
40
49
mod on_disk_cache;
41
50
pub use on_disk_cache:: OnDiskCache ;
42
51
43
52
mod profiling_support;
44
53
pub use self :: profiling_support:: alloc_self_profile_query_strings;
45
54
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
+ }
47
145
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
52
209
}
53
210
}
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