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.
11 //! The data that we will serialize and deserialize.
13 use rustc::dep_graph::{DepNode, WorkProduct, WorkProductId};
14 use rustc::hir::def_id::DefIndex;
17 use super::directory::DefPathIndex;
19 /// Data for use when recompiling the **current crate**.
20 #[derive(Debug, RustcEncodable, RustcDecodable)]
21 pub struct SerializedDepGraph {
22 pub nodes: Vec<DepNode<DefPathIndex>>,
23 pub edges: Vec<SerializedEdge>,
25 /// These are hashes of two things:
26 /// - the HIR nodes in this crate
27 /// - the metadata nodes from dependent crates we use
29 /// In each case, we store a hash summarizing the contents of
30 /// those items as they were at the time we did this compilation.
31 /// In the case of HIR nodes, this hash is derived by walking the
32 /// HIR itself. In the case of metadata nodes, the hash is loaded
35 /// When we do the next compile, we will load these back up and
36 /// compare them against the hashes we see at that time, which
37 /// will tell us what has changed, either in this crate or in some
38 /// crate that we depend on.
40 /// Because they will be reloaded, we don't store the DefId (which
41 /// will be different when we next compile) related to each node,
42 /// but rather the `DefPathIndex`. This can then be retraced
43 /// to find the current def-id.
44 pub hashes: Vec<SerializedHash>,
47 pub type SerializedEdge = (DepNode<DefPathIndex>, DepNode<DefPathIndex>);
49 #[derive(Debug, RustcEncodable, RustcDecodable)]
50 pub struct SerializedHash {
51 /// node being hashed; either a Hir or MetaData variant, in
53 pub node: DepNode<DefPathIndex>,
55 /// the hash itself, computed by `calculate_item_hash`
59 #[derive(Debug, RustcEncodable, RustcDecodable)]
60 pub struct SerializedWorkProduct {
61 /// node that produced the work-product
62 pub id: Arc<WorkProductId>,
64 /// work-product data itself
65 pub work_product: WorkProduct,
68 /// Data for use when downstream crates get recompiled.
69 #[derive(Debug, RustcEncodable, RustcDecodable)]
70 pub struct SerializedMetadataHashes {
71 /// For each def-id defined in this crate that appears in the
72 /// metadata, we hash all the inputs that were used when producing
73 /// the metadata. We save this after compilation is done. Then,
74 /// when some downstream crate is being recompiled, it can compare
75 /// the hashes we saved against the hashes that it saw from
76 /// before; this will tell it which of the items in this crate
77 /// changed, which in turn implies what items in the downstream
78 /// crate need to be recompiled.
80 /// Note that we store the def-ids here. This is because we don't
81 /// reload this file when we recompile this crate, we will just
82 /// regenerate it completely with the current hashes and new def-ids.
84 /// Then downstream creates will load up their
85 /// `SerializedDepGraph`, which may contain `MetaData(X)` nodes
86 /// where `X` refers to some item in this crate. That `X` will be
87 /// a `DefPathIndex` that gets retracted to the current `DefId`
88 /// (matching the one found in this structure).
89 pub hashes: Vec<SerializedMetadataHash>,
92 /// The hash for some metadata that (when saving) will be exported
93 /// from this crate, or which (when importing) was exported by an
95 #[derive(Debug, RustcEncodable, RustcDecodable)]
96 pub struct SerializedMetadataHash {
97 pub def_index: DefIndex,
99 /// the hash itself, computed by `calculate_item_hash`