From 12e5b699a493e3d67698a9a42c82f686684c32af Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 6 Jun 2017 15:09:21 +0200 Subject: [PATCH] incr.comp.: Make WorkProductId opaque so we don't accidentally rely on being able to reconstruct obj-file names from one. --- src/librustc/dep_graph/dep_node.rs | 17 ++++++++++++++--- src/librustc/dep_graph/graph.rs | 15 +++++++-------- src/librustc_incremental/persist/data.rs | 3 +-- src/librustc_incremental/persist/load.rs | 7 +++---- .../persist/work_product.rs | 3 +-- src/librustc_trans/partitioning.rs | 5 ++--- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 85a02953a910..1a0f89a1e536 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -9,8 +9,10 @@ // except according to those terms. use hir::def_id::CrateNum; +use ich::Fingerprint; +use rustc_data_structures::stable_hasher::StableHasher; use std::fmt::Debug; -use std::sync::Arc; +use std::hash::Hash; macro_rules! try_opt { ($e:expr) => ( @@ -56,7 +58,7 @@ pub enum DepNode { /// Represents some artifact that we save to disk. Note that these /// do not have a def-id as part of their identifier. - WorkProduct(Arc), + WorkProduct(WorkProductId), // Represents different phases in the compiler. RegionMaps(D), @@ -318,7 +320,16 @@ impl DepNode { /// the need to be mapped or unmapped. (This ensures we can serialize /// them even in the absence of a tcx.) #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] -pub struct WorkProductId(pub String); +pub struct WorkProductId(pub Fingerprint); + +impl WorkProductId { + pub fn from_cgu_name(cgu_name: &str) -> WorkProductId { + let mut hasher = StableHasher::new(); + cgu_name.len().hash(&mut hasher); + cgu_name.hash(&mut hasher); + WorkProductId(hasher.finish()) + } +} #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] pub enum GlobalMetaDataKind { diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 18eb4e5d0ad7..dc482b0d6ac8 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -13,7 +13,6 @@ use rustc_data_structures::fx::FxHashMap; use session::config::OutputType; use std::cell::{Ref, RefCell}; use std::rc::Rc; -use std::sync::Arc; use super::dep_node::{DepNode, WorkProductId}; use super::query::DepGraphQuery; @@ -35,10 +34,10 @@ struct DepGraphData { /// things available to us. If we find that they are not dirty, we /// load the path to the file storing those work-products here into /// this map. We can later look for and extract that data. - previous_work_products: RefCell, WorkProduct>>, + previous_work_products: RefCell>, /// Work-products that we generate in this run. - work_products: RefCell, WorkProduct>>, + work_products: RefCell>, } impl DepGraph { @@ -120,7 +119,7 @@ impl DepGraph { /// Indicates that a previous work product exists for `v`. This is /// invoked during initial start-up based on what nodes are clean /// (and what files exist in the incr. directory). - pub fn insert_previous_work_product(&self, v: &Arc, data: WorkProduct) { + pub fn insert_previous_work_product(&self, v: &WorkProductId, data: WorkProduct) { debug!("insert_previous_work_product({:?}, {:?})", v, data); self.data.previous_work_products.borrow_mut() .insert(v.clone(), data); @@ -129,7 +128,7 @@ impl DepGraph { /// 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: &Arc, data: WorkProduct) { + pub fn insert_work_product(&self, v: &WorkProductId, data: WorkProduct) { debug!("insert_work_product({:?}, {:?})", v, data); self.data.work_products.borrow_mut() .insert(v.clone(), data); @@ -137,7 +136,7 @@ impl DepGraph { /// 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: &Arc) -> Option { + pub fn previous_work_product(&self, v: &WorkProductId) -> Option { self.data.previous_work_products.borrow() .get(v) .cloned() @@ -145,13 +144,13 @@ impl DepGraph { /// Access the map of work-products created during this run. Only /// used during saving of the dep-graph. - pub fn work_products(&self) -> Ref, WorkProduct>> { + pub fn work_products(&self) -> Ref> { self.data.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) -> Ref, WorkProduct>> { + pub fn previous_work_products(&self) -> Ref> { self.data.previous_work_products.borrow() } } diff --git a/src/librustc_incremental/persist/data.rs b/src/librustc_incremental/persist/data.rs index 682a7051a1e9..4669bb866d41 100644 --- a/src/librustc_incremental/persist/data.rs +++ b/src/librustc_incremental/persist/data.rs @@ -15,7 +15,6 @@ use rustc::hir::def_id::DefIndex; use rustc::hir::map::DefPathHash; use rustc::ich::Fingerprint; use rustc::middle::cstore::EncodedMetadataHash; -use std::sync::Arc; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -98,7 +97,7 @@ pub struct SerializedHash { #[derive(Debug, RustcEncodable, RustcDecodable)] pub struct SerializedWorkProduct { /// node that produced the work-product - pub id: Arc, + pub id: WorkProductId, /// work-product data itself pub work_product: WorkProduct, diff --git a/src/librustc_incremental/persist/load.rs b/src/librustc_incremental/persist/load.rs index b30a1f4d3254..f2ecf4c74e78 100644 --- a/src/librustc_incremental/persist/load.rs +++ b/src/librustc_incremental/persist/load.rs @@ -22,7 +22,6 @@ use rustc_serialize::Decodable as RustcDecodable; use rustc_serialize::opaque::Decoder; use std::default::Default; use std::path::{Path}; -use std::sync::Arc; use IncrementalHashesMap; use super::data::*; @@ -327,7 +326,7 @@ fn transitive_dirty_nodes(edge_map: &FxHashMap, Vec(tcx: TyCtxt<'a, 'tcx, 'tcx>, work_products: Vec, - clean_work_products: &FxHashSet>) { + clean_work_products: &FxHashSet) { debug!("reconcile_work_products({:?})", work_products); for swp in work_products { if !clean_work_products.contains(&swp.id) { @@ -424,8 +423,8 @@ fn process_edges<'a, 'tcx, 'edges>( target: &'edges DepNode, edges: &'edges FxHashMap, Vec>>, dirty_raw_nodes: &DirtyNodes, - clean_work_products: &mut FxHashSet>, - dirty_work_products: &mut FxHashSet>, + clean_work_products: &mut FxHashSet, + dirty_work_products: &mut FxHashSet, extra_edges: &mut Vec<(&'edges DepNode, &'edges DepNode)>) { // If the target is dirty, skip the edge. If this is an edge diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs index 0e9f90615401..16ab10ab4bbb 100644 --- a/src/librustc_incremental/persist/work_product.rs +++ b/src/librustc_incremental/persist/work_product.rs @@ -16,7 +16,6 @@ use rustc::session::Session; use rustc::session::config::OutputType; use rustc::util::fs::link_or_copy; use std::path::PathBuf; -use std::sync::Arc; use std::fs as std_fs; pub fn save_trans_partition(sess: &Session, @@ -30,7 +29,7 @@ pub fn save_trans_partition(sess: &Session, if sess.opts.incremental.is_none() { return; } - let work_product_id = Arc::new(WorkProductId(cgu_name.to_string())); + let work_product_id = WorkProductId::from_cgu_name(cgu_name); let saved_files: Option> = files.iter() diff --git a/src/librustc_trans/partitioning.rs b/src/librustc_trans/partitioning.rs index 2fe463e92a8a..df8984e6d247 100644 --- a/src/librustc_trans/partitioning.rs +++ b/src/librustc_trans/partitioning.rs @@ -114,7 +114,6 @@ use rustc::ty::{self, TyCtxt}; use rustc::ty::item_path::characteristic_def_id_of_type; use rustc_incremental::IchHasher; use std::hash::Hash; -use std::sync::Arc; use syntax::ast::NodeId; use syntax::symbol::{Symbol, InternedString}; use trans_item::{TransItem, InstantiationMode}; @@ -164,8 +163,8 @@ impl<'tcx> CodegenUnit<'tcx> { &self.items } - pub fn work_product_id(&self) -> Arc { - Arc::new(WorkProductId(self.name().to_string())) + pub fn work_product_id(&self) -> WorkProductId { + WorkProductId::from_cgu_name(self.name()) } pub fn work_product_dep_node(&self) -> DepNode {