@@ -63,6 +63,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
63
63
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
64
64
use rustc_hir::definitions::DefPathHash;
65
65
use rustc_hir::HirId;
66
+ use rustc_query_system::dep_graph::FingerprintStyle;
66
67
use rustc_span::symbol::Symbol;
67
68
use std::hash::Hash;
68
69
@@ -89,9 +90,9 @@ pub struct DepKindStruct {
89
90
90
91
/// Whether the query key can be recovered from the hashed fingerprint.
91
92
/// See [DepNodeParams] trait for the behaviour of each key type.
92
- // FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
93
+ // FIXME: Make this a simple boolean once DepNodeParams::fingerprint_style
93
94
// can be made a specialized associated const.
94
- can_reconstruct_query_key : fn() -> bool ,
95
+ fingerprint_style : fn() -> FingerprintStyle ,
95
96
}
96
97
97
98
impl std::ops::Deref for DepKind {
@@ -103,14 +104,14 @@ impl std::ops::Deref for DepKind {
103
104
104
105
impl DepKind {
105
106
#[inline(always)]
106
- pub fn can_reconstruct_query_key (&self) -> bool {
107
+ pub fn fingerprint_style (&self) -> FingerprintStyle {
107
108
// Only fetch the DepKindStruct once.
108
109
let data: &DepKindStruct = &**self;
109
110
if data.is_anon {
110
- return false ;
111
+ return FingerprintStyle::Opaque ;
111
112
}
112
113
113
- (data.can_reconstruct_query_key )()
114
+ (data.fingerprint_style )()
114
115
}
115
116
}
116
117
@@ -151,38 +152,39 @@ macro_rules! contains_eval_always_attr {
151
152
pub mod dep_kind {
152
153
use super::*;
153
154
use crate::ty::query::query_keys;
155
+ use rustc_query_system::dep_graph::FingerprintStyle;
154
156
155
157
// We use this for most things when incr. comp. is turned off.
156
158
pub const Null: DepKindStruct = DepKindStruct {
157
159
has_params: false,
158
160
is_anon: false,
159
161
is_eval_always: false,
160
162
161
- can_reconstruct_query_key : || true ,
163
+ fingerprint_style : || FingerprintStyle::Unit ,
162
164
};
163
165
164
166
pub const TraitSelect: DepKindStruct = DepKindStruct {
165
167
has_params: false,
166
168
is_anon: true,
167
169
is_eval_always: false,
168
170
169
- can_reconstruct_query_key : || true ,
171
+ fingerprint_style : || FingerprintStyle::Unit ,
170
172
};
171
173
172
174
pub const CompileCodegenUnit: DepKindStruct = DepKindStruct {
173
175
has_params: true,
174
176
is_anon: false,
175
177
is_eval_always: false,
176
178
177
- can_reconstruct_query_key : || false ,
179
+ fingerprint_style : || FingerprintStyle::Opaque ,
178
180
};
179
181
180
182
pub const CompileMonoItem: DepKindStruct = DepKindStruct {
181
183
has_params: true,
182
184
is_anon: false,
183
185
is_eval_always: false,
184
186
185
- can_reconstruct_query_key : || false ,
187
+ fingerprint_style : || FingerprintStyle::Opaque ,
186
188
};
187
189
188
190
macro_rules! define_query_dep_kinds {
@@ -196,16 +198,16 @@ pub mod dep_kind {
196
198
const is_eval_always: bool = contains_eval_always_attr!($($attrs)*);
197
199
198
200
#[inline(always)]
199
- fn can_reconstruct_query_key () -> bool {
201
+ fn fingerprint_style () -> rustc_query_system::dep_graph::FingerprintStyle {
200
202
<query_keys::$variant<'_> as DepNodeParams<TyCtxt<'_>>>
201
- ::can_reconstruct_query_key ()
203
+ ::fingerprint_style ()
202
204
}
203
205
204
206
DepKindStruct {
205
207
has_params,
206
208
is_anon,
207
209
is_eval_always,
208
- can_reconstruct_query_key ,
210
+ fingerprint_style ,
209
211
}
210
212
};)*
211
213
);
@@ -320,7 +322,7 @@ impl DepNodeExt for DepNode {
320
322
/// method will assert that the given DepKind actually requires a
321
323
/// single DefId/DefPathHash parameter.
322
324
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
323
- debug_assert!(kind.can_reconstruct_query_key () && kind.has_params );
325
+ debug_assert!(kind.fingerprint_style () == FingerprintStyle::DefPathHash );
324
326
DepNode { kind, hash: def_path_hash.0.into() }
325
327
}
326
328
@@ -335,7 +337,7 @@ impl DepNodeExt for DepNode {
335
337
/// refers to something from the previous compilation session that
336
338
/// has been removed.
337
339
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
338
- if self.kind.can_reconstruct_query_key() {
340
+ if self.kind.fingerprint_style() == FingerprintStyle::DefPathHash {
339
341
Some(
340
342
tcx.on_disk_cache
341
343
.as_ref()?
@@ -350,14 +352,16 @@ impl DepNodeExt for DepNode {
350
352
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
351
353
let kind = dep_kind_from_label_string(label)?;
352
354
353
- if !kind.can_reconstruct_query_key() {
354
- return Err(());
355
- }
356
-
357
- if kind.has_params {
358
- Ok(DepNode::from_def_path_hash(def_path_hash, kind))
359
- } else {
360
- Ok(DepNode::new_no_params(kind))
355
+ match kind.fingerprint_style() {
356
+ FingerprintStyle::Opaque => Err(()),
357
+ FingerprintStyle::Unit => {
358
+ if !kind.has_params {
359
+ Ok(DepNode::new_no_params(kind))
360
+ } else {
361
+ Err(())
362
+ }
363
+ }
364
+ FingerprintStyle::DefPathHash => Ok(DepNode::from_def_path_hash(def_path_hash, kind)),
361
365
}
362
366
}
363
367
@@ -369,8 +373,8 @@ impl DepNodeExt for DepNode {
369
373
370
374
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
371
375
#[inline(always)]
372
- fn can_reconstruct_query_key () -> bool {
373
- true
376
+ fn fingerprint_style () -> FingerprintStyle {
377
+ FingerprintStyle::Unit
374
378
}
375
379
376
380
fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint {
@@ -384,8 +388,8 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
384
388
385
389
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
386
390
#[inline(always)]
387
- fn can_reconstruct_query_key () -> bool {
388
- true
391
+ fn fingerprint_style () -> FingerprintStyle {
392
+ FingerprintStyle::DefPathHash
389
393
}
390
394
391
395
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
@@ -403,8 +407,8 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
403
407
404
408
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
405
409
#[inline(always)]
406
- fn can_reconstruct_query_key () -> bool {
407
- true
410
+ fn fingerprint_style () -> FingerprintStyle {
411
+ FingerprintStyle::DefPathHash
408
412
}
409
413
410
414
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
@@ -422,8 +426,8 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
422
426
423
427
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
424
428
#[inline(always)]
425
- fn can_reconstruct_query_key () -> bool {
426
- true
429
+ fn fingerprint_style () -> FingerprintStyle {
430
+ FingerprintStyle::DefPathHash
427
431
}
428
432
429
433
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
@@ -442,8 +446,8 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
442
446
443
447
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
444
448
#[inline(always)]
445
- fn can_reconstruct_query_key () -> bool {
446
- false
449
+ fn fingerprint_style () -> FingerprintStyle {
450
+ FingerprintStyle::Opaque
447
451
}
448
452
449
453
// We actually would not need to specialize the implementation of this
@@ -467,8 +471,8 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
467
471
468
472
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
469
473
#[inline(always)]
470
- fn can_reconstruct_query_key () -> bool {
471
- false
474
+ fn fingerprint_style () -> FingerprintStyle {
475
+ FingerprintStyle::Opaque
472
476
}
473
477
474
478
// We actually would not need to specialize the implementation of this
0 commit comments