1 //! This module defines the `DepNode` type which the compiler uses to represent
2 //! nodes in the dependency graph. A `DepNode` consists of a `DepKind` (which
3 //! specifies the kind of thing it represents, like a piece of HIR, MIR, etc)
4 //! and a `Fingerprint`, a 128 bit hash value the exact meaning of which
5 //! depends on the node's `DepKind`. Together, the kind and the fingerprint
6 //! fully identify a dependency node, even across multiple compilation sessions.
7 //! In other words, the value of the fingerprint does not depend on anything
8 //! that is specific to a given compilation session, like an unpredictable
9 //! interning key (e.g., NodeId, DefId, Symbol) or the numeric value of a
10 //! pointer. The concept behind this could be compared to how git commit hashes
11 //! uniquely identify a given commit and has a few advantages:
13 //! * A `DepNode` can simply be serialized to disk and loaded in another session
14 //! without the need to do any "rebasing (like we have to do for Spans and
15 //! NodeIds) or "retracing" like we had to do for `DefId` in earlier
16 //! implementations of the dependency graph.
17 //! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
18 //! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
19 //! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
20 //! memory without any post-processing (e.g., "abomination-style" pointer
22 //! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
23 //! refer to things that do not exist anymore. In previous implementations
24 //! `DepNode` contained a `DefId`. A `DepNode` referring to something that
25 //! had been removed between the previous and the current compilation session
26 //! could not be instantiated because the current compilation session
27 //! contained no `DefId` for thing that had been removed.
29 //! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
30 //! defines the `DepKind` enum and a corresponding `DepConstructor` enum. The
31 //! `DepConstructor` enum links a `DepKind` to the parameters that are needed at
32 //! runtime in order to construct a valid `DepNode` fingerprint.
34 //! Because the macro sees what parameters a given `DepKind` requires, it can
35 //! "infer" some properties for each kind of `DepNode`:
37 //! * Whether a `DepNode` of a given kind has any parameters at all. Some
38 //! `DepNode`s, like `Krate`, represent global concepts with only one value.
39 //! * Whether it is possible, in principle, to reconstruct a query key from a
40 //! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
41 //! in which case it is possible to map the node's fingerprint back to the
42 //! `DefId` it was computed from. In other cases, too much information gets
43 //! lost during fingerprint computation.
45 //! The `DepConstructor` enum, together with `DepNode::new()` ensures that only
46 //! valid `DepNode` instances can be constructed. For example, the API does not
47 //! allow for constructing parameterless `DepNode`s with anything other
48 //! than a zeroed out fingerprint. More generally speaking, it relieves the
49 //! user of the `DepNode` API of having to know how to compute the expected
50 //! fingerprint for a given set of node parameters.
52 use crate::mir::interpret::GlobalId;
53 use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
54 use crate::hir::map::DefPathHash;
55 use crate::hir::HirId;
57 use crate::ich::{Fingerprint, StableHashingContext};
58 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
61 use syntax_pos::symbol::InternedString;
63 use crate::traits::query::{
64 CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
65 CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalPredicateGoal,
66 CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
68 use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef,
69 ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
70 use crate::ty::subst::Substs;
72 // erase!() just makes tokens go away. It's used to specify which macro argument
73 // is repeated (i.e., which sub-expression of the macro we are in) but don't need
74 // to actually use any of the arguments.
79 macro_rules! replace {
80 ($x:tt with $($y:tt)*) => ($($y)*)
83 macro_rules! is_anon_attr {
85 ($attr:ident) => (false);
88 macro_rules! is_input_attr {
90 ($attr:ident) => (false);
93 macro_rules! is_eval_always_attr {
94 (eval_always) => (true);
95 ($attr:ident) => (false);
98 macro_rules! contains_anon_attr {
99 ($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
102 macro_rules! contains_input_attr {
103 ($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
106 macro_rules! contains_eval_always_attr {
107 ($($attr:ident),*) => ({$(is_eval_always_attr!($attr) | )* false});
110 macro_rules! define_dep_nodes {
114 $variant:ident $(( $tuple_arg_ty:ty $(,)* ))*
115 $({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
118 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
119 RustcEncodable, RustcDecodable)]
125 #[allow(unreachable_code)]
127 pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
130 DepKind :: $variant => {
131 if contains_anon_attr!($($attr),*) {
137 return <$tuple_arg_ty as DepNodeParams>
138 ::CAN_RECONSTRUCT_QUERY_KEY;
144 return <( $($struct_arg_ty,)* ) as DepNodeParams>
145 ::CAN_RECONSTRUCT_QUERY_KEY;
154 // FIXME: Make `is_anon`, `is_input`, `is_eval_always` and `has_params` properties
157 pub fn is_anon(&self) -> bool {
160 DepKind :: $variant => { contains_anon_attr!($($attr),*) }
166 pub fn is_input(&self) -> bool {
169 DepKind :: $variant => { contains_input_attr!($($attr),*) }
175 pub fn is_eval_always(&self) -> bool {
178 DepKind :: $variant => { contains_eval_always_attr!($($attr), *) }
183 #[allow(unreachable_code)]
185 pub fn has_params(&self) -> bool {
188 DepKind :: $variant => {
191 erase!($tuple_arg_ty);
197 $(erase!($struct_arg_name);)*
208 pub enum DepConstructor<$tcx> {
210 $variant $(( $tuple_arg_ty ))*
211 $({ $($struct_arg_name : $struct_arg_ty),* })*
215 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
216 RustcEncodable, RustcDecodable)]
219 pub hash: Fingerprint,
223 #[allow(unreachable_code, non_snake_case)]
225 pub fn new<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
226 dep: DepConstructor<'gcx>)
228 where 'gcx: 'a + 'tcx,
233 DepConstructor :: $variant $(( replace!(($tuple_arg_ty) with arg) ))*
234 $({ $($struct_arg_name),* })*
239 erase!($tuple_arg_ty);
240 let hash = DepNodeParams::to_fingerprint(&arg, tcx);
241 let dep_node = DepNode {
242 kind: DepKind::$variant,
246 if cfg!(debug_assertions) &&
247 !dep_node.kind.can_reconstruct_query_key() &&
248 (tcx.sess.opts.debugging_opts.incremental_info ||
249 tcx.sess.opts.debugging_opts.query_dep_graph)
251 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
252 arg.to_debug_str(tcx)
261 let tupled_args = ( $($struct_arg_name,)* );
262 let hash = DepNodeParams::to_fingerprint(&tupled_args,
264 let dep_node = DepNode {
265 kind: DepKind::$variant,
269 if cfg!(debug_assertions) &&
270 !dep_node.kind.can_reconstruct_query_key() &&
271 (tcx.sess.opts.debugging_opts.incremental_info ||
272 tcx.sess.opts.debugging_opts.query_dep_graph)
274 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
275 tupled_args.to_debug_str(tcx)
283 kind: DepKind::$variant,
284 hash: Fingerprint::ZERO,
291 /// Construct a DepNode from the given DepKind and DefPathHash. This
292 /// method will assert that the given DepKind actually requires a
293 /// single DefId/DefPathHash parameter.
295 pub fn from_def_path_hash(kind: DepKind,
296 def_path_hash: DefPathHash)
298 debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
301 hash: def_path_hash.0,
305 /// Creates a new, parameterless DepNode. This method will assert
306 /// that the DepNode corresponding to the given DepKind actually
307 /// does not require any parameters.
309 pub fn new_no_params(kind: DepKind) -> DepNode {
310 debug_assert!(!kind.has_params());
313 hash: Fingerprint::ZERO,
317 /// Extracts the DefId corresponding to this DepNode. This will work
318 /// if two conditions are met:
320 /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
321 /// 2. the item that the DefPath refers to exists in the current tcx.
323 /// Condition (1) is determined by the DepKind variant of the
324 /// DepNode. Condition (2) might not be fulfilled if a DepNode
325 /// refers to something from the previous compilation session that
326 /// has been removed.
328 pub fn extract_def_id(&self, tcx: TyCtxt<'_, '_, '_>) -> Option<DefId> {
329 if self.kind.can_reconstruct_query_key() {
330 let def_path_hash = DefPathHash(self.hash);
331 tcx.def_path_hash_to_def_id.as_ref()?
332 .get(&def_path_hash).cloned()
339 pub fn from_label_string(label: &str,
340 def_path_hash: DefPathHash)
341 -> Result<DepNode, ()> {
342 let kind = match label {
344 stringify!($variant) => DepKind::$variant,
349 if !kind.can_reconstruct_query_key() {
353 if kind.has_params() {
354 Ok(def_path_hash.to_dep_node(kind))
356 Ok(DepNode::new_no_params(kind))
361 pub fn has_label_string(label: &str) -> bool {
364 stringify!($variant) => true,
371 /// Contains variant => str representations for constructing
372 /// DepNode groups for tests.
373 #[allow(dead_code, non_upper_case_globals)]
376 pub const $variant: &str = stringify!($variant);
382 impl fmt::Debug for DepNode {
383 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
384 write!(f, "{:?}", self.kind)?;
386 if !self.kind.has_params() && !self.kind.is_anon() {
392 crate::ty::tls::with_opt(|opt_tcx| {
393 if let Some(tcx) = opt_tcx {
394 if let Some(def_id) = self.extract_def_id(tcx) {
395 write!(f, "{}", tcx.def_path_debug_str(def_id))?;
396 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*self) {
399 write!(f, "{}", self.hash)?;
402 write!(f, "{}", self.hash)?;
414 pub fn to_dep_node(self, kind: DepKind) -> DepNode {
415 DepNode::from_def_path_hash(kind, self)
421 pub fn to_dep_node(self, tcx: TyCtxt<'_, '_, '_>, kind: DepKind) -> DepNode {
422 DepNode::from_def_path_hash(kind, tcx.def_path_hash(self))
426 define_dep_nodes!( <'tcx>
427 // We use this for most things when incr. comp. is turned off.
430 // Represents the `Krate` as a whole (the `hir::Krate` value) (as
431 // distinct from the krate module). This is basically a hash of
432 // the entire krate, so if you read from `Krate` (e.g., by calling
433 // `tcx.hir().krate()`), we will have to assume that any change
434 // means that you need to be recompiled. This is because the
435 // `Krate` value gives you access to all other items. To avoid
436 // this fate, do not call `tcx.hir().krate()`; instead, prefer
437 // wrappers like `tcx.visit_all_items_in_krate()`. If there is no
438 // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
439 // access to the krate, but you must remember to add suitable
440 // edges yourself for the individual items that you read.
443 // Represents the body of a function or method. The def-id is that of the
445 [input] HirBody(DefId),
447 // Represents the HIR node with the given node-id
450 // Represents metadata from an extern crate.
451 [input] CrateMetadata(CrateNum),
453 // Represents different phases in the compiler.
454 [] RegionScopeTree(DefId),
455 [eval_always] Coherence,
456 [eval_always] CoherenceInherentImplOverlapCheck,
457 [] CoherenceCheckTrait(DefId),
458 [eval_always] PrivacyAccessLevels(CrateNum),
460 // Represents the MIR for a fn; also used as the task node for
461 // things read/modify that MIR.
462 [] MirConstQualif(DefId),
465 [] MirValidated(DefId),
466 [] MirOptimized(DefId),
467 [] MirShim { instance_def: InstanceDef<'tcx> },
470 [] BorrowCheck(DefId),
471 [] MirBorrowCheck(DefId),
472 [] UnsafetyCheckResult(DefId),
473 [] UnsafeDeriveOnReprPacked(DefId),
475 [] CheckModAttrs(DefId),
476 [] CheckModLoops(DefId),
477 [] CheckModUnstableApiUsage(DefId),
478 [] CheckModItemTypes(DefId),
479 [] CheckModPrivacy(DefId),
480 [] CheckModIntrinsics(DefId),
481 [] CheckModLiveness(DefId),
482 [] CheckModImplWf(DefId),
483 [] CollectModItemTypes(DefId),
487 [eval_always] CrateVariances,
489 // Nodes representing bits of computed IR in the tcx. Each shared
490 // table in the tcx (or elsewhere) maps to one of these
492 [] AssociatedItems(DefId),
493 [] TypeOfItem(DefId),
494 [] GenericsOfItem(DefId),
495 [] PredicatesOfItem(DefId),
496 [] ExplicitPredicatesOfItem(DefId),
497 [] PredicatesDefinedOnItem(DefId),
498 [] InferredOutlivesOf(DefId),
499 [] InferredOutlivesCrate(CrateNum),
500 [] SuperPredicatesOfItem(DefId),
501 [] TraitDefOfItem(DefId),
502 [] AdtDefOfItem(DefId),
503 [] ImplTraitRef(DefId),
504 [] ImplPolarity(DefId),
505 [] Issue33140SelfTy(DefId),
506 [] FnSignature(DefId),
507 [] CoerceUnsizedInfo(DefId),
509 [] ItemVarianceConstraints(DefId),
510 [] ItemVariances(DefId),
512 [] IsPromotableConstFn(DefId),
513 [] IsForeignItem(DefId),
514 [] TypeParamPredicates { item_id: DefId, param_id: DefId },
515 [] SizedConstraint(DefId),
516 [] DtorckConstraint(DefId),
517 [] AdtDestructor(DefId),
518 [] AssociatedItemDefIds(DefId),
519 [eval_always] InherentImpls(DefId),
520 [] TypeckBodiesKrate,
521 [] TypeckTables(DefId),
522 [] UsedTraitImports(DefId),
523 [] HasTypeckTables(DefId),
524 [] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
525 [] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
526 [] CheckMatch(DefId),
527 [] SymbolName(DefId),
528 [] InstanceSymbolName { instance: Instance<'tcx> },
529 [] SpecializationGraph(DefId),
530 [] ObjectSafety(DefId),
531 [] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
532 [] VtableMethods { trait_ref: PolyTraitRef<'tcx> },
534 [] IsCopy { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
535 [] IsSized { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
536 [] IsFreeze { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
537 [] NeedsDrop { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
538 [] Layout { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
540 // The set of impls for a given trait.
541 [] TraitImpls(DefId),
543 [input] AllLocalTraitImpls,
548 [] Environment(DefId),
549 [] DescribeDef(DefId),
551 // FIXME(mw): DefSpans are not really inputs since they are derived from
552 // HIR. But at the moment HIR hashing still contains some hacks that allow
553 // to make type debuginfo to be source location independent. Declaring
554 // DefSpan an input makes sure that changes to these are always detected
555 // regardless of HIR hashing.
556 [input] DefSpan(DefId),
557 [] LookupStability(DefId),
558 [] LookupDeprecationEntry(DefId),
559 [] ConstIsRvaluePromotableToStatic(DefId),
560 [] RvaluePromotableMap(DefId),
561 [] ImplParent(DefId),
562 [] TraitOfItem(DefId),
563 [] IsReachableNonGeneric(DefId),
564 [] IsUnreachableLocalDefinition(DefId),
565 [] IsMirAvailable(DefId),
567 [] CodegenFnAttrs(DefId),
568 [] FnArgNames(DefId),
569 [] RenderedConst(DefId),
570 [] DylibDepFormats(CrateNum),
571 [] IsPanicRuntime(CrateNum),
572 [] IsCompilerBuiltins(CrateNum),
573 [] HasGlobalAllocator(CrateNum),
574 [] HasPanicHandler(CrateNum),
575 [input] ExternCrate(DefId),
576 [eval_always] LintLevels,
577 [] Specializes { impl1: DefId, impl2: DefId },
578 [input] InScopeTraits(DefIndex),
579 [input] ModuleExports(DefId),
580 [] IsSanitizerRuntime(CrateNum),
581 [] IsProfilerRuntime(CrateNum),
582 [] GetPanicStrategy(CrateNum),
583 [] IsNoBuiltins(CrateNum),
584 [] ImplDefaultness(DefId),
585 [] CheckItemWellFormed(DefId),
586 [] CheckTraitItemWellFormed(DefId),
587 [] CheckImplItemWellFormed(DefId),
588 [] ReachableNonGenerics(CrateNum),
589 [] NativeLibraries(CrateNum),
590 [] EntryFn(CrateNum),
591 [] PluginRegistrarFn(CrateNum),
592 [] ProcMacroDeclsStatic(CrateNum),
593 [input] CrateDisambiguator(CrateNum),
594 [input] CrateHash(CrateNum),
595 [input] OriginalCrateName(CrateNum),
596 [input] ExtraFileName(CrateNum),
598 [] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
599 [] AllTraitImplementations(CrateNum),
601 [] DllimportForeignItems(CrateNum),
602 [] IsDllimportForeignItem(DefId),
603 [] IsStaticallyIncludedForeignItem(DefId),
604 [] NativeLibraryKind(DefId),
607 [] ResolveLifetimes(CrateNum),
608 [] NamedRegion(DefIndex),
609 [] IsLateBound(DefIndex),
610 [] ObjectLifetimeDefaults(DefIndex),
612 [] Visibility(DefId),
613 [input] DepKind(CrateNum),
614 [input] CrateName(CrateNum),
615 [] ItemChildren(DefId),
616 [] ExternModStmtCnum(DefId),
617 [eval_always] GetLibFeatures,
618 [] DefinedLibFeatures(CrateNum),
619 [eval_always] GetLangItems,
620 [] DefinedLangItems(CrateNum),
621 [] MissingLangItems(CrateNum),
623 [input] MissingExternCrateItem(CrateNum),
624 [input] UsedCrateSource(CrateNum),
625 [input] PostorderCnums,
627 // These queries are not expected to have inputs -- as a result, they
628 // are not good candidates for "replay" because they are essentially
629 // pure functions of their input (and hence the expectation is that
630 // no caller would be green **apart** from just these
631 // queries). Making them anonymous avoids hashing the result, which
632 // may save a bit of time.
633 [anon] EraseRegionsTy { ty: Ty<'tcx> },
635 [input] Freevars(DefId),
636 [input] MaybeUnusedTraitImport(DefId),
637 [input] MaybeUnusedExternCrates,
638 [input] NamesImportedByGlobUse(DefId),
639 [eval_always] StabilityIndex,
640 [eval_always] AllTraits,
641 [input] AllCrateNums,
642 [] ExportedSymbols(CrateNum),
643 [eval_always] CollectAndPartitionMonoItems,
644 [] IsCodegenedItem(DefId),
645 [] CodegenUnit(InternedString),
646 [] BackendOptimizationLevel(CrateNum),
647 [] CompileCodegenUnit(InternedString),
648 [input] OutputFilenames,
649 [] NormalizeProjectionTy(CanonicalProjectionGoal<'tcx>),
650 [] NormalizeTyAfterErasingRegions(ParamEnvAnd<'tcx, Ty<'tcx>>),
651 [] ImpliedOutlivesBounds(CanonicalTyGoal<'tcx>),
652 [] DropckOutlives(CanonicalTyGoal<'tcx>),
653 [] EvaluateObligation(CanonicalPredicateGoal<'tcx>),
654 [] EvaluateGoal(traits::ChalkCanonicalGoal<'tcx>),
655 [] TypeOpAscribeUserType(CanonicalTypeOpAscribeUserTypeGoal<'tcx>),
656 [] TypeOpEq(CanonicalTypeOpEqGoal<'tcx>),
657 [] TypeOpSubtype(CanonicalTypeOpSubtypeGoal<'tcx>),
658 [] TypeOpProvePredicate(CanonicalTypeOpProvePredicateGoal<'tcx>),
659 [] TypeOpNormalizeTy(CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>),
660 [] TypeOpNormalizePredicate(CanonicalTypeOpNormalizeGoal<'tcx, Predicate<'tcx>>),
661 [] TypeOpNormalizePolyFnSig(CanonicalTypeOpNormalizeGoal<'tcx, PolyFnSig<'tcx>>),
662 [] TypeOpNormalizeFnSig(CanonicalTypeOpNormalizeGoal<'tcx, FnSig<'tcx>>),
664 [] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
665 [] MethodAutoderefSteps(CanonicalTyGoal<'tcx>),
667 [input] TargetFeaturesWhitelist,
669 [] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
673 [] ProgramClausesFor(DefId),
674 [] ProgramClausesForEnv(traits::Environment<'tcx>),
675 [] WasmImportModuleMap(CrateNum),
676 [] ForeignModules(CrateNum),
678 [] UpstreamMonomorphizations(CrateNum),
679 [] UpstreamMonomorphizationsFor(DefId),
682 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
683 const CAN_RECONSTRUCT_QUERY_KEY: bool;
685 /// This method turns the parameters of a DepNodeConstructor into an opaque
686 /// Fingerprint to be used in DepNode.
687 /// Not all DepNodeParams support being turned into a Fingerprint (they
688 /// don't need to if the corresponding DepNode is anonymous).
689 fn to_fingerprint(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
690 panic!("Not implemented. Accidentally called on anonymous node?")
693 fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
694 format!("{:?}", self)
698 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
699 where T: HashStable<StableHashingContext<'a>> + fmt::Debug
701 default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
703 default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
704 let mut hcx = tcx.create_stable_hashing_context();
705 let mut hasher = StableHasher::new();
707 self.hash_stable(&mut hcx, &mut hasher);
712 default fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
713 format!("{:?}", *self)
717 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefId {
718 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
720 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
721 tcx.def_path_hash(*self).0
724 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
725 tcx.item_path_str(*self)
729 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefIndex {
730 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
732 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
733 tcx.hir().definitions().def_path_hash(*self).0
736 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
737 tcx.item_path_str(DefId::local(*self))
741 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for CrateNum {
742 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
744 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
747 index: CRATE_DEF_INDEX,
749 tcx.def_path_hash(def_id).0
752 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
753 tcx.crate_name(*self).as_str().to_string()
757 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
758 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
760 // We actually would not need to specialize the implementation of this
761 // method but it's faster to combine the hashes than to instantiate a full
762 // hashing context and stable-hashing state.
763 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
764 let (def_id_0, def_id_1) = *self;
766 let def_path_hash_0 = tcx.def_path_hash(def_id_0);
767 let def_path_hash_1 = tcx.def_path_hash(def_id_1);
769 def_path_hash_0.0.combine(def_path_hash_1.0)
772 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
773 let (def_id_0, def_id_1) = *self;
776 tcx.def_path_debug_str(def_id_0),
777 tcx.def_path_debug_str(def_id_1))
781 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for HirId {
782 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
784 // We actually would not need to specialize the implementation of this
785 // method but it's faster to combine the hashes than to instantiate a full
786 // hashing context and stable-hashing state.
787 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
793 let def_path_hash = tcx.def_path_hash(DefId::local(owner));
794 let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
796 def_path_hash.0.combine(local_id)
800 /// A "work product" corresponds to a `.o` (or other) file that we
801 /// save in between runs. These IDs do not have a `DefId` but rather
802 /// some independent path or string that persists between runs without
803 /// the need to be mapped or unmapped. (This ensures we can serialize
804 /// them even in the absence of a tcx.)
805 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
806 RustcEncodable, RustcDecodable)]
807 pub struct WorkProductId {
812 pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
813 let mut hasher = StableHasher::new();
814 cgu_name.len().hash(&mut hasher);
815 cgu_name.hash(&mut hasher);
817 hash: hasher.finish()
821 pub fn from_fingerprint(fingerprint: Fingerprint) -> WorkProductId {
828 impl_stable_hash_for!(struct crate::dep_graph::WorkProductId {