Skip to content

Commit 89a8f2c

Browse files
committed
Remove shared access to DepGraph::work_products
1 parent 41707d8 commit 89a8f2c

File tree

6 files changed

+39
-58
lines changed

6 files changed

+39
-58
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1515
use rustc_data_structures::small_vec::SmallVec;
16-
use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock};
16+
use rustc_data_structures::sync::{Lrc, Lock};
1717
use std::env;
1818
use std::hash::Hash;
1919
use ty::{self, TyCtxt};
@@ -80,9 +80,6 @@ struct DepGraphData {
8080
/// this map. We can later look for and extract that data.
8181
previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
8282

83-
/// Work-products that we generate in this run.
84-
work_products: RwLock<FxHashMap<WorkProductId, WorkProduct>>,
85-
8683
dep_node_debug: Lock<FxHashMap<DepNode, String>>,
8784

8885
// Used for testing, only populated when -Zquery-dep-graph is specified.
@@ -103,7 +100,6 @@ impl DepGraph {
103100
DepGraph {
104101
data: Some(Lrc::new(DepGraphData {
105102
previous_work_products: prev_work_products,
106-
work_products: RwLock::new(FxHashMap()),
107103
dep_node_debug: Lock::new(FxHashMap()),
108104
current: Lock::new(CurrentDepGraph::new()),
109105
previous: prev_graph,
@@ -462,19 +458,6 @@ impl DepGraph {
462458
self.data.as_ref().unwrap().previous.node_to_index(dep_node)
463459
}
464460

465-
/// Indicates that we created the given work-product in this run
466-
/// for `v`. This record will be preserved and loaded in the next
467-
/// run.
468-
pub fn insert_work_product(&self, v: &WorkProductId, data: WorkProduct) {
469-
debug!("insert_work_product({:?}, {:?})", v, data);
470-
self.data
471-
.as_ref()
472-
.unwrap()
473-
.work_products
474-
.borrow_mut()
475-
.insert(v.clone(), data);
476-
}
477-
478461
/// Check whether a previous work product exists for `v` and, if
479462
/// so, return the path that leads to it. Used to skip doing work.
480463
pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
@@ -485,12 +468,6 @@ impl DepGraph {
485468
})
486469
}
487470

488-
/// Access the map of work-products created during this run. Only
489-
/// used during saving of the dep-graph.
490-
pub fn work_products(&self) -> ReadGuard<FxHashMap<WorkProductId, WorkProduct>> {
491-
self.data.as_ref().unwrap().work_products.borrow()
492-
}
493-
494471
/// Access the map of work-products created during the cached run. Only
495472
/// used during saving of the dep-graph.
496473
pub fn previous_work_products(&self) -> &FxHashMap<WorkProductId, WorkProduct> {

src/librustc_incremental/persist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ pub use self::load::load_query_result_cache;
3030
pub use self::load::LoadResult;
3131
pub use self::save::save_dep_graph;
3232
pub use self::save::save_work_products;
33-
pub use self::work_product::save_trans_partition;
33+
pub use self::work_product::create_trans_partition;
3434
pub use self::work_product::delete_workproduct_files;

src/librustc_incremental/persist/save.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::dep_graph::{DepGraph, DepKind};
11+
use rustc::dep_graph::{DepGraph, DepKind, WorkProduct, WorkProductId};
1212
use rustc::session::Session;
1313
use rustc::ty::TyCtxt;
1414
use rustc::util::common::time;
@@ -55,22 +55,22 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
5555
})
5656
}
5757

58-
pub fn save_work_products(sess: &Session, dep_graph: &DepGraph) {
58+
pub fn save_work_products(sess: &Session,
59+
dep_graph: &DepGraph,
60+
new_work_products: FxHashMap<WorkProductId, WorkProduct>) {
5961
if sess.opts.incremental.is_none() {
6062
return;
6163
}
6264

6365
debug!("save_work_products()");
6466
dep_graph.assert_ignored();
6567
let path = work_products_path(sess);
66-
save_in(sess, path, |e| encode_work_products(dep_graph, e));
68+
save_in(sess, path, |e| encode_work_products(&new_work_products, e));
6769

6870
// We also need to clean out old work-products, as not all of them are
6971
// deleted during invalidation. Some object files don't change their
7072
// content, they are just not needed anymore.
71-
let new_work_products = dep_graph.work_products();
7273
let previous_work_products = dep_graph.previous_work_products();
73-
7474
for (id, wp) in previous_work_products.iter() {
7575
if !new_work_products.contains_key(id) {
7676
work_product::delete_workproduct_files(sess, wp);
@@ -234,10 +234,9 @@ fn encode_dep_graph(tcx: TyCtxt,
234234
Ok(())
235235
}
236236

237-
fn encode_work_products(dep_graph: &DepGraph,
237+
fn encode_work_products(work_products: &FxHashMap<WorkProductId, WorkProduct>,
238238
encoder: &mut Encoder) -> io::Result<()> {
239-
let work_products: Vec<_> = dep_graph
240-
.work_products()
239+
let serialized_products: Vec<_> = work_products
241240
.iter()
242241
.map(|(id, work_product)| {
243242
SerializedWorkProduct {
@@ -247,7 +246,7 @@ fn encode_work_products(dep_graph: &DepGraph,
247246
})
248247
.collect();
249248

250-
work_products.encode(encoder)
249+
serialized_products.encode(encoder)
251250
}
252251

253252
fn encode_query_cache(tcx: TyCtxt,

src/librustc_incremental/persist/work_product.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
//! This module contains files for saving intermediate work-products.
1212
1313
use persist::fs::*;
14-
use rustc::dep_graph::{WorkProduct, WorkProductId, DepGraph, WorkProductFileKind};
14+
use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
1515
use rustc::session::Session;
1616
use rustc::util::fs::link_or_copy;
1717
use std::path::PathBuf;
1818
use std::fs as std_fs;
1919

20-
pub fn save_trans_partition(sess: &Session,
21-
dep_graph: &DepGraph,
22-
cgu_name: &str,
23-
files: &[(WorkProductFileKind, PathBuf)]) {
24-
debug!("save_trans_partition({:?},{:?})",
20+
pub fn create_trans_partition(sess: &Session,
21+
cgu_name: &str,
22+
files: &[(WorkProductFileKind, PathBuf)])
23+
-> Option<(WorkProductId, WorkProduct)> {
24+
debug!("create_trans_partition({:?},{:?})",
2525
cgu_name,
2626
files);
2727
if sess.opts.incremental.is_none() {
28-
return
28+
return None
2929
}
3030
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
3131

@@ -53,16 +53,16 @@ pub fn save_trans_partition(sess: &Session,
5353
})
5454
.collect();
5555
let saved_files = match saved_files {
56+
None => return None,
5657
Some(v) => v,
57-
None => return,
5858
};
5959

6060
let work_product = WorkProduct {
6161
cgu_name: cgu_name.to_string(),
6262
saved_files,
6363
};
6464

65-
dep_graph.insert_work_product(&work_product_id, work_product);
65+
Some((work_product_id, work_product))
6666
}
6767

6868
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {

src/librustc_trans/back/write.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use back::linker::LinkerInfo;
1717
use back::symbol_export::ExportedSymbols;
1818
use base;
1919
use consts;
20-
use rustc_incremental::{save_trans_partition, in_incr_comp_dir};
21-
use rustc::dep_graph::{DepGraph, WorkProductFileKind};
20+
use rustc_incremental::{create_trans_partition, in_incr_comp_dir};
21+
use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
2222
use rustc::middle::cstore::{LinkMeta, EncodedMetadata};
2323
use rustc::session::config::{self, OutputFilenames, OutputType, Passes, SomePasses,
2424
AllPasses, Sanitizer, Lto};
@@ -1021,11 +1021,13 @@ pub fn start_async_translation(tcx: TyCtxt,
10211021
}
10221022
}
10231023

1024-
fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
1025-
dep_graph: &DepGraph,
1026-
compiled_modules: &CompiledModules) {
1024+
fn generate_module_artifacts(sess: &Session,
1025+
compiled_modules: &CompiledModules)
1026+
-> FxHashMap<WorkProductId, WorkProduct> {
1027+
let mut work_products = FxHashMap::default();
1028+
10271029
if sess.opts.incremental.is_none() {
1028-
return;
1030+
return work_products;
10291031
}
10301032

10311033
for module in compiled_modules.modules.iter() {
@@ -1041,8 +1043,12 @@ fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
10411043
files.push((WorkProductFileKind::BytecodeCompressed, path.clone()));
10421044
}
10431045

1044-
save_trans_partition(sess, dep_graph, &module.name, &files);
1046+
if let Some((id, product)) = create_trans_partition(sess, &module.name, &files) {
1047+
work_products.insert(id, product);
1048+
}
10451049
}
1050+
1051+
work_products
10461052
}
10471053

10481054
fn produce_final_output_artifacts(sess: &Session,
@@ -2236,7 +2242,7 @@ pub struct OngoingCrateTranslation {
22362242
}
22372243

22382244
impl OngoingCrateTranslation {
2239-
pub(crate) fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation {
2245+
pub(crate) fn join(self, sess: &Session) -> (CrateTranslation, FxHashMap<WorkProductId, WorkProduct>) {
22402246
self.shared_emitter_main.check(sess, true);
22412247
let compiled_modules = match self.future.join() {
22422248
Ok(Ok(compiled_modules)) => compiled_modules,
@@ -2255,9 +2261,8 @@ impl OngoingCrateTranslation {
22552261
time_graph.dump(&format!("{}-timings", self.crate_name));
22562262
}
22572263

2258-
copy_module_artifacts_into_incr_comp_cache(sess,
2259-
dep_graph,
2260-
&compiled_modules);
2264+
let work_products = generate_module_artifacts(sess, &compiled_modules);
2265+
22612266
produce_final_output_artifacts(sess,
22622267
&compiled_modules,
22632268
&self.output_filenames);
@@ -2281,7 +2286,7 @@ impl OngoingCrateTranslation {
22812286
metadata_module: compiled_modules.metadata_module,
22822287
};
22832288

2284-
trans
2289+
(trans, work_products)
22852290
}
22862291

22872292
pub(crate) fn submit_pre_translated_module_to_llvm(&self,

src/librustc_trans/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ impl TransCrate for LlvmTransCrate {
212212
outputs: &OutputFilenames,
213213
) -> Result<(), CompileIncomplete>{
214214
use rustc::util::common::time;
215-
let trans = trans.downcast::<::back::write::OngoingCrateTranslation>()
215+
let (trans, work_products) = trans.downcast::<::back::write::OngoingCrateTranslation>()
216216
.expect("Expected LlvmTransCrate's OngoingCrateTranslation, found Box<Any>")
217-
.join(sess, dep_graph);
217+
.join(sess);
218218
if sess.opts.debugging_opts.incremental_info {
219219
back::write::dump_incremental_data(&trans);
220220
}
221221

222222
time(sess,
223223
"serialize work products",
224-
move || rustc_incremental::save_work_products(sess, &dep_graph));
224+
move || rustc_incremental::save_work_products(sess, &dep_graph, work_products));
225225

226226
sess.compile_status()?;
227227

0 commit comments

Comments
 (0)