use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::small_vec::SmallVec;
-use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock};
+use rustc_data_structures::sync::{Lrc, Lock};
use std::env;
use std::hash::Hash;
use ty::{self, TyCtxt};
/// this map. We can later look for and extract that data.
previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
- /// Work-products that we generate in this run.
- work_products: RwLock<FxHashMap<WorkProductId, WorkProduct>>,
-
dep_node_debug: Lock<FxHashMap<DepNode, String>>,
// Used for testing, only populated when -Zquery-dep-graph is specified.
DepGraph {
data: Some(Lrc::new(DepGraphData {
previous_work_products: prev_work_products,
- work_products: RwLock::new(FxHashMap()),
dep_node_debug: Lock::new(FxHashMap()),
current: Lock::new(CurrentDepGraph::new()),
previous: prev_graph,
self.data.as_ref().unwrap().previous.node_to_index(dep_node)
}
- /// Indicates that we created the given work-product in this run
- /// for `v`. This record will be preserved and loaded in the next
- /// run.
- pub fn insert_work_product(&self, v: &WorkProductId, data: WorkProduct) {
- debug!("insert_work_product({:?}, {:?})", v, data);
- self.data
- .as_ref()
- .unwrap()
- .work_products
- .borrow_mut()
- .insert(v.clone(), data);
- }
-
/// Check whether a previous work product exists for `v` and, if
/// so, return the path that leads to it. Used to skip doing work.
pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
})
}
- /// Access the map of work-products created during this run. Only
- /// used during saving of the dep-graph.
- pub fn work_products(&self) -> ReadGuard<FxHashMap<WorkProductId, WorkProduct>> {
- self.data.as_ref().unwrap().work_products.borrow()
- }
-
/// Access the map of work-products created during the cached run. Only
/// used during saving of the dep-graph.
pub fn previous_work_products(&self) -> &FxHashMap<WorkProductId, WorkProduct> {
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;
// 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;
})
}
-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;
}
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);
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 {
})
.collect();
- work_products.encode(encoder)
+ serialized_products.encode(encoder)
}
fn encode_query_cache(tcx: TyCtxt,
//! 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);
})
.collect();
let saved_files = match saved_files {
+ None => return None,
Some(v) => v,
- None => return,
};
let work_product = WorkProduct {
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) {
use back::symbol_export::ExportedSymbols;
use base;
use consts;
-use rustc_incremental::{save_trans_partition, in_incr_comp_dir};
-use rustc::dep_graph::{DepGraph, WorkProductFileKind};
+use rustc_incremental::{create_trans_partition, in_incr_comp_dir};
+use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
use rustc::middle::cstore::{LinkMeta, EncodedMetadata};
use rustc::session::config::{self, OutputFilenames, OutputType, Passes, SomePasses,
AllPasses, Sanitizer, Lto};
}
}
-fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
- dep_graph: &DepGraph,
- compiled_modules: &CompiledModules) {
+fn generate_module_artifacts(sess: &Session,
+ compiled_modules: &CompiledModules)
+ -> FxHashMap<WorkProductId, WorkProduct> {
+ let mut work_products = FxHashMap::default();
+
if sess.opts.incremental.is_none() {
- return;
+ return work_products;
}
for module in compiled_modules.modules.iter() {
files.push((WorkProductFileKind::BytecodeCompressed, path.clone()));
}
- save_trans_partition(sess, dep_graph, &module.name, &files);
+ if let Some((id, product)) = create_trans_partition(sess, &module.name, &files) {
+ work_products.insert(id, product);
+ }
}
+
+ work_products
}
fn produce_final_output_artifacts(sess: &Session,
}
impl OngoingCrateTranslation {
- pub(crate) fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation {
+ pub(crate) fn join(self, sess: &Session) -> (CrateTranslation, FxHashMap<WorkProductId, WorkProduct>) {
self.shared_emitter_main.check(sess, true);
let compiled_modules = match self.future.join() {
Ok(Ok(compiled_modules)) => compiled_modules,
time_graph.dump(&format!("{}-timings", self.crate_name));
}
- copy_module_artifacts_into_incr_comp_cache(sess,
- dep_graph,
- &compiled_modules);
+ let work_products = generate_module_artifacts(sess, &compiled_modules);
+
produce_final_output_artifacts(sess,
&compiled_modules,
&self.output_filenames);
metadata_module: compiled_modules.metadata_module,
};
- trans
+ (trans, work_products)
}
pub(crate) fn submit_pre_translated_module_to_llvm(&self,
outputs: &OutputFilenames,
) -> Result<(), CompileIncomplete>{
use rustc::util::common::time;
- let trans = trans.downcast::<::back::write::OngoingCrateTranslation>()
+ let (trans, work_products) = trans.downcast::<::back::write::OngoingCrateTranslation>()
.expect("Expected LlvmTransCrate's OngoingCrateTranslation, found Box<Any>")
- .join(sess, dep_graph);
+ .join(sess);
if sess.opts.debugging_opts.incremental_info {
back::write::dump_incremental_data(&trans);
}
time(sess,
"serialize work products",
- move || rustc_incremental::save_work_products(sess, &dep_graph));
+ move || rustc_incremental::save_work_products(sess, &dep_graph, work_products));
sess.compile_status()?;