Skip to content

Commit 980143b

Browse files
committed
Pass WorkProductMap to build_dep_graph instead of FxIndexMap
Constructing an FxIndexMap is useless work as the iteration order never matters.
1 parent 4a6de8e commit 980143b

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

compiler/rustc_incremental/src/persist/load.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::errors;
44
use rustc_data_structures::memmap::Mmap;
55
use rustc_data_structures::unord::UnordMap;
6-
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
6+
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProductMap};
77
use rustc_middle::query::on_disk_cache::OnDiskCache;
88
use rustc_serialize::opaque::MemDecoder;
99
use rustc_serialize::Decodable;
@@ -16,8 +16,6 @@ use super::file_format;
1616
use super::fs::*;
1717
use super::work_product;
1818

19-
type WorkProductMap = UnordMap<WorkProductId, WorkProduct>;
20-
2119
#[derive(Debug)]
2220
/// Represents the result of an attempt to load incremental compilation data.
2321
pub enum LoadResult<T> {

compiler/rustc_incremental/src/persist/save.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::errors;
22
use rustc_data_structures::fx::FxIndexMap;
33
use rustc_data_structures::sync::join;
4-
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
4+
use rustc_middle::dep_graph::{
5+
DepGraph, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
6+
};
57
use rustc_middle::ty::TyCtxt;
68
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
79
use rustc_serialize::Encodable as RustcEncodable;
@@ -101,7 +103,7 @@ pub fn save_work_product_index(
101103
// deleted during invalidation. Some object files don't change their
102104
// content, they are just not needed anymore.
103105
let previous_work_products = dep_graph.previous_work_products();
104-
for (id, wp) in previous_work_products.iter() {
106+
for (id, wp) in previous_work_products.to_sorted_stable_ord().iter() {
105107
if !new_work_products.contains_key(id) {
106108
work_product::delete_workproduct_files(sess, wp);
107109
debug_assert!(
@@ -146,7 +148,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult
146148
pub fn build_dep_graph(
147149
sess: &Session,
148150
prev_graph: SerializedDepGraph,
149-
prev_work_products: FxIndexMap<WorkProductId, WorkProduct>,
151+
prev_work_products: WorkProductMap,
150152
) -> Option<DepGraph> {
151153
if sess.opts.incremental.is_none() {
152154
// No incremental compilation.

compiler/rustc_interface/src/queries.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::{passes, util};
55
use rustc_ast as ast;
66
use rustc_codegen_ssa::traits::CodegenBackend;
77
use rustc_codegen_ssa::CodegenResults;
8-
use rustc_data_structures::fx::FxIndexMap;
98
use rustc_data_structures::steal::Steal;
109
use rustc_data_structures::svh::Svh;
1110
use rustc_data_structures::sync::{AppendOnlyIndexVec, Lrc, OnceCell, RwLock, WorkerLocal};
@@ -162,15 +161,8 @@ impl<'tcx> Queries<'tcx> {
162161
dep_graph_future
163162
.and_then(|future| {
164163
let sess = self.session();
165-
let (prev_graph, mut prev_work_products) =
164+
let (prev_graph, prev_work_products) =
166165
sess.time("blocked_on_dep_graph_loading", || future.open().open(sess));
167-
// Convert from UnordMap to FxIndexMap by sorting
168-
let prev_work_product_ids =
169-
prev_work_products.items().map(|x| *x.0).into_sorted_stable_ord();
170-
let prev_work_products = prev_work_product_ids
171-
.into_iter()
172-
.map(|x| (x, prev_work_products.remove(&x).unwrap()))
173-
.collect::<FxIndexMap<_, _>>();
174166
rustc_incremental::build_dep_graph(sess, prev_graph, prev_work_products)
175167
})
176168
.unwrap_or_else(DepGraph::new_disabled)

compiler/rustc_middle/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod dep_node;
88

99
pub use rustc_query_system::dep_graph::{
1010
debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex,
11-
SerializedDepNodeIndex, WorkProduct, WorkProductId,
11+
SerializedDepNodeIndex, WorkProduct, WorkProductId, WorkProductMap,
1212
};
1313

1414
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};

compiler/rustc_query_system/src/dep_graph/graph.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fingerprint::Fingerprint;
2-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
2+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33
use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef};
44
use rustc_data_structures::sharded::{self, Sharded};
55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -93,7 +93,7 @@ pub struct DepGraphData<K: DepKind> {
9393
/// things available to us. If we find that they are not dirty, we
9494
/// load the path to the file storing those work-products here into
9595
/// this map. We can later look for and extract that data.
96-
previous_work_products: FxIndexMap<WorkProductId, WorkProduct>,
96+
previous_work_products: WorkProductMap,
9797

9898
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
9999

@@ -116,7 +116,7 @@ impl<K: DepKind> DepGraph<K> {
116116
pub fn new(
117117
profiler: &SelfProfilerRef,
118118
prev_graph: SerializedDepGraph<K>,
119-
prev_work_products: FxIndexMap<WorkProductId, WorkProduct>,
119+
prev_work_products: WorkProductMap,
120120
encoder: FileEncoder,
121121
record_graph: bool,
122122
record_stats: bool,
@@ -688,7 +688,7 @@ impl<K: DepKind> DepGraph<K> {
688688

689689
/// Access the map of work-products created during the cached run. Only
690690
/// used during saving of the dep-graph.
691-
pub fn previous_work_products(&self) -> &FxIndexMap<WorkProductId, WorkProduct> {
691+
pub fn previous_work_products(&self) -> &WorkProductMap {
692692
&self.data.as_ref().unwrap().previous_work_products
693693
}
694694

@@ -1051,6 +1051,8 @@ pub struct WorkProduct {
10511051
pub saved_files: UnordMap<String, String>,
10521052
}
10531053

1054+
pub type WorkProductMap = UnordMap<WorkProductId, WorkProduct>;
1055+
10541056
// Index type for `DepNodeData`'s edges.
10551057
rustc_index::newtype_index! {
10561058
struct EdgeIndex {}

compiler/rustc_query_system/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod serialized;
77
pub use dep_node::{DepKindStruct, DepNode, DepNodeParams, WorkProductId};
88
pub use graph::{
99
hash_result, DepGraph, DepGraphData, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef,
10-
WorkProduct,
10+
WorkProduct, WorkProductMap,
1111
};
1212
pub use query::DepGraphQuery;
1313
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};

0 commit comments

Comments
 (0)