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! contains_anon_attr {
94 ($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
97 macro_rules! contains_input_attr {
98 ($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
101 macro_rules! define_dep_nodes {
105 $variant:ident $(( $($tuple_arg:tt),* ))*
106 $({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
109 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
110 RustcEncodable, RustcDecodable)]
116 #[allow(unreachable_code)]
118 pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
121 DepKind :: $variant => {
122 if contains_anon_attr!($($attr),*) {
128 return <( $($tuple_arg,)* ) as DepNodeParams>
129 ::CAN_RECONSTRUCT_QUERY_KEY;
135 return <( $($struct_arg_ty,)* ) as DepNodeParams>
136 ::CAN_RECONSTRUCT_QUERY_KEY;
146 pub fn is_anon(&self) -> bool {
149 DepKind :: $variant => { contains_anon_attr!($($attr),*) }
155 pub fn is_input(&self) -> bool {
158 DepKind :: $variant => { contains_input_attr!($($attr),*) }
163 #[allow(unreachable_code)]
165 pub fn has_params(&self) -> bool {
168 DepKind :: $variant => {
171 $(erase!($tuple_arg);)*
177 $(erase!($struct_arg_name);)*
188 pub enum DepConstructor<$tcx> {
190 $variant $(( $($tuple_arg),* ))*
191 $({ $($struct_arg_name : $struct_arg_ty),* })*
195 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
196 RustcEncodable, RustcDecodable)]
199 pub hash: Fingerprint,
203 #[allow(unreachable_code, non_snake_case)]
204 pub fn new<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
205 dep: DepConstructor<'gcx>)
207 where 'gcx: 'a + 'tcx,
212 DepConstructor :: $variant $(( $($tuple_arg),* ))*
213 $({ $($struct_arg_name),* })*
218 let tupled_args = ( $($tuple_arg,)* );
219 let hash = DepNodeParams::to_fingerprint(&tupled_args,
221 let dep_node = DepNode {
222 kind: DepKind::$variant,
226 if cfg!(debug_assertions) &&
227 !dep_node.kind.can_reconstruct_query_key() &&
228 (tcx.sess.opts.debugging_opts.incremental_info ||
229 tcx.sess.opts.debugging_opts.query_dep_graph)
231 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
232 tupled_args.to_debug_str(tcx)
241 let tupled_args = ( $($struct_arg_name,)* );
242 let hash = DepNodeParams::to_fingerprint(&tupled_args,
244 let dep_node = DepNode {
245 kind: DepKind::$variant,
249 if cfg!(debug_assertions) &&
250 !dep_node.kind.can_reconstruct_query_key() &&
251 (tcx.sess.opts.debugging_opts.incremental_info ||
252 tcx.sess.opts.debugging_opts.query_dep_graph)
254 tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
255 tupled_args.to_debug_str(tcx)
263 kind: DepKind::$variant,
264 hash: Fingerprint::zero(),
271 /// Construct a DepNode from the given DepKind and DefPathHash. This
272 /// method will assert that the given DepKind actually requires a
273 /// single DefId/DefPathHash parameter.
275 pub fn from_def_path_hash(kind: DepKind,
276 def_path_hash: DefPathHash)
278 assert!(kind.can_reconstruct_query_key() && kind.has_params());
281 hash: def_path_hash.0,
285 /// Create a new, parameterless DepNode. This method will assert
286 /// that the DepNode corresponding to the given DepKind actually
287 /// does not require any parameters.
289 pub fn new_no_params(kind: DepKind) -> DepNode {
290 assert!(!kind.has_params());
293 hash: Fingerprint::zero(),
297 /// Extract the DefId corresponding to this DepNode. This will work
298 /// if two conditions are met:
300 /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
301 /// 2. the item that the DefPath refers to exists in the current tcx.
303 /// Condition (1) is determined by the DepKind variant of the
304 /// DepNode. Condition (2) might not be fulfilled if a DepNode
305 /// refers to something from the previous compilation session that
306 /// has been removed.
308 pub fn extract_def_id(&self, tcx: TyCtxt) -> Option<DefId> {
309 if self.kind.can_reconstruct_query_key() {
310 let def_path_hash = DefPathHash(self.hash);
311 if let Some(ref def_path_map) = tcx.def_path_hash_to_def_id.as_ref() {
312 def_path_map.get(&def_path_hash).cloned()
322 pub fn from_label_string(label: &str,
323 def_path_hash: DefPathHash)
324 -> Result<DepNode, ()> {
325 let kind = match label {
327 stringify!($variant) => DepKind::$variant,
332 if !kind.can_reconstruct_query_key() {
336 if kind.has_params() {
337 Ok(def_path_hash.to_dep_node(kind))
339 Ok(DepNode::new_no_params(kind))
344 pub fn has_label_string(label: &str) -> bool {
347 stringify!($variant) => true,
354 /// Contains variant => str representations for constructing
355 /// DepNode groups for tests.
356 #[allow(dead_code, non_upper_case_globals)]
359 pub const $variant: &'static str = stringify!($variant);
365 impl fmt::Debug for DepNode {
366 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
367 write!(f, "{:?}", self.kind)?;
369 if !self.kind.has_params() && !self.kind.is_anon() {
375 ::ty::tls::with_opt(|opt_tcx| {
376 if let Some(tcx) = opt_tcx {
377 if let Some(def_id) = self.extract_def_id(tcx) {
378 write!(f, "{}", tcx.def_path_debug_str(def_id))?;
379 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*self) {
382 write!(f, "{}", self.hash)?;
385 write!(f, "{}", self.hash)?;
397 pub fn to_dep_node(self, kind: DepKind) -> DepNode {
398 DepNode::from_def_path_hash(kind, self)
404 pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
405 DepNode::from_def_path_hash(kind, tcx.def_path_hash(self))
411 pub fn fingerprint_needed_for_crate_hash(self) -> bool {
414 DepKind::Krate => true,
420 define_dep_nodes!( <'tcx>
421 // Represents the `Krate` as a whole (the `hir::Krate` value) (as
422 // distinct from the krate module). This is basically a hash of
423 // the entire krate, so if you read from `Krate` (e.g., by calling
424 // `tcx.hir.krate()`), we will have to assume that any change
425 // means that you need to be recompiled. This is because the
426 // `Krate` value gives you access to all other items. To avoid
427 // this fate, do not call `tcx.hir.krate()`; instead, prefer
428 // wrappers like `tcx.visit_all_items_in_krate()`. If there is no
429 // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
430 // access to the krate, but you must remember to add suitable
431 // edges yourself for the individual items that you read.
434 // Represents the body of a function or method. The def-id is that of the
436 [input] HirBody(DefId),
438 // Represents the HIR node with the given node-id
441 // Represents metadata from an extern crate.
442 [input] CrateMetadata(CrateNum),
444 // Represents some artifact that we save to disk. Note that these
445 // do not have a def-id as part of their identifier.
446 [] WorkProduct(WorkProductId),
448 // Represents different phases in the compiler.
449 [] RegionScopeTree(DefId),
451 [] CoherenceInherentImplOverlapCheck,
452 [] CoherenceCheckTrait(DefId),
453 [] PrivacyAccessLevels(CrateNum),
455 // Represents the MIR for a fn; also used as the task node for
456 // things read/modify that MIR.
457 [] MirConstQualif(DefId),
459 [] MirValidated(DefId),
460 [] MirOptimized(DefId),
461 [] MirShim { instance_def: InstanceDef<'tcx> },
464 [] BorrowCheck(DefId),
465 [] MirBorrowCheck(DefId),
466 [] UnsafetyViolations(DefId),
472 // Nodes representing bits of computed IR in the tcx. Each shared
473 // table in the tcx (or elsewhere) maps to one of these
475 [] AssociatedItems(DefId),
476 [] TypeOfItem(DefId),
477 [] GenericsOfItem(DefId),
478 [] PredicatesOfItem(DefId),
479 [] InferredOutlivesOf(DefId),
480 [] SuperPredicatesOfItem(DefId),
481 [] TraitDefOfItem(DefId),
482 [] AdtDefOfItem(DefId),
483 [] IsDefaultImpl(DefId),
484 [] ImplTraitRef(DefId),
485 [] ImplPolarity(DefId),
486 [] ClosureKind(DefId),
487 [] FnSignature(DefId),
488 [] GenSignature(DefId),
489 [] CoerceUnsizedInfo(DefId),
491 [] ItemVarianceConstraints(DefId),
492 [] ItemVariances(DefId),
494 [] IsForeignItem(DefId),
495 [] TypeParamPredicates { item_id: DefId, param_id: DefId },
496 [] SizedConstraint(DefId),
497 [] DtorckConstraint(DefId),
498 [] AdtDestructor(DefId),
499 [] AssociatedItemDefIds(DefId),
500 [] InherentImpls(DefId),
501 [] TypeckBodiesKrate,
502 [] TypeckTables(DefId),
503 [] HasTypeckTables(DefId),
504 [] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
505 [] SymbolName(DefId),
506 [] InstanceSymbolName { instance: Instance<'tcx> },
507 [] SpecializationGraph(DefId),
508 [] ObjectSafety(DefId),
509 [] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
510 [] VtableMethods { trait_ref: PolyTraitRef<'tcx> },
512 [] IsCopy { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
513 [] IsSized { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
514 [] IsFreeze { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
515 [] NeedsDrop { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
516 [] Layout { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
518 // The set of impls for a given trait.
519 [] TraitImpls(DefId),
521 [] AllLocalTraitImpls,
523 // Trait selection cache is a little funny. Given a trait
524 // reference like `Foo: SomeTrait<Bar>`, there could be
525 // arbitrarily many def-ids to map on in there (e.g., `Foo`,
526 // `SomeTrait`, `Bar`). We could have a vector of them, but it
527 // requires heap-allocation, and trait sel in general can be a
528 // surprisingly hot path. So instead we pick two def-ids: the
529 // trait def-id, and the first def-id in the input types. If there
530 // is no def-id in the input types, then we use the trait def-id
531 // again. So for example:
533 // - `i32: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
534 // - `u32: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
535 // - `Clone: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Clone }`
536 // - `Vec<i32>: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: Vec }`
537 // - `String: Clone` -> `TraitSelect { trait_def_id: Clone, self_def_id: String }`
538 // - `Foo: Trait<Bar>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
539 // - `Foo: Trait<i32>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
540 // - `(Foo, Bar): Trait` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
541 // - `i32: Trait<Foo>` -> `TraitSelect { trait_def_id: Trait, self_def_id: Foo }`
543 // You can see that we map many trait refs to the same
544 // trait-select node. This is not a problem, it just means
545 // imprecision in our dep-graph tracking. The important thing is
546 // that for any given trait-ref, we always map to the **same**
547 // trait-select node.
551 [] DescribeDef(DefId),
553 [] LookupStability(DefId),
554 [] LookupDeprecationEntry(DefId),
555 [] ItemBodyNestedBodies(DefId),
556 [] ConstIsRvaluePromotableToStatic(DefId),
557 [] RvaluePromotableMap(DefId),
558 [] ImplParent(DefId),
559 [] TraitOfItem(DefId),
560 [] IsExportedSymbol(DefId),
561 [] IsMirAvailable(DefId),
563 [] FnArgNames(DefId),
564 [] DylibDepFormats(CrateNum),
565 [] IsPanicRuntime(CrateNum),
566 [] IsCompilerBuiltins(CrateNum),
567 [] HasGlobalAllocator(CrateNum),
568 [] ExternCrate(DefId),
570 [] Specializes { impl1: DefId, impl2: DefId },
571 [input] InScopeTraits(DefIndex),
572 [] ModuleExports(DefId),
573 [] IsSanitizerRuntime(CrateNum),
574 [] IsProfilerRuntime(CrateNum),
575 [] GetPanicStrategy(CrateNum),
576 [] IsNoBuiltins(CrateNum),
577 [] ImplDefaultness(DefId),
578 [] ExportedSymbolIds(CrateNum),
579 [] NativeLibraries(CrateNum),
580 [] PluginRegistrarFn(CrateNum),
581 [] DeriveRegistrarFn(CrateNum),
582 [] CrateDisambiguator(CrateNum),
583 [] CrateHash(CrateNum),
584 [] OriginalCrateName(CrateNum),
586 [] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
587 [] AllTraitImplementations(CrateNum),
589 [] IsDllimportForeignItem(DefId),
590 [] IsStaticallyIncludedForeignItem(DefId),
591 [] NativeLibraryKind(DefId),
594 [] NamedRegion(DefIndex),
595 [] IsLateBound(DefIndex),
596 [] ObjectLifetimeDefaults(DefIndex),
598 [] Visibility(DefId),
599 [] DepKind(CrateNum),
600 [] CrateName(CrateNum),
601 [] ItemChildren(DefId),
602 [] ExternModStmtCnum(DefId),
604 [] DefinedLangItems(CrateNum),
605 [] MissingLangItems(CrateNum),
606 [] ExternConstBody(DefId),
608 [] MissingExternCrateItem(CrateNum),
609 [] UsedCrateSource(CrateNum),
611 [] HasCloneClosures(CrateNum),
612 [] HasCopyClosures(CrateNum),
613 [] EraseRegionsTy { ty: Ty<'tcx> },
616 [] MaybeUnusedTraitImport(DefId),
617 [] MaybeUnusedExternCrates,
620 [] ExportedSymbols(CrateNum),
621 [] CollectAndPartitionTranslationItems,
622 [] ExportName(DefId),
623 [] ContainsExternIndicator(DefId),
624 [] IsTranslatedFunction(DefId),
625 [] CodegenUnit(InternedString),
626 [] CompileCodegenUnit(InternedString),
629 // We use this for most things when incr. comp. is turned off.
633 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
634 const CAN_RECONSTRUCT_QUERY_KEY: bool;
636 /// This method turns the parameters of a DepNodeConstructor into an opaque
637 /// Fingerprint to be used in DepNode.
638 /// Not all DepNodeParams support being turned into a Fingerprint (they
639 /// don't need to if the corresponding DepNode is anonymous).
640 fn to_fingerprint(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
641 panic!("Not implemented. Accidentally called on anonymous node?")
644 fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
645 format!("{:?}", self)
649 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
650 where T: HashStable<StableHashingContext<'gcx>> + fmt::Debug
652 default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
654 default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
655 let mut hcx = tcx.create_stable_hashing_context();
656 let mut hasher = StableHasher::new();
658 self.hash_stable(&mut hcx, &mut hasher);
663 default fn to_debug_str(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> String {
664 format!("{:?}", *self)
668 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
669 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
671 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
672 tcx.def_path_hash(self.0).0
675 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
676 tcx.item_path_str(self.0)
680 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
681 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
683 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
684 tcx.hir.definitions().def_path_hash(self.0).0
687 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
688 tcx.item_path_str(DefId::local(self.0))
692 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (CrateNum,) {
693 const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
695 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
698 index: CRATE_DEF_INDEX,
700 tcx.def_path_hash(def_id).0
703 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
704 tcx.crate_name(self.0).as_str().to_string()
708 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
709 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
711 // We actually would not need to specialize the implementation of this
712 // method but it's faster to combine the hashes than to instantiate a full
713 // hashing context and stable-hashing state.
714 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
715 let (def_id_0, def_id_1) = *self;
717 let def_path_hash_0 = tcx.def_path_hash(def_id_0);
718 let def_path_hash_1 = tcx.def_path_hash(def_id_1);
720 def_path_hash_0.0.combine(def_path_hash_1.0)
723 fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
724 let (def_id_0, def_id_1) = *self;
727 tcx.def_path_debug_str(def_id_0),
728 tcx.def_path_debug_str(def_id_1))
732 impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (HirId,) {
733 const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
735 // We actually would not need to specialize the implementation of this
736 // method but it's faster to combine the hashes than to instantiate a full
737 // hashing context and stable-hashing state.
738 fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
741 local_id: ItemLocalId(local_id),
744 let def_path_hash = tcx.def_path_hash(DefId::local(owner));
745 let local_id = Fingerprint::from_smaller_hash(local_id as u64);
747 def_path_hash.0.combine(local_id)
751 /// A "work product" corresponds to a `.o` (or other) file that we
752 /// save in between runs. These ids do not have a DefId but rather
753 /// some independent path or string that persists between runs without
754 /// the need to be mapped or unmapped. (This ensures we can serialize
755 /// them even in the absence of a tcx.)
756 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
757 RustcEncodable, RustcDecodable)]
758 pub struct WorkProductId {
763 pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
764 let mut hasher = StableHasher::new();
765 cgu_name.len().hash(&mut hasher);
766 cgu_name.hash(&mut hasher);
768 hash: hasher.finish()
772 pub fn from_fingerprint(fingerprint: Fingerprint) -> WorkProductId {
778 pub fn to_dep_node(self) -> DepNode {
780 kind: DepKind::WorkProduct,
786 impl_stable_hash_for!(struct ::dep_graph::WorkProductId {