1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 //! This module defines the `DepNode` type which the compiler uses to represent
13 //! nodes in the dependency graph. A `DepNode` consists of a `DepKind` (which
14 //! specifies the kind of thing it represents, like a piece of HIR, MIR, etc)
15 //! and a `Fingerprint`, a 128 bit hash value the exact meaning of which
16 //! depends on the node's `DepKind`. Together, the kind and the fingerprint
17 //! fully identify a dependency node, even across multiple compilation sessions.
18 //! In other words, the value of the fingerprint does not depend on anything
19 //! that is specific to a given compilation session, like an unpredictable
20 //! interning key (e.g. NodeId, DefId, Symbol) or the numeric value of a
21 //! pointer. The concept behind this could be compared to how git commit hashes
22 //! uniquely identify a given commit and has a few advantages:
24 //! * A `DepNode` can simply be serialized to disk and loaded in another session
25 //! without the need to do any "rebasing (like we have to do for Spans and
26 //! NodeIds) or "retracing" like we had to do for `DefId` in earlier
27 //! implementations of the dependency graph.
28 //! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
29 //! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
30 //! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
31 //! memory without any post-processing (e.g. "abomination-style" pointer
33 //! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
34 //! refer to things that do not exist anymore. In previous implementations
35 //! `DepNode` contained a `DefId`. A `DepNode` referring to something that
36 //! had been removed between the previous and the current compilation session
37 //! could not be instantiated because the current compilation session
38 //! contained no `DefId` for thing that had been removed.
40 //! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
41 //! defines the `DepKind` enum and a corresponding `DepConstructor` enum. The
42 //! `DepConstructor` enum links a `DepKind` to the parameters that are needed at
43 //! runtime in order to construct a valid `DepNode` fingerprint.
45 //! Because the macro sees what parameters a given `DepKind` requires, it can
46 //! "infer" some properties for each kind of `DepNode`:
48 //! * Whether a `DepNode` of a given kind has any parameters at all. Some
49 //! `DepNode`s, like `Krate`, represent global concepts with only one value.
50 //! * Whether it is possible, in principle, to reconstruct a query key from a
51 //! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
52 //! in which case it is possible to map the node's fingerprint back to the
53 //! `DefId` it was computed from. In other cases, too much information gets
54 //! lost during fingerprint computation.
56 //! The `DepConstructor` enum, together with `DepNode::new()` ensures that only
57 //! valid `DepNode` instances can be constructed. For example, the API does not
58 //! allow for constructing parameterless `DepNode`s with anything other
59 //! than a zeroed out fingerprint. More generally speaking, it relieves the
60 //! user of the `DepNode` API of having to know how to compute the expected
61 //! fingerprint for a given set of node parameters.
63 use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
64 use hir::map::DefPathHash;
65 use hir::{HirId, ItemLocalId};
68 use ty::{TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
69 use ty::subst::Substs;
70 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
71 use ich::StableHashingContext;
74 use syntax_pos::symbol::InternedString;
76 // erase!() just makes tokens go away. It's used to specify which macro argument
77 // is repeated (i.e. which sub-expression of the macro we are in) but don't need
78 // to actually use any of the arguments.
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:tt),* ))*
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,)* ) as DepNodeParams>
138 ::CAN_RECONSTRUCT_QUERY_KEY;
144 return <( $($struct_arg_ty,)* ) as DepNodeParams>
145 ::CAN_RECONSTRUCT_QUERY_KEY;
155 pub fn is_anon(&self) -> bool {
158 DepKind :: $variant => { contains_anon_attr!($($attr),*) }
164 pub fn is_input(&self) -> bool {
167 DepKind :: $variant => { contains_input_attr!($($attr),*) }
173 pub fn is_eval_always(&self) -> bool {
176 DepKind :: $variant => { contains_eval_always_attr!($($attr), *) }
181 #[allow(unreachable_code)]
183 pub fn has_params(&self) -> bool {
186 DepKind :: $variant => {
189 $(erase!($tuple_arg);)*
195 $(erase!($struct_arg_name);)*
206 pub enum DepConstructor<$tcx> {
208 $variant $(( $($tuple_arg),* ))*
209 $({ $($struct_arg_name : $struct_arg_ty),* })*
213 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
214 RustcEncodable, RustcDecodable)]
217 pub hash: Fingerprint,
221 #[allow(unreachable_code, non_snake_case)]
222 pub fn new<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
223 dep: DepConstructor<'gcx>)
225 where 'gcx: 'a + 'tcx,
230 DepConstructor :: $variant $(( $($tuple_arg),* ))*
231 $({ $($struct_arg_name),* })*
236 let tupled_args = ( $($tuple_arg,)* );
237 let hash = DepNodeParams::to_fingerprint(&tupled_args,
239 let dep_node = DepNode {
240 kind: DepKind::$variant,
244 if cfg!(debug_assertions) &&
245 !dep_node.kind.can_reconstruct_query_key() &&
246 (tcx.sess.opts.debugging_opts.incremental_info ||
247 tcx.sess.opts.debugging_opts.query_dep_graph)
249 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
250 tupled_args.to_debug_str(tcx)
259 let tupled_args = ( $($struct_arg_name,)* );
260 let hash = DepNodeParams::to_fingerprint(&tupled_args,
262 let dep_node = DepNode {
263 kind: DepKind::$variant,
267 if cfg!(debug_assertions) &&
268 !dep_node.kind.can_reconstruct_query_key() &&
269 (tcx.sess.opts.debugging_opts.incremental_info ||
270 tcx.sess.opts.debugging_opts.query_dep_graph)
272 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
273 tupled_args.to_debug_str(tcx)
281 kind: DepKind::$variant,
282 hash: Fingerprint::zero(),
289 /// Construct a DepNode from the given DepKind and DefPathHash. This
290 /// method will assert that the given DepKind actually requires a
291 /// single DefId/DefPathHash parameter.
293 pub fn from_def_path_hash(kind: DepKind,
294 def_path_hash: DefPathHash)
296 assert!(kind.can_reconstruct_query_key() && kind.has_params());
299 hash: def_path_hash.0,
303 /// Create a new, parameterless DepNode. This method will assert
304 /// that the DepNode corresponding to the given DepKind actually
305 /// does not require any parameters.
307 pub fn new_no_params(kind: DepKind) -> DepNode {
308 assert!(!kind.has_params());
311 hash: Fingerprint::zero(),
315 /// Extract the DefId corresponding to this DepNode. This will work
316 /// if two conditions are met:
318 /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
319 /// 2. the item that the DefPath refers to exists in the current tcx.
321 /// Condition (1) is determined by the DepKind variant of the
322 /// DepNode. Condition (2) might not be fulfilled if a DepNode
323 /// refers to something from the previous compilation session that
324 /// has been removed.
326 pub fn extract_def_id(&self, tcx: TyCtxt) -> Option<DefId> {
327 if self.kind.can_reconstruct_query_key() {
328 let def_path_hash = DefPathHash(self.hash);
329 if let Some(ref def_path_map) = tcx.def_path_hash_to_def_id.as_ref() {
330 def_path_map.get(&def_path_hash).cloned()
340 pub fn from_label_string(label: &str,
341 def_path_hash: DefPathHash)
342 -> Result<DepNode, ()> {
343 let kind = match label {
345 stringify!($variant) => DepKind::$variant,
350 if !kind.can_reconstruct_query_key() {
354 if kind.has_params() {
355 Ok(def_path_hash.to_dep_node(kind))
357 Ok(DepNode::new_no_params(kind))
362 pub fn has_label_string(label: &str) -> bool {
365 stringify!($variant) => true,
372 /// Contains variant => str representations for constructing
373 /// DepNode groups for tests.
374 #[allow(dead_code, non_upper_case_globals)]
377 pub const $variant: &'static str = stringify!($variant);
383 impl fmt::Debug for DepNode {
384 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
385 write!(f, "{:?}", self.kind)?;
387 if !self.kind.has_params() && !self.kind.is_anon() {
393 ::ty::tls::with_opt(|opt_tcx| {
394 if let Some(tcx) = opt_tcx {
395 if let Some(def_id) = self.extract_def_id(tcx) {
396 write!(f, "{}", tcx.def_path_debug_str(def_id))?;
397 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*self) {
400 write!(f, "{}", self.hash)?;
403 write!(f, "{}", self.hash)?;
415 pub fn to_dep_node(self, kind: DepKind) -> DepNode {
416 DepNode::from_def_path_hash(kind, self)
422 pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
423 DepNode::from_def_path_hash(kind, tcx.def_path_hash(self))
429 pub fn fingerprint_needed_for_crate_hash(self) -> bool {
432 DepKind::Krate => true,
438 define_dep_nodes!( <'tcx>
439 // Represents the `Krate` as a whole (the `hir::Krate` value) (as
440 // distinct from the krate module). This is basically a hash of
441 // the entire krate, so if you read from `Krate` (e.g., by calling
442 // `tcx.hir.krate()`), we will have to assume that any change
443 // means that you need to be recompiled. This is because the
444 // `Krate` value gives you access to all other items. To avoid
445 // this fate, do not call `tcx.hir.krate()`; instead, prefer
446 // wrappers like `tcx.visit_all_items_in_krate()`. If there is no
447 // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
448 // access to the krate, but you must remember to add suitable
449 // edges yourself for the individual items that you read.
452 // Represents the body of a function or method. The def-id is that of the
454 [input] HirBody(DefId),
456 // Represents the HIR node with the given node-id
459 // Represents metadata from an extern crate.
460 [input] CrateMetadata(CrateNum),
462 // Represents some artifact that we save to disk. Note that these
463 // do not have a def-id as part of their identifier.
464 [] WorkProduct(WorkProductId),
466 // Represents different phases in the compiler.
467 [] RegionScopeTree(DefId),
468 [eval_always] Coherence,
469 [eval_always] CoherenceInherentImplOverlapCheck,
470 [] CoherenceCheckTrait(DefId),
471 [eval_always] PrivacyAccessLevels(CrateNum),
473 // Represents the MIR for a fn; also used as the task node for
474 // things read/modify that MIR.
475 [] MirConstQualif(DefId),
477 [] MirValidated(DefId),
478 [] MirOptimized(DefId),
479 [] MirShim { instance_def: InstanceDef<'tcx> },
482 [] BorrowCheck(DefId),
483 [] MirBorrowCheck(DefId),
484 [] UnsafetyViolations(DefId),
488 [eval_always] CrateVariances,
490 // Nodes representing bits of computed IR in the tcx. Each shared
491 // table in the tcx (or elsewhere) maps to one of these
493 [] AssociatedItems(DefId),
494 [] TypeOfItem(DefId),
495 [] GenericsOfItem(DefId),
496 [] PredicatesOfItem(DefId),
497 [] InferredOutlivesOf(DefId),
498 [] SuperPredicatesOfItem(DefId),
499 [] TraitDefOfItem(DefId),
500 [] AdtDefOfItem(DefId),
501 [] IsDefaultImpl(DefId),
502 [] ImplTraitRef(DefId),
503 [] ImplPolarity(DefId),
504 [] ClosureKind(DefId),
505 [] FnSignature(DefId),
506 [] GenSignature(DefId),
507 [] CoerceUnsizedInfo(DefId),
509 [] ItemVarianceConstraints(DefId),
510 [] ItemVariances(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, (DefId, &'tcx Substs<'tcx>)> },
524 [] SymbolName(DefId),
525 [] InstanceSymbolName { instance: Instance<'tcx> },
526 [] SpecializationGraph(DefId),
527 [] ObjectSafety(DefId),
528 [] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
529 [] VtableMethods { trait_ref: PolyTraitRef<'tcx> },
531 [] IsCopy { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
532 [] IsSized { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
533 [] IsFreeze { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
534 [] NeedsDrop { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
535 [] Layout { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
537 // The set of impls for a given trait.
538 [] TraitImpls(DefId),
540 [] AllLocalTraitImpls,
542 // Trait selection cache is a little funny. Given a trait
543 // reference like `Foo: SomeTrait<Bar>`, there could be
544 // arbitrarily many def-ids to map on in there (e.g., `Foo`,
545 // `SomeTrait`, `Bar`). We could have a vector of them, but it
546 // requires heap-allocation, and trait sel in general can be a
547 // surprisingly hot path. So instead we pick two def-ids: the
548 // trait def-id, and the first def-id in the input types. If there
549 // is no def-id in the input types, then we use the trait def-id
550 // again. So for example:
552 // - `i32: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
553 // - `u32: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
554 // - `Clone: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
555 // - `Vec<i32>: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Vec }`
556 // - `String: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: String }`
557 // - `Foo: Trait<Bar>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
558 // - `Foo: Trait<i32>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
559 // - `(Foo, Bar): Trait` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
560 // - `i32: Trait<Foo>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
562 // You can see that we map many trait refs to the same
563 // trait-select node. This is not a problem, it just means
564 // imprecision in our dep-graph tracking. The important thing is
565 // that for any given trait-ref, we always map to the **same**
566 // trait-select node.
570 [] DescribeDef(DefId),
572 [] LookupStability(DefId),
573 [] LookupDeprecationEntry(DefId),
574 [] ItemBodyNestedBodies(DefId),
575 [] ConstIsRvaluePromotableToStatic(DefId),
576 [] RvaluePromotableMap(DefId),
577 [] ImplParent(DefId),
578 [] TraitOfItem(DefId),
579 [] IsExportedSymbol(DefId),
580 [] IsMirAvailable(DefId),
582 [] FnArgNames(DefId),
583 [] DylibDepFormats(CrateNum),
584 [] IsPanicRuntime(CrateNum),
585 [] IsCompilerBuiltins(CrateNum),
586 [] HasGlobalAllocator(CrateNum),
587 [] ExternCrate(DefId),
588 [eval_always] LintLevels,
589 [] Specializes { impl1: DefId, impl2: DefId },
590 [input] InScopeTraits(DefIndex),
591 [] ModuleExports(DefId),
592 [] IsSanitizerRuntime(CrateNum),
593 [] IsProfilerRuntime(CrateNum),
594 [] GetPanicStrategy(CrateNum),
595 [] IsNoBuiltins(CrateNum),
596 [] ImplDefaultness(DefId),
597 [] ExportedSymbolIds(CrateNum),
598 [] NativeLibraries(CrateNum),
599 [] PluginRegistrarFn(CrateNum),
600 [] DeriveRegistrarFn(CrateNum),
601 [] CrateDisambiguator(CrateNum),
602 [] CrateHash(CrateNum),
603 [] OriginalCrateName(CrateNum),
605 [] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
606 [] AllTraitImplementations(CrateNum),
608 [] IsDllimportForeignItem(DefId),
609 [] IsStaticallyIncludedForeignItem(DefId),
610 [] NativeLibraryKind(DefId),
613 [] NamedRegion(DefIndex),
614 [] IsLateBound(DefIndex),
615 [] ObjectLifetimeDefaults(DefIndex),
617 [] Visibility(DefId),
618 [] DepKind(CrateNum),
619 [] CrateName(CrateNum),
620 [] ItemChildren(DefId),
621 [] ExternModStmtCnum(DefId),
623 [] DefinedLangItems(CrateNum),
624 [] MissingLangItems(CrateNum),
625 [] ExternConstBody(DefId),
627 [] MissingExternCrateItem(CrateNum),
628 [] UsedCrateSource(CrateNum),
630 [] HasCloneClosures(CrateNum),
631 [] HasCopyClosures(CrateNum),
633 // This query is not expected to have inputs -- as a result, it's
634 // not a good candidate for "replay" because it's essentially a
635 // pure function of its input (and hence the expectation is that
636 // no caller would be green **apart** from just this
637 // query). Making it anonymous avoids hashing the result, which
638 // may save a bit of time.
639 [anon] EraseRegionsTy { ty: Ty<'tcx> },
642 [] MaybeUnusedTraitImport(DefId),
643 [] MaybeUnusedExternCrates,
646 [] ExportedSymbols(CrateNum),
647 [eval_always] CollectAndPartitionTranslationItems,
648 [] ExportName(DefId),
649 [] ContainsExternIndicator(DefId),
650 [] IsTranslatedFunction(DefId),
651 [] CodegenUnit(InternedString),
652 [] CompileCodegenUnit(InternedString),
655 // We use this for most things when incr. comp. is turned off.
659 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
660 const CAN_RECONSTRUCT_QUERY_KEY: bool;
662 /// This method turns the parameters of a DepNodeConstructor into an opaque
663 /// Fingerprint to be used in DepNode.
664 /// Not all DepNodeParams support being turned into a Fingerprint (they
665 /// don't need to if the corresponding DepNode is anonymous).
666 fn to_fingerprint(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
667 panic!("Not implemented. Accidentally called on anonymous node?")
670 fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
671 format!("{:?}", self)
675 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
676 where T: HashStable<StableHashingContext<'gcx>> + fmt::Debug
678 default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
680 default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
681 let mut hcx = tcx.create_stable_hashing_context();
682 let mut hasher = StableHasher::new();
684 self.hash_stable(&mut hcx, &mut hasher);
689 default fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
690 format!("{:?}", *self)
694 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
695 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
697 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
698 tcx.def_path_hash(self.0).0
701 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
702 tcx.item_path_str(self.0)
706 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
707 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
709 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
710 tcx.hir.definitions().def_path_hash(self.0).0
713 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
714 tcx.item_path_str(DefId::local(self.0))
718 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (CrateNum,) {
719 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
721 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
724 index: CRATE_DEF_INDEX,
726 tcx.def_path_hash(def_id).0
729 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
730 tcx.crate_name(self.0).as_str().to_string()
734 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
735 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
737 // We actually would not need to specialize the implementation of this
738 // method but it's faster to combine the hashes than to instantiate a full
739 // hashing context and stable-hashing state.
740 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
741 let (def_id_0, def_id_1) = *self;
743 let def_path_hash_0 = tcx.def_path_hash(def_id_0);
744 let def_path_hash_1 = tcx.def_path_hash(def_id_1);
746 def_path_hash_0.0.combine(def_path_hash_1.0)
749 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
750 let (def_id_0, def_id_1) = *self;
753 tcx.def_path_debug_str(def_id_0),
754 tcx.def_path_debug_str(def_id_1))
758 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (HirId,) {
759 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
761 // We actually would not need to specialize the implementation of this
762 // method but it's faster to combine the hashes than to instantiate a full
763 // hashing context and stable-hashing state.
764 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
767 local_id: ItemLocalId(local_id),
770 let def_path_hash = tcx.def_path_hash(DefId::local(owner));
771 let local_id = Fingerprint::from_smaller_hash(local_id as u64);
773 def_path_hash.0.combine(local_id)
777 /// A "work product" corresponds to a `.o` (or other) file that we
778 /// save in between runs. These ids do not have a DefId but rather
779 /// some independent path or string that persists between runs without
780 /// the need to be mapped or unmapped. (This ensures we can serialize
781 /// them even in the absence of a tcx.)
782 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
783 RustcEncodable, RustcDecodable)]
784 pub struct WorkProductId {
789 pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
790 let mut hasher = StableHasher::new();
791 cgu_name.len().hash(&mut hasher);
792 cgu_name.hash(&mut hasher);
794 hash: hasher.finish()
798 pub fn from_fingerprint(fingerprint: Fingerprint) -> WorkProductId {
804 pub fn to_dep_node(self) -> DepNode {
806 kind: DepKind::WorkProduct,
812 impl_stable_hash_for!(struct ::dep_graph::WorkProductId {