Skip to content

Commit 5948b97

Browse files
authored
Rollup merge of rust-lang#50558 - whitfin:issue-50500, r=michaelwoerister
Remove all reference to DepGraph::work_products This is an attempt at fixing rust-lang#50500. It will remove the `work_products` key from `DepGraphData` completely, in favour of just passing the relevant data around. I went in a little blindly; everything appears to work just fine but I'd appreciate any additional advice people. I didn't want to remove too much of what was already there, so I kept the structure pretty much the same (aside from some naming tweaks) - if anyone has suggestions on how to streamline it a little better, happy to follow up. r? @michaelwoerister
2 parents d4444cb + 8402a58 commit 5948b97

File tree

7 files changed

+51
-63
lines changed

7 files changed

+51
-63
lines changed

src/librustc/dep_graph/graph.rs

+1-24
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/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub use persist::dep_graph_tcx_init;
3636
pub use persist::load_dep_graph;
3737
pub use persist::load_query_result_cache;
3838
pub use persist::LoadResult;
39+
pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
3940
pub use persist::save_dep_graph;
40-
pub use persist::save_trans_partition;
41-
pub use persist::save_work_products;
41+
pub use persist::save_work_product_index;
4242
pub use persist::in_incr_comp_dir;
4343
pub use persist::prepare_session_directory;
4444
pub use persist::finalize_session_directory;

src/librustc_incremental/persist/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ pub use self::load::load_dep_graph;
2929
pub use self::load::load_query_result_cache;
3030
pub use self::load::LoadResult;
3131
pub use self::save::save_dep_graph;
32-
pub use self::save::save_work_products;
33-
pub use self::work_product::save_trans_partition;
32+
pub use self::save::save_work_product_index;
33+
pub use self::work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
3434
pub use self::work_product::delete_workproduct_files;

src/librustc_incremental/persist/save.rs

+10-11
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_product_index(sess: &Session,
59+
dep_graph: &DepGraph,
60+
new_work_products: FxHashMap<WorkProductId, WorkProduct>) {
5961
if sess.opts.incremental.is_none() {
6062
return;
6163
}
6264

63-
debug!("save_work_products()");
65+
debug!("save_work_product_index()");
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_product_index(&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,
238-
encoder: &mut Encoder) -> io::Result<()> {
239-
let work_products: Vec<_> = dep_graph
240-
.work_products()
237+
fn encode_work_product_index(work_products: &FxHashMap<WorkProductId, WorkProduct>,
238+
encoder: &mut Encoder) -> io::Result<()> {
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

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
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 copy_cgu_workproducts_to_incr_comp_cache_dir(
21+
sess: &Session,
22+
cgu_name: &str,
23+
files: &[(WorkProductFileKind, PathBuf)]
24+
) -> Option<(WorkProductId, WorkProduct)> {
25+
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})",
2526
cgu_name,
2627
files);
2728
if sess.opts.incremental.is_none() {
28-
return
29+
return None
2930
}
3031
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
3132

@@ -53,16 +54,16 @@ pub fn save_trans_partition(sess: &Session,
5354
})
5455
.collect();
5556
let saved_files = match saved_files {
57+
None => return None,
5658
Some(v) => v,
57-
None => return,
5859
};
5960

6061
let work_product = WorkProduct {
6162
cgu_name: cgu_name.to_string(),
6263
saved_files,
6364
};
6465

65-
dep_graph.insert_work_product(&work_product_id, work_product);
66+
Some((work_product_id, work_product))
6667
}
6768

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

src/librustc_trans/back/write.rs

+23-12
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::{copy_cgu_workproducts_to_incr_comp_cache_dir, 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,14 @@ 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 copy_all_cgu_workproducts_to_incr_comp_cache_dir(
1025+
sess: &Session,
1026+
compiled_modules: &CompiledModules
1027+
) -> FxHashMap<WorkProductId, WorkProduct> {
1028+
let mut work_products = FxHashMap::default();
1029+
10271030
if sess.opts.incremental.is_none() {
1028-
return;
1031+
return work_products;
10291032
}
10301033

10311034
for module in compiled_modules.modules.iter() {
@@ -1041,8 +1044,13 @@ fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
10411044
files.push((WorkProductFileKind::BytecodeCompressed, path.clone()));
10421045
}
10431046

1044-
save_trans_partition(sess, dep_graph, &module.name, &files);
1047+
if let Some((id, product)) =
1048+
copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files) {
1049+
work_products.insert(id, product);
1050+
}
10451051
}
1052+
1053+
work_products
10461054
}
10471055

10481056
fn produce_final_output_artifacts(sess: &Session,
@@ -2236,7 +2244,10 @@ pub struct OngoingCrateTranslation {
22362244
}
22372245

22382246
impl OngoingCrateTranslation {
2239-
pub(crate) fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation {
2247+
pub(crate) fn join(
2248+
self,
2249+
sess: &Session
2250+
) -> (CrateTranslation, FxHashMap<WorkProductId, WorkProduct>) {
22402251
self.shared_emitter_main.check(sess, true);
22412252
let compiled_modules = match self.future.join() {
22422253
Ok(Ok(compiled_modules)) => compiled_modules,
@@ -2255,9 +2266,9 @@ impl OngoingCrateTranslation {
22552266
time_graph.dump(&format!("{}-timings", self.crate_name));
22562267
}
22572268

2258-
copy_module_artifacts_into_incr_comp_cache(sess,
2259-
dep_graph,
2260-
&compiled_modules);
2269+
let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess,
2270+
&compiled_modules);
2271+
22612272
produce_final_output_artifacts(sess,
22622273
&compiled_modules,
22632274
&self.output_filenames);
@@ -2281,7 +2292,7 @@ impl OngoingCrateTranslation {
22812292
metadata_module: compiled_modules.metadata_module,
22822293
};
22832294

2284-
trans
2295+
(trans, work_products)
22852296
}
22862297

22872298
pub(crate) fn submit_pre_translated_module_to_llvm(&self,

src/librustc_trans/lib.rs

+3-3
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_product_index(sess, &dep_graph, work_products));
225225

226226
sess.compile_status()?;
227227

0 commit comments

Comments
 (0)