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