@@ -88,6 +88,12 @@ pub struct DepKindStruct {
8888 /// their inputs have not changed since the last compiler invocation. The result is still
8989 /// cached within one compiler invocation.
9090 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 ,
9197}
9298
9399impl std:: ops:: Deref for DepKind {
@@ -97,6 +103,19 @@ impl std::ops::Deref for DepKind {
97103 }
98104}
99105
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+
100119// erase!() just makes tokens go away. It's used to specify which macro argument
101120// is repeated (i.e., which sub-expression of the macro we are in) but don't need
102121// to actually use any of the arguments.
@@ -133,20 +152,41 @@ macro_rules! contains_eval_always_attr {
133152#[ allow( non_upper_case_globals) ]
134153pub mod dep_kind {
135154 use super :: * ;
155+ use crate :: ty:: query:: query_keys;
136156
137157 // 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+ } ;
140165
141166 // 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 ,
144179
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 ,
147187
148- pub const CompileCodegenUnit : DepKindStruct =
149- DepKindStruct { has_params : true , is_anon : false , is_eval_always : false } ;
188+ can_reconstruct_query_key : || false ,
189+ } ;
150190
151191 macro_rules! define_query_dep_kinds {
152192 ( $(
@@ -158,10 +198,18 @@ pub mod dep_kind {
158198 const is_anon: bool = contains_anon_attr!( $( $attrs) * ) ;
159199 const is_eval_always: bool = contains_eval_always_attr!( $( $attrs) * ) ;
160200
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+
161208 DepKindStruct {
162209 has_params,
163210 is_anon,
164211 is_eval_always,
212+ can_reconstruct_query_key,
165213 }
166214 } ; ) *
167215 ) ;
@@ -186,29 +234,6 @@ macro_rules! define_dep_nodes {
186234 $( $variant) ,*
187235 }
188236
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-
212237 pub struct DepConstructor ;
213238
214239 #[ allow( non_camel_case_types) ]
0 commit comments