]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_middle/src/dep_graph/dep_node.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / compiler / rustc_middle / src / dep_graph / dep_node.rs
CommitLineData
5869c6ff 1//! Nodes in the dependency graph.
3dfed10e 2//!
5869c6ff
XL
3//! A node in the [dependency graph] is represented by a [`DepNode`].
4//! A `DepNode` consists of a [`DepKind`] (which
5//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
6//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
041b39d2
XL
7//! depends on the node's `DepKind`. Together, the kind and the fingerprint
8//! fully identify a dependency node, even across multiple compilation sessions.
9//! In other words, the value of the fingerprint does not depend on anything
10//! that is specific to a given compilation session, like an unpredictable
5869c6ff 11//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
041b39d2 12//! pointer. The concept behind this could be compared to how git commit hashes
5869c6ff
XL
13//! uniquely identify a given commit. The fingerprinting approach has
14//! a few advantages:
041b39d2
XL
15//!
16//! * A `DepNode` can simply be serialized to disk and loaded in another session
3dfed10e
XL
17//! without the need to do any "rebasing" (like we have to do for Spans and
18//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
19//! implementations of the dependency graph).
041b39d2
XL
20//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
21//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
22//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
0731742a 23//! memory without any post-processing (e.g., "abomination-style" pointer
041b39d2
XL
24//! reconstruction).
25//! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
26//! refer to things that do not exist anymore. In previous implementations
27//! `DepNode` contained a `DefId`. A `DepNode` referring to something that
28//! had been removed between the previous and the current compilation session
29//! could not be instantiated because the current compilation session
30//! contained no `DefId` for thing that had been removed.
31//!
32//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
5869c6ff
XL
33//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
34//! needed at runtime in order to construct a valid `DepNode` fingerprint.
35//! However, only `CompileCodegenUnit` is constructed explicitly (with
36//! `make_compile_codegen_unit`).
041b39d2
XL
37//!
38//! Because the macro sees what parameters a given `DepKind` requires, it can
39//! "infer" some properties for each kind of `DepNode`:
40//!
41//! * Whether a `DepNode` of a given kind has any parameters at all. Some
ba9703b0 42//! `DepNode`s could represent global concepts with only one value.
041b39d2
XL
43//! * Whether it is possible, in principle, to reconstruct a query key from a
44//! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
45//! in which case it is possible to map the node's fingerprint back to the
46//! `DefId` it was computed from. In other cases, too much information gets
47//! lost during fingerprint computation.
48//!
5869c6ff 49//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only
041b39d2
XL
50//! valid `DepNode` instances can be constructed. For example, the API does not
51//! allow for constructing parameterless `DepNode`s with anything other
52//! than a zeroed out fingerprint. More generally speaking, it relieves the
53//! user of the `DepNode` API of having to know how to compute the expected
54//! fingerprint for a given set of node parameters.
5869c6ff
XL
55//!
56//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
041b39d2 57
5869c6ff 58use crate::ty::TyCtxt;
dfeec247 59
ba9703b0
XL
60use rustc_data_structures::fingerprint::Fingerprint;
61use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
62use rustc_hir::definitions::DefPathHash;
dfeec247
XL
63use rustc_hir::HirId;
64use rustc_span::symbol::Symbol;
5869c6ff 65use rustc_span::DUMMY_SP;
dfeec247 66use std::hash::Hash;
041b39d2 67
ba9703b0
XL
68pub use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
69
5869c6ff
XL
70/// This struct stores metadata about each DepKind.
71///
72/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
73/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
74/// jump table instead of large matches.
75pub struct DepKindStruct {
76 /// Whether the DepNode has parameters (query keys).
77 pub(super) has_params: bool,
78
79 /// Anonymous queries cannot be replayed from one compiler invocation to the next.
80 /// When their result is needed, it is recomputed. They are useful for fine-grained
81 /// dependency tracking, and caching within one compiler invocation.
82 pub(super) is_anon: bool,
83
84 /// Eval-always queries do not track their dependencies, and are always recomputed, even if
85 /// their inputs have not changed since the last compiler invocation. The result is still
86 /// cached within one compiler invocation.
87 pub(super) is_eval_always: bool,
88
89 /// Whether the query key can be recovered from the hashed fingerprint.
90 /// See [DepNodeParams] trait for the behaviour of each key type.
91 // FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
92 // can be made a specialized associated const.
93 can_reconstruct_query_key: fn() -> bool,
94
95 /// The red/green evaluation system will try to mark a specific DepNode in the
96 /// dependency graph as green by recursively trying to mark the dependencies of
97 /// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
98 /// where we don't know if it is red or green and we therefore actually have
99 /// to recompute its value in order to find out. Since the only piece of
100 /// information that we have at that point is the `DepNode` we are trying to
101 /// re-evaluate, we need some way to re-run a query from just that. This is what
102 /// `force_from_dep_node()` implements.
103 ///
104 /// In the general case, a `DepNode` consists of a `DepKind` and an opaque
105 /// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
106 /// is usually constructed by computing a stable hash of the query-key that the
107 /// `DepNode` corresponds to. Consequently, it is not in general possible to go
108 /// back from hash to query-key (since hash functions are not reversible). For
109 /// this reason `force_from_dep_node()` is expected to fail from time to time
110 /// because we just cannot find out, from the `DepNode` alone, what the
111 /// corresponding query-key is and therefore cannot re-run the query.
112 ///
113 /// The system deals with this case letting `try_mark_green` fail which forces
114 /// the root query to be re-evaluated.
115 ///
116 /// Now, if `force_from_dep_node()` would always fail, it would be pretty useless.
117 /// Fortunately, we can use some contextual information that will allow us to
118 /// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we
119 /// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a
120 /// valid `DefPathHash`. Since we also always build a huge table that maps every
121 /// `DefPathHash` in the current codebase to the corresponding `DefId`, we have
122 /// everything we need to re-run the query.
123 ///
124 /// Take the `mir_promoted` query as an example. Like many other queries, it
125 /// just has a single parameter: the `DefId` of the item it will compute the
126 /// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode`
127 /// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
128 /// is actually a `DefPathHash`, and can therefore just look up the corresponding
129 /// `DefId` in `tcx.def_path_hash_to_def_id`.
130 ///
131 /// When you implement a new query, it will likely have a corresponding new
132 /// `DepKind`, and you'll have to support it here in `force_from_dep_node()`. As
133 /// a rule of thumb, if your query takes a `DefId` or `LocalDefId` as sole parameter,
134 /// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
135 /// add it to the "We don't have enough information to reconstruct..." group in
136 /// the match below.
137 pub(super) force_from_dep_node: fn(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool,
138
139 /// Invoke a query to put the on-disk cached value in memory.
140 pub(super) try_load_from_on_disk_cache: fn(TyCtxt<'_>, &DepNode),
141}
142
143impl std::ops::Deref for DepKind {
144 type Target = DepKindStruct;
145 fn deref(&self) -> &DepKindStruct {
146 &DEP_KINDS[*self as usize]
147 }
148}
149
150impl DepKind {
151 #[inline(always)]
152 pub fn can_reconstruct_query_key(&self) -> bool {
153 // Only fetch the DepKindStruct once.
154 let data: &DepKindStruct = &**self;
155 if data.is_anon {
156 return false;
157 }
158
159 (data.can_reconstruct_query_key)()
160 }
161}
162
041b39d2 163// erase!() just makes tokens go away. It's used to specify which macro argument
0731742a 164// is repeated (i.e., which sub-expression of the macro we are in) but don't need
041b39d2
XL
165// to actually use any of the arguments.
166macro_rules! erase {
dfeec247 167 ($x:tt) => {{}};
041b39d2
XL
168}
169
ea8adc8c 170macro_rules! is_anon_attr {
dfeec247
XL
171 (anon) => {
172 true
173 };
174 ($attr:ident) => {
175 false
176 };
ea8adc8c
XL
177}
178
abe05a73 179macro_rules! is_eval_always_attr {
dfeec247
XL
180 (eval_always) => {
181 true
182 };
183 ($attr:ident) => {
184 false
185 };
abe05a73
XL
186}
187
ea8adc8c 188macro_rules! contains_anon_attr {
74b04a01 189 ($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_anon_attr!($attr) | )* false});
ea8adc8c
XL
190}
191
abe05a73 192macro_rules! contains_eval_always_attr {
74b04a01 193 ($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_eval_always_attr!($attr) | )* false});
abe05a73
XL
194}
195
5869c6ff
XL
196#[allow(non_upper_case_globals)]
197pub mod dep_kind {
198 use super::*;
199 use crate::ty::query::{queries, query_keys};
200 use rustc_query_system::query::{force_query, QueryDescription};
041b39d2 201
5869c6ff
XL
202 // We use this for most things when incr. comp. is turned off.
203 pub const Null: DepKindStruct = DepKindStruct {
204 has_params: false,
205 is_anon: false,
206 is_eval_always: false,
207
208 can_reconstruct_query_key: || true,
209 force_from_dep_node: |_, dep_node| bug!("force_from_dep_node: encountered {:?}", dep_node),
210 try_load_from_on_disk_cache: |_, _| {},
211 };
041b39d2 212
5869c6ff
XL
213 pub const TraitSelect: DepKindStruct = DepKindStruct {
214 has_params: false,
215 is_anon: true,
216 is_eval_always: false,
ea8adc8c 217
5869c6ff
XL
218 can_reconstruct_query_key: || true,
219 force_from_dep_node: |_, _| false,
220 try_load_from_on_disk_cache: |_, _| {},
221 };
abe05a73 222
5869c6ff
XL
223 pub const CompileCodegenUnit: DepKindStruct = DepKindStruct {
224 has_params: true,
225 is_anon: false,
226 is_eval_always: false,
041b39d2 227
5869c6ff
XL
228 can_reconstruct_query_key: || false,
229 force_from_dep_node: |_, _| false,
230 try_load_from_on_disk_cache: |_, _| {},
231 };
232
233 macro_rules! define_query_dep_kinds {
234 ($(
235 [$($attrs:tt)*]
236 $variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
237 ,)*) => (
238 $(pub const $variant: DepKindStruct = {
239 const has_params: bool = $({ erase!($tuple_arg_ty); true } |)* false;
240 const is_anon: bool = contains_anon_attr!($($attrs)*);
241 const is_eval_always: bool = contains_eval_always_attr!($($attrs)*);
74b04a01 242
74b04a01 243 #[inline(always)]
5869c6ff
XL
244 fn can_reconstruct_query_key() -> bool {
245 <query_keys::$variant<'_> as DepNodeParams<TyCtxt<'_>>>
246 ::can_reconstruct_query_key()
74b04a01 247 }
041b39d2 248
5869c6ff
XL
249 fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<query_keys::$variant<'tcx>> {
250 <query_keys::$variant<'_> as DepNodeParams<TyCtxt<'_>>>::recover(tcx, dep_node)
041b39d2 251 }
041b39d2 252
5869c6ff
XL
253 fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool {
254 if is_anon {
255 return false;
256 }
257
258 if !can_reconstruct_query_key() {
259 return false;
260 }
261
262 if let Some(key) = recover(tcx, dep_node) {
263 force_query::<queries::$variant<'_>, _>(
264 tcx,
265 key,
266 DUMMY_SP,
267 *dep_node
268 );
269 return true;
270 }
271
272 false
041b39d2 273 }
041b39d2 274
5869c6ff
XL
275 fn try_load_from_on_disk_cache(tcx: TyCtxt<'_>, dep_node: &DepNode) {
276 if is_anon {
277 return
278 }
279
280 if !can_reconstruct_query_key() {
281 return
282 }
283
284 debug_assert!(tcx.dep_graph
285 .node_color(dep_node)
286 .map(|c| c.is_green())
287 .unwrap_or(false));
041b39d2 288
5869c6ff
XL
289 let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
290 if queries::$variant::cache_on_disk(tcx, &key, None) {
291 let _ = tcx.$variant(key);
292 }
041b39d2 293 }
ea8adc8c 294
5869c6ff
XL
295 DepKindStruct {
296 has_params,
297 is_anon,
298 is_eval_always,
299 can_reconstruct_query_key,
300 force_from_dep_node,
301 try_load_from_on_disk_cache,
ea8adc8c 302 }
5869c6ff
XL
303 };)*
304 );
305 }
306
307 rustc_dep_node_append!([define_query_dep_kinds!][]);
308}
309
310macro_rules! define_dep_nodes {
311 (<$tcx:tt>
312 $(
313 [$($attrs:tt)*]
314 $variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
315 ,)*
316 ) => (
317 static DEP_KINDS: &[DepKindStruct] = &[ $(dep_kind::$variant),* ];
318
319 /// This enum serves as an index into the `DEP_KINDS` array.
320 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
321 #[allow(non_camel_case_types)]
322 pub enum DepKind {
323 $($variant),*
324 }
325
326 fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> {
327 match label {
328 $(stringify!($variant) => Ok(DepKind::$variant),)*
329 _ => Err(()),
ea8adc8c
XL
330 }
331 }
332
333 /// Contains variant => str representations for constructing
334 /// DepNode groups for tests.
335 #[allow(dead_code, non_upper_case_globals)]
336 pub mod label_strs {
337 $(
0731742a 338 pub const $variant: &str = stringify!($variant);
ea8adc8c 339 )*
041b39d2
XL
340 }
341 );
342}
343
532ac7d7 344rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
0531ce1d
XL
345 // We use this for most things when incr. comp. is turned off.
346 [] Null,
347
3b2f2976 348 [anon] TraitSelect,
041b39d2 349
5869c6ff 350 // WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
e74abb32 351 [] CompileCodegenUnit(Symbol),
532ac7d7
XL
352]);
353
5869c6ff
XL
354// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
355// Be very careful changing this type signature!
356crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
357 DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
358}
359
360pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
361
362// We keep a lot of `DepNode`s in memory during compilation. It's not
363// required that their size stay the same, but we don't want to change
364// it inadvertently. This assert just ensures we're aware of any change.
365#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
366static_assert_size!(DepNode, 17);
367
368#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
369static_assert_size!(DepNode, 24);
370
371pub trait DepNodeExt: Sized {
372 /// Construct a DepNode from the given DepKind and DefPathHash. This
373 /// method will assert that the given DepKind actually requires a
374 /// single DefId/DefPathHash parameter.
375 fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
376
377 /// Extracts the DefId corresponding to this DepNode. This will work
378 /// if two conditions are met:
379 ///
380 /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
381 /// 2. the item that the DefPath refers to exists in the current tcx.
382 ///
383 /// Condition (1) is determined by the DepKind variant of the
384 /// DepNode. Condition (2) might not be fulfilled if a DepNode
385 /// refers to something from the previous compilation session that
386 /// has been removed.
387 fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
388
389 /// Used in testing
390 fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<Self, ()>;
391
392 /// Used in testing
393 fn has_label_string(label: &str) -> bool;
394}
395
396impl DepNodeExt for DepNode {
397 /// Construct a DepNode from the given DepKind and DefPathHash. This
398 /// method will assert that the given DepKind actually requires a
399 /// single DefId/DefPathHash parameter.
400 fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
401 debug_assert!(kind.can_reconstruct_query_key() && kind.has_params);
402 DepNode { kind, hash: def_path_hash.0.into() }
403 }
404
405 /// Extracts the DefId corresponding to this DepNode. This will work
406 /// if two conditions are met:
407 ///
408 /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
409 /// 2. the item that the DefPath refers to exists in the current tcx.
410 ///
411 /// Condition (1) is determined by the DepKind variant of the
412 /// DepNode. Condition (2) might not be fulfilled if a DepNode
413 /// refers to something from the previous compilation session that
414 /// has been removed.
415 fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
416 if self.kind.can_reconstruct_query_key() {
417 tcx.queries
418 .on_disk_cache
419 .as_ref()?
420 .def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
421 } else {
422 None
423 }
424 }
425
426 /// Used in testing
427 fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
428 let kind = dep_kind_from_label_string(label)?;
429
430 if !kind.can_reconstruct_query_key() {
431 return Err(());
432 }
433
434 if kind.has_params {
435 Ok(DepNode::from_def_path_hash(def_path_hash, kind))
436 } else {
437 Ok(DepNode::new_no_params(kind))
438 }
439 }
440
441 /// Used in testing
442 fn has_label_string(label: &str) -> bool {
443 dep_kind_from_label_string(label).is_ok()
444 }
445}
446
447impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
448 #[inline(always)]
449 fn can_reconstruct_query_key() -> bool {
450 true
451 }
452
453 fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint {
454 Fingerprint::ZERO
455 }
456
457 fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
458 Some(())
459 }
460}
461
ba9703b0 462impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
5869c6ff 463 #[inline(always)]
f035d41b
XL
464 fn can_reconstruct_query_key() -> bool {
465 true
466 }
041b39d2 467
ba9703b0 468 fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
fc512014
XL
469 let hash = tcx.def_path_hash(*self);
470 // If this is a foreign `DefId`, store its current value
471 // in the incremental cache. When we decode the cache,
472 // we will use the old DefIndex as an initial guess for
473 // a lookup into the crate metadata.
474 if !self.is_local() {
475 if let Some(cache) = &tcx.queries.on_disk_cache {
476 cache.store_foreign_def_id_hash(*self, hash);
477 }
478 }
479 hash.0
041b39d2
XL
480 }
481
dc9dc135 482 fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
532ac7d7 483 tcx.def_path_str(*self)
041b39d2 484 }
74b04a01
XL
485
486 fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
487 dep_node.extract_def_id(tcx)
488 }
041b39d2 489}
9e0c209e 490
ba9703b0 491impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
5869c6ff 492 #[inline(always)]
f035d41b
XL
493 fn can_reconstruct_query_key() -> bool {
494 true
495 }
ea8adc8c 496
ba9703b0
XL
497 fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
498 self.to_def_id().to_fingerprint(tcx)
ea8adc8c
XL
499 }
500
dc9dc135 501 fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
ba9703b0 502 self.to_def_id().to_debug_str(tcx)
ea8adc8c 503 }
74b04a01
XL
504
505 fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
ba9703b0 506 dep_node.extract_def_id(tcx).map(|id| id.expect_local())
74b04a01 507 }
ea8adc8c
XL
508}
509
ba9703b0 510impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
5869c6ff 511 #[inline(always)]
f035d41b
XL
512 fn can_reconstruct_query_key() -> bool {
513 true
514 }
ea8adc8c 515
ba9703b0 516 fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
dfeec247 517 let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
fc512014 518 def_id.to_fingerprint(tcx)
ea8adc8c
XL
519 }
520
dc9dc135 521 fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
60c5eb7d 522 tcx.crate_name(*self).to_string()
ea8adc8c 523 }
74b04a01
XL
524
525 fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
526 dep_node.extract_def_id(tcx).map(|id| id.krate)
527 }
ea8adc8c
XL
528}
529
ba9703b0 530impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
5869c6ff 531 #[inline(always)]
f035d41b
XL
532 fn can_reconstruct_query_key() -> bool {
533 false
534 }
041b39d2
XL
535
536 // We actually would not need to specialize the implementation of this
537 // method but it's faster to combine the hashes than to instantiate a full
538 // hashing context and stable-hashing state.
ba9703b0 539 fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
041b39d2
XL
540 let (def_id_0, def_id_1) = *self;
541
542 let def_path_hash_0 = tcx.def_path_hash(def_id_0);
543 let def_path_hash_1 = tcx.def_path_hash(def_id_1);
544
545 def_path_hash_0.0.combine(def_path_hash_1.0)
546 }
547
dc9dc135 548 fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
041b39d2
XL
549 let (def_id_0, def_id_1) = *self;
550
dfeec247 551 format!("({}, {})", tcx.def_path_debug_str(def_id_0), tcx.def_path_debug_str(def_id_1))
041b39d2
XL
552 }
553}
554
ba9703b0 555impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
5869c6ff 556 #[inline(always)]
f035d41b
XL
557 fn can_reconstruct_query_key() -> bool {
558 false
559 }
041b39d2
XL
560
561 // We actually would not need to specialize the implementation of this
562 // method but it's faster to combine the hashes than to instantiate a full
563 // hashing context and stable-hashing state.
ba9703b0 564 fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
dfeec247 565 let HirId { owner, local_id } = *self;
041b39d2 566
ba9703b0 567 let def_path_hash = tcx.def_path_hash(owner.to_def_id());
a1dfa0c6 568 let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
041b39d2 569
ea8adc8c 570 def_path_hash.0.combine(local_id)
54a0048b
SL
571 }
572}