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::SubstsRef;
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 rustc_dep_node_append!([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),
459 [eval_always] CheckPrivateInPublic(CrateNum),
460 [eval_always] Analysis(CrateNum),
462 // Represents the MIR for a fn; also used as the task node for
463 // things read/modify that MIR.
464 [] MirConstQualif(DefId),
467 [] MirValidated(DefId),
468 [] MirOptimized(DefId),
469 [] MirShim { instance_def: InstanceDef<'tcx> },
472 [] BorrowCheck(DefId),
473 [] MirBorrowCheck(DefId),
474 [] UnsafetyCheckResult(DefId),
475 [] UnsafeDeriveOnReprPacked(DefId),
477 [] CheckModAttrs(DefId),
478 [] CheckModLoops(DefId),
479 [] CheckModUnstableApiUsage(DefId),
480 [] CheckModItemTypes(DefId),
481 [] CheckModPrivacy(DefId),
482 [] CheckModIntrinsics(DefId),
483 [] CheckModLiveness(DefId),
484 [] CheckModImplWf(DefId),
485 [] CollectModItemTypes(DefId),
489 [eval_always] CrateVariances,
491 // Nodes representing bits of computed IR in the tcx. Each shared
492 // table in the tcx (or elsewhere) maps to one of these
494 [] AssociatedItems(DefId),
495 [] ExplicitPredicatesOfItem(DefId),
496 [] PredicatesDefinedOnItem(DefId),
497 [] InferredOutlivesOf(DefId),
498 [] InferredOutlivesCrate(CrateNum),
499 [] SuperPredicatesOfItem(DefId),
500 [] TraitDefOfItem(DefId),
501 [] AdtDefOfItem(DefId),
502 [] ImplTraitRef(DefId),
503 [] ImplPolarity(DefId),
504 [] Issue33140SelfTy(DefId),
505 [] FnSignature(DefId),
506 [] CoerceUnsizedInfo(DefId),
508 [] ItemVarianceConstraints(DefId),
509 [] ItemVariances(DefId),
511 [] IsPromotableConstFn(DefId),
512 [] IsForeignItem(DefId),
513 [] TypeParamPredicates { item_id: DefId, param_id: DefId },
514 [] SizedConstraint(DefId),
515 [] DtorckConstraint(DefId),
516 [] AdtDestructor(DefId),
517 [] AssociatedItemDefIds(DefId),
518 [eval_always] InherentImpls(DefId),
519 [] TypeckBodiesKrate,
520 [] TypeckTables(DefId),
521 [] UsedTraitImports(DefId),
522 [] HasTypeckTables(DefId),
523 [] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
524 [] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
525 [] CheckMatch(DefId),
526 [] SymbolName(DefId),
527 [] InstanceSymbolName { instance: Instance<'tcx> },
528 [] SpecializationGraph(DefId),
529 [] ObjectSafety(DefId),
530 [] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
531 [] VtableMethods { trait_ref: PolyTraitRef<'tcx> },
533 [] IsCopy { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
534 [] IsSized { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
535 [] IsFreeze { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
536 [] NeedsDrop { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
537 [] Layout { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
539 // The set of impls for a given trait.
540 [] TraitImpls(DefId),
542 [input] AllLocalTraitImpls,
547 [] Environment(DefId),
548 [] DescribeDef(DefId),
550 // FIXME(mw): DefSpans are not really inputs since they are derived from
551 // HIR. But at the moment HIR hashing still contains some hacks that allow
552 // to make type debuginfo to be source location independent. Declaring
553 // DefSpan an input makes sure that changes to these are always detected
554 // regardless of HIR hashing.
555 [input] DefSpan(DefId),
556 [] LookupStability(DefId),
557 [] LookupDeprecationEntry(DefId),
558 [] ConstIsRvaluePromotableToStatic(DefId),
559 [] RvaluePromotableMap(DefId),
560 [] ImplParent(DefId),
561 [] TraitOfItem(DefId),
562 [] IsReachableNonGeneric(DefId),
563 [] IsUnreachableLocalDefinition(DefId),
564 [] IsMirAvailable(DefId),
566 [] CodegenFnAttrs(DefId),
567 [] FnArgNames(DefId),
568 [] RenderedConst(DefId),
569 [] DylibDepFormats(CrateNum),
570 [] IsCompilerBuiltins(CrateNum),
571 [] HasGlobalAllocator(CrateNum),
572 [] HasPanicHandler(CrateNum),
573 [input] ExternCrate(DefId),
574 [eval_always] LintLevels,
575 [] Specializes { impl1: DefId, impl2: DefId },
576 [input] InScopeTraits(DefIndex),
577 [input] ModuleExports(DefId),
578 [] IsSanitizerRuntime(CrateNum),
579 [] IsProfilerRuntime(CrateNum),
580 [] GetPanicStrategy(CrateNum),
581 [] IsNoBuiltins(CrateNum),
582 [] ImplDefaultness(DefId),
583 [] CheckItemWellFormed(DefId),
584 [] CheckTraitItemWellFormed(DefId),
585 [] CheckImplItemWellFormed(DefId),
586 [] ReachableNonGenerics(CrateNum),
587 [] EntryFn(CrateNum),
588 [] PluginRegistrarFn(CrateNum),
589 [] ProcMacroDeclsStatic(CrateNum),
590 [input] CrateDisambiguator(CrateNum),
591 [input] CrateHash(CrateNum),
592 [input] OriginalCrateName(CrateNum),
593 [input] ExtraFileName(CrateNum),
595 [] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
596 [] AllTraitImplementations(CrateNum),
598 [] DllimportForeignItems(CrateNum),
599 [] IsDllimportForeignItem(DefId),
600 [] IsStaticallyIncludedForeignItem(DefId),
601 [] NativeLibraryKind(DefId),
604 [] ResolveLifetimes(CrateNum),
605 [] NamedRegion(DefIndex),
606 [] IsLateBound(DefIndex),
607 [] ObjectLifetimeDefaults(DefIndex),
609 [] Visibility(DefId),
610 [input] DepKind(CrateNum),
611 [input] CrateName(CrateNum),
612 [] ItemChildren(DefId),
613 [] ExternModStmtCnum(DefId),
614 [eval_always] GetLibFeatures,
615 [] DefinedLibFeatures(CrateNum),
616 [eval_always] GetLangItems,
617 [] DefinedLangItems(CrateNum),
618 [] MissingLangItems(CrateNum),
620 [input] MissingExternCrateItem(CrateNum),
621 [input] UsedCrateSource(CrateNum),
622 [input] PostorderCnums,
624 // These queries are not expected to have inputs -- as a result, they
625 // are not good candidates for "replay" because they are essentially
626 // pure functions of their input (and hence the expectation is that
627 // no caller would be green **apart** from just these
628 // queries). Making them anonymous avoids hashing the result, which
629 // may save a bit of time.
630 [anon] EraseRegionsTy { ty: Ty<'tcx> },
632 [input] Freevars(DefId),
633 [input] MaybeUnusedTraitImport(DefId),
634 [input] MaybeUnusedExternCrates,
635 [input] NamesImportedByGlobUse(DefId),
636 [eval_always] StabilityIndex,
637 [eval_always] AllTraits,
638 [input] AllCrateNums,
639 [] ExportedSymbols(CrateNum),
640 [eval_always] CollectAndPartitionMonoItems,
641 [] IsCodegenedItem(DefId),
642 [] CodegenUnit(InternedString),
643 [] BackendOptimizationLevel(CrateNum),
644 [] CompileCodegenUnit(InternedString),
645 [input] OutputFilenames,
646 [] NormalizeProjectionTy(CanonicalProjectionGoal<'tcx>),
647 [] NormalizeTyAfterErasingRegions(ParamEnvAnd<'tcx, Ty<'tcx>>),
648 [] ImpliedOutlivesBounds(CanonicalTyGoal<'tcx>),
649 [] DropckOutlives(CanonicalTyGoal<'tcx>),
650 [] EvaluateObligation(CanonicalPredicateGoal<'tcx>),
651 [] EvaluateGoal(traits::ChalkCanonicalGoal<'tcx>),
652 [] TypeOpAscribeUserType(CanonicalTypeOpAscribeUserTypeGoal<'tcx>),
653 [] TypeOpEq(CanonicalTypeOpEqGoal<'tcx>),
654 [] TypeOpSubtype(CanonicalTypeOpSubtypeGoal<'tcx>),
655 [] TypeOpProvePredicate(CanonicalTypeOpProvePredicateGoal<'tcx>),
656 [] TypeOpNormalizeTy(CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>),
657 [] TypeOpNormalizePredicate(CanonicalTypeOpNormalizeGoal<'tcx, Predicate<'tcx>>),
658 [] TypeOpNormalizePolyFnSig(CanonicalTypeOpNormalizeGoal<'tcx, PolyFnSig<'tcx>>),
659 [] TypeOpNormalizeFnSig(CanonicalTypeOpNormalizeGoal<'tcx, FnSig<'tcx>>),
661 [] SubstituteNormalizeAndTestPredicates { key: (DefId, SubstsRef<'tcx>) },
662 [] MethodAutoderefSteps(CanonicalTyGoal<'tcx>),
664 [input] TargetFeaturesWhitelist,
666 [] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
670 [] ProgramClausesFor(DefId),
671 [] ProgramClausesForEnv(traits::Environment<'tcx>),
672 [] WasmImportModuleMap(CrateNum),
673 [] ForeignModules(CrateNum),
675 [] UpstreamMonomorphizations(CrateNum),
676 [] UpstreamMonomorphizationsFor(DefId),
679 pub trait RecoverKey<'tcx>: Sized {
680 fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option<Self>;
683 impl RecoverKey<'tcx> for CrateNum {
684 fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option<Self> {
685 dep_node.extract_def_id(tcx).map(|id| id.krate)
689 impl RecoverKey<'tcx> for DefId {
690 fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option<Self> {
691 dep_node.extract_def_id(tcx)
695 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
696 const CAN_RECONSTRUCT_QUERY_KEY: bool;
698 /// This method turns the parameters of a DepNodeConstructor into an opaque
699 /// Fingerprint to be used in DepNode.
700 /// Not all DepNodeParams support being turned into a Fingerprint (they
701 /// don't need to if the corresponding DepNode is anonymous).
702 fn to_fingerprint(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
703 panic!("Not implemented. Accidentally called on anonymous node?")
706 fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
707 format!("{:?}", self)
711 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
712 where T: HashStable<StableHashingContext<'a>> + fmt::Debug
714 default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
716 default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
717 let mut hcx = tcx.create_stable_hashing_context();
718 let mut hasher = StableHasher::new();
720 self.hash_stable(&mut hcx, &mut hasher);
725 default fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
726 format!("{:?}", *self)
730 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefId {
731 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
733 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
734 tcx.def_path_hash(*self).0
737 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
738 tcx.def_path_str(*self)
742 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefIndex {
743 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
745 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
746 tcx.hir().definitions().def_path_hash(*self).0
749 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
750 tcx.def_path_str(DefId::local(*self))
754 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for CrateNum {
755 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
757 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
760 index: CRATE_DEF_INDEX,
762 tcx.def_path_hash(def_id).0
765 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
766 tcx.crate_name(*self).as_str().to_string()
770 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
771 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
773 // We actually would not need to specialize the implementation of this
774 // method but it's faster to combine the hashes than to instantiate a full
775 // hashing context and stable-hashing state.
776 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
777 let (def_id_0, def_id_1) = *self;
779 let def_path_hash_0 = tcx.def_path_hash(def_id_0);
780 let def_path_hash_1 = tcx.def_path_hash(def_id_1);
782 def_path_hash_0.0.combine(def_path_hash_1.0)
785 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
786 let (def_id_0, def_id_1) = *self;
789 tcx.def_path_debug_str(def_id_0),
790 tcx.def_path_debug_str(def_id_1))
794 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for HirId {
795 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
797 // We actually would not need to specialize the implementation of this
798 // method but it's faster to combine the hashes than to instantiate a full
799 // hashing context and stable-hashing state.
800 fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
806 let def_path_hash = tcx.def_path_hash(DefId::local(owner));
807 let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
809 def_path_hash.0.combine(local_id)
813 /// A "work product" corresponds to a `.o` (or other) file that we
814 /// save in between runs. These IDs do not have a `DefId` but rather
815 /// some independent path or string that persists between runs without
816 /// the need to be mapped or unmapped. (This ensures we can serialize
817 /// them even in the absence of a tcx.)
818 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
819 RustcEncodable, RustcDecodable)]
820 pub struct WorkProductId {
825 pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
826 let mut hasher = StableHasher::new();
827 cgu_name.len().hash(&mut hasher);
828 cgu_name.hash(&mut hasher);
830 hash: hasher.finish()
834 pub fn from_fingerprint(fingerprint: Fingerprint) -> WorkProductId {
841 impl_stable_hash_for!(struct crate::dep_graph::WorkProductId {