@@ -88,6 +88,12 @@ pub struct DepKindStruct {
88
88
/// their inputs have not changed since the last compiler invocation. The result is still
89
89
/// cached within one compiler invocation.
90
90
pub ( super ) is_eval_always : bool ,
91
+
92
+ /// Whether the query key can be recovered from the hashed fingerprint.
93
+ /// See [DepNodeParams] trait for the behaviour of each key type.
94
+ // FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
95
+ // can be made a specialized associated const.
96
+ can_reconstruct_query_key : fn ( ) -> bool ,
91
97
}
92
98
93
99
impl std:: ops:: Deref for DepKind {
@@ -97,6 +103,19 @@ impl std::ops::Deref for DepKind {
97
103
}
98
104
}
99
105
106
+ impl DepKind {
107
+ #[ inline( always) ]
108
+ pub fn can_reconstruct_query_key ( & self ) -> bool {
109
+ // Only fetch the DepKindStruct once.
110
+ let data: & DepKindStruct = & * * self ;
111
+ if data. is_anon {
112
+ return false ;
113
+ }
114
+
115
+ ( data. can_reconstruct_query_key ) ( )
116
+ }
117
+ }
118
+
100
119
// erase!() just makes tokens go away. It's used to specify which macro argument
101
120
// is repeated (i.e., which sub-expression of the macro we are in) but don't need
102
121
// to actually use any of the arguments.
@@ -133,20 +152,41 @@ macro_rules! contains_eval_always_attr {
133
152
#[ allow( non_upper_case_globals) ]
134
153
pub mod dep_kind {
135
154
use super :: * ;
155
+ use crate :: ty:: query:: query_keys;
136
156
137
157
// We use this for most things when incr. comp. is turned off.
138
- pub const Null : DepKindStruct =
139
- DepKindStruct { has_params : false , is_anon : false , is_eval_always : false } ;
158
+ pub const Null : DepKindStruct = DepKindStruct {
159
+ has_params : false ,
160
+ is_anon : false ,
161
+ is_eval_always : false ,
162
+
163
+ can_reconstruct_query_key : || true ,
164
+ } ;
140
165
141
166
// Represents metadata from an extern crate.
142
- pub const CrateMetadata : DepKindStruct =
143
- DepKindStruct { has_params : true , is_anon : false , is_eval_always : true } ;
167
+ pub const CrateMetadata : DepKindStruct = DepKindStruct {
168
+ has_params : true ,
169
+ is_anon : false ,
170
+ is_eval_always : true ,
171
+
172
+ can_reconstruct_query_key : || true ,
173
+ } ;
174
+
175
+ pub const TraitSelect : DepKindStruct = DepKindStruct {
176
+ has_params : false ,
177
+ is_anon : true ,
178
+ is_eval_always : false ,
144
179
145
- pub const TraitSelect : DepKindStruct =
146
- DepKindStruct { has_params : false , is_anon : true , is_eval_always : false } ;
180
+ can_reconstruct_query_key : || false ,
181
+ } ;
182
+
183
+ pub const CompileCodegenUnit : DepKindStruct = DepKindStruct {
184
+ has_params : true ,
185
+ is_anon : false ,
186
+ is_eval_always : false ,
147
187
148
- pub const CompileCodegenUnit : DepKindStruct =
149
- DepKindStruct { has_params : true , is_anon : false , is_eval_always : false } ;
188
+ can_reconstruct_query_key : || false ,
189
+ } ;
150
190
151
191
macro_rules! define_query_dep_kinds {
152
192
( $(
@@ -158,10 +198,18 @@ pub mod dep_kind {
158
198
const is_anon: bool = contains_anon_attr!( $( $attrs) * ) ;
159
199
const is_eval_always: bool = contains_eval_always_attr!( $( $attrs) * ) ;
160
200
201
+ #[ inline( always) ]
202
+ fn can_reconstruct_query_key( ) -> bool {
203
+ !is_anon &&
204
+ <query_keys:: $variant<' _> as DepNodeParams <TyCtxt <' _>>>
205
+ :: can_reconstruct_query_key( )
206
+ }
207
+
161
208
DepKindStruct {
162
209
has_params,
163
210
is_anon,
164
211
is_eval_always,
212
+ can_reconstruct_query_key,
165
213
}
166
214
} ; ) *
167
215
) ;
@@ -186,29 +234,6 @@ macro_rules! define_dep_nodes {
186
234
$( $variant) ,*
187
235
}
188
236
189
- impl DepKind {
190
- #[ allow( unreachable_code) ]
191
- pub fn can_reconstruct_query_key<$tcx>( & self ) -> bool {
192
- if self . is_anon {
193
- return false ;
194
- }
195
-
196
- match * self {
197
- $(
198
- DepKind :: $variant => {
199
- // tuple args
200
- $( {
201
- return <$tuple_arg_ty as DepNodeParams <TyCtxt <' _>>>
202
- :: can_reconstruct_query_key( ) ;
203
- } ) *
204
-
205
- true
206
- }
207
- ) *
208
- }
209
- }
210
- }
211
-
212
237
pub struct DepConstructor ;
213
238
214
239
#[ allow( non_camel_case_types) ]
0 commit comments