]> git.lizzy.rs Git - rust.git/blob - src/librustc_incremental/persist/data.rs
Rollup merge of #41087 - estebank:tuple-float-index, r=arielb1
[rust.git] / src / librustc_incremental / persist / data.rs
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.
4 //
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.
10
11 //! The data that we will serialize and deserialize.
12
13 use rustc::dep_graph::{DepNode, WorkProduct, WorkProductId};
14 use rustc::hir::def_id::DefIndex;
15 use rustc::ich::Fingerprint;
16 use std::sync::Arc;
17 use rustc_data_structures::fx::FxHashMap;
18
19 use super::directory::DefPathIndex;
20
21 /// Data for use when recompiling the **current crate**.
22 #[derive(Debug, RustcEncodable, RustcDecodable)]
23 pub struct SerializedDepGraph {
24     pub edges: Vec<SerializedEdgeSet>,
25
26     /// These are output nodes that have no incoming edges. We track
27     /// these separately so that when we reload all edges, we don't
28     /// lose track of these nodes.
29     pub bootstrap_outputs: Vec<DepNode<DefPathIndex>>,
30
31     /// These are hashes of two things:
32     /// - the HIR nodes in this crate
33     /// - the metadata nodes from dependent crates we use
34     ///
35     /// In each case, we store a hash summarizing the contents of
36     /// those items as they were at the time we did this compilation.
37     /// In the case of HIR nodes, this hash is derived by walking the
38     /// HIR itself. In the case of metadata nodes, the hash is loaded
39     /// from saved state.
40     ///
41     /// When we do the next compile, we will load these back up and
42     /// compare them against the hashes we see at that time, which
43     /// will tell us what has changed, either in this crate or in some
44     /// crate that we depend on.
45     ///
46     /// Because they will be reloaded, we don't store the DefId (which
47     /// will be different when we next compile) related to each node,
48     /// but rather the `DefPathIndex`. This can then be retraced
49     /// to find the current def-id.
50     pub hashes: Vec<SerializedHash>,
51 }
52
53 /// Represents a set of "reduced" dependency edge. We group the
54 /// outgoing edges from a single source together.
55 #[derive(Debug, RustcEncodable, RustcDecodable)]
56 pub struct SerializedEdgeSet {
57     pub source: DepNode<DefPathIndex>,
58     pub targets: Vec<DepNode<DefPathIndex>>
59 }
60
61 #[derive(Debug, RustcEncodable, RustcDecodable)]
62 pub struct SerializedHash {
63     /// def-id of thing being hashed
64     pub dep_node: DepNode<DefPathIndex>,
65
66     /// the hash as of previous compilation, computed by code in
67     /// `hash` module
68     pub hash: Fingerprint,
69 }
70
71 #[derive(Debug, RustcEncodable, RustcDecodable)]
72 pub struct SerializedWorkProduct {
73     /// node that produced the work-product
74     pub id: Arc<WorkProductId>,
75
76     /// work-product data itself
77     pub work_product: WorkProduct,
78 }
79
80 /// Data for use when downstream crates get recompiled.
81 #[derive(Debug, RustcEncodable, RustcDecodable)]
82 pub struct SerializedMetadataHashes {
83     /// For each def-id defined in this crate that appears in the
84     /// metadata, we hash all the inputs that were used when producing
85     /// the metadata. We save this after compilation is done. Then,
86     /// when some downstream crate is being recompiled, it can compare
87     /// the hashes we saved against the hashes that it saw from
88     /// before; this will tell it which of the items in this crate
89     /// changed, which in turn implies what items in the downstream
90     /// crate need to be recompiled.
91     ///
92     /// Note that we store the def-ids here. This is because we don't
93     /// reload this file when we recompile this crate, we will just
94     /// regenerate it completely with the current hashes and new def-ids.
95     ///
96     /// Then downstream creates will load up their
97     /// `SerializedDepGraph`, which may contain `MetaData(X)` nodes
98     /// where `X` refers to some item in this crate. That `X` will be
99     /// a `DefPathIndex` that gets retracted to the current `DefId`
100     /// (matching the one found in this structure).
101     pub hashes: Vec<SerializedMetadataHash>,
102
103     /// For each DefIndex (as it occurs in SerializedMetadataHash), this
104     /// map stores the DefPathIndex (as it occurs in DefIdDirectory), so
105     /// that we can find the new DefId for a SerializedMetadataHash in a
106     /// subsequent compilation session.
107     ///
108     /// This map is only needed for running auto-tests using the
109     /// #[rustc_metadata_dirty] and #[rustc_metadata_clean] attributes, and
110     /// is only populated if -Z query-dep-graph is specified. It will be
111     /// empty otherwise. Importing crates are perfectly happy with just having
112     /// the DefIndex.
113     pub index_map: FxHashMap<DefIndex, DefPathIndex>
114 }
115
116 /// The hash for some metadata that (when saving) will be exported
117 /// from this crate, or which (when importing) was exported by an
118 /// upstream crate.
119 #[derive(Debug, RustcEncodable, RustcDecodable)]
120 pub struct SerializedMetadataHash {
121     pub def_index: DefIndex,
122
123     /// the hash itself, computed by `calculate_item_hash`
124     pub hash: Fingerprint,
125 }