Remove shared access to DepGraph::work_products

This commit is contained in:
Isaac Whitfield 2018-05-08 22:20:09 -07:00
parent 41707d8df9
commit 89a8f2c103
6 changed files with 39 additions and 58 deletions

View file

@ -30,5 +30,5 @@ pub use self::load::load_query_result_cache;
pub use self::load::LoadResult;
pub use self::save::save_dep_graph;
pub use self::save::save_work_products;
pub use self::work_product::save_trans_partition;
pub use self::work_product::create_trans_partition;
pub use self::work_product::delete_workproduct_files;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::dep_graph::{DepGraph, DepKind};
use rustc::dep_graph::{DepGraph, DepKind, WorkProduct, WorkProductId};
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc::util::common::time;
@ -55,7 +55,9 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
})
}
pub fn save_work_products(sess: &Session, dep_graph: &DepGraph) {
pub fn save_work_products(sess: &Session,
dep_graph: &DepGraph,
new_work_products: FxHashMap<WorkProductId, WorkProduct>) {
if sess.opts.incremental.is_none() {
return;
}
@ -63,14 +65,12 @@ pub fn save_work_products(sess: &Session, dep_graph: &DepGraph) {
debug!("save_work_products()");
dep_graph.assert_ignored();
let path = work_products_path(sess);
save_in(sess, path, |e| encode_work_products(dep_graph, e));
save_in(sess, path, |e| encode_work_products(&new_work_products, e));
// We also need to clean out old work-products, as not all of them are
// deleted during invalidation. Some object files don't change their
// content, they are just not needed anymore.
let new_work_products = dep_graph.work_products();
let previous_work_products = dep_graph.previous_work_products();
for (id, wp) in previous_work_products.iter() {
if !new_work_products.contains_key(id) {
work_product::delete_workproduct_files(sess, wp);
@ -234,10 +234,9 @@ fn encode_dep_graph(tcx: TyCtxt,
Ok(())
}
fn encode_work_products(dep_graph: &DepGraph,
fn encode_work_products(work_products: &FxHashMap<WorkProductId, WorkProduct>,
encoder: &mut Encoder) -> io::Result<()> {
let work_products: Vec<_> = dep_graph
.work_products()
let serialized_products: Vec<_> = work_products
.iter()
.map(|(id, work_product)| {
SerializedWorkProduct {
@ -247,7 +246,7 @@ fn encode_work_products(dep_graph: &DepGraph,
})
.collect();
work_products.encode(encoder)
serialized_products.encode(encoder)
}
fn encode_query_cache(tcx: TyCtxt,

View file

@ -11,21 +11,21 @@
//! This module contains files for saving intermediate work-products.
use persist::fs::*;
use rustc::dep_graph::{WorkProduct, WorkProductId, DepGraph, WorkProductFileKind};
use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
use rustc::session::Session;
use rustc::util::fs::link_or_copy;
use std::path::PathBuf;
use std::fs as std_fs;
pub fn save_trans_partition(sess: &Session,
dep_graph: &DepGraph,
cgu_name: &str,
files: &[(WorkProductFileKind, PathBuf)]) {
debug!("save_trans_partition({:?},{:?})",
pub fn create_trans_partition(sess: &Session,
cgu_name: &str,
files: &[(WorkProductFileKind, PathBuf)])
-> Option<(WorkProductId, WorkProduct)> {
debug!("create_trans_partition({:?},{:?})",
cgu_name,
files);
if sess.opts.incremental.is_none() {
return
return None
}
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
@ -53,8 +53,8 @@ pub fn save_trans_partition(sess: &Session,
})
.collect();
let saved_files = match saved_files {
None => return None,
Some(v) => v,
None => return,
};
let work_product = WorkProduct {
@ -62,7 +62,7 @@ pub fn save_trans_partition(sess: &Session,
saved_files,
};
dep_graph.insert_work_product(&work_product_id, work_product);
Some((work_product_id, work_product))
}
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {