Skip to content

Commit 12e5b69

Browse files
incr.comp.: Make WorkProductId opaque so we don't accidentally rely on being able to reconstruct obj-file names from one.
1 parent 7fc8490 commit 12e5b69

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
// except according to those terms.
1010

1111
use hir::def_id::CrateNum;
12+
use ich::Fingerprint;
13+
use rustc_data_structures::stable_hasher::StableHasher;
1214
use std::fmt::Debug;
13-
use std::sync::Arc;
15+
use std::hash::Hash;
1416

1517
macro_rules! try_opt {
1618
($e:expr) => (
@@ -56,7 +58,7 @@ pub enum DepNode<D: Clone + Debug> {
5658

5759
/// Represents some artifact that we save to disk. Note that these
5860
/// do not have a def-id as part of their identifier.
59-
WorkProduct(Arc<WorkProductId>),
61+
WorkProduct(WorkProductId),
6062

6163
// Represents different phases in the compiler.
6264
RegionMaps(D),
@@ -318,7 +320,16 @@ impl<D: Clone + Debug> DepNode<D> {
318320
/// the need to be mapped or unmapped. (This ensures we can serialize
319321
/// them even in the absence of a tcx.)
320322
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
321-
pub struct WorkProductId(pub String);
323+
pub struct WorkProductId(pub Fingerprint);
324+
325+
impl WorkProductId {
326+
pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
327+
let mut hasher = StableHasher::new();
328+
cgu_name.len().hash(&mut hasher);
329+
cgu_name.hash(&mut hasher);
330+
WorkProductId(hasher.finish())
331+
}
332+
}
322333

323334
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
324335
pub enum GlobalMetaDataKind {

src/librustc/dep_graph/graph.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_data_structures::fx::FxHashMap;
1313
use session::config::OutputType;
1414
use std::cell::{Ref, RefCell};
1515
use std::rc::Rc;
16-
use std::sync::Arc;
1716

1817
use super::dep_node::{DepNode, WorkProductId};
1918
use super::query::DepGraphQuery;
@@ -35,10 +34,10 @@ struct DepGraphData {
3534
/// things available to us. If we find that they are not dirty, we
3635
/// load the path to the file storing those work-products here into
3736
/// this map. We can later look for and extract that data.
38-
previous_work_products: RefCell<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
37+
previous_work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
3938

4039
/// Work-products that we generate in this run.
41-
work_products: RefCell<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
40+
work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
4241
}
4342

4443
impl DepGraph {
@@ -120,7 +119,7 @@ impl DepGraph {
120119
/// Indicates that a previous work product exists for `v`. This is
121120
/// invoked during initial start-up based on what nodes are clean
122121
/// (and what files exist in the incr. directory).
123-
pub fn insert_previous_work_product(&self, v: &Arc<WorkProductId>, data: WorkProduct) {
122+
pub fn insert_previous_work_product(&self, v: &WorkProductId, data: WorkProduct) {
124123
debug!("insert_previous_work_product({:?}, {:?})", v, data);
125124
self.data.previous_work_products.borrow_mut()
126125
.insert(v.clone(), data);
@@ -129,29 +128,29 @@ impl DepGraph {
129128
/// Indicates that we created the given work-product in this run
130129
/// for `v`. This record will be preserved and loaded in the next
131130
/// run.
132-
pub fn insert_work_product(&self, v: &Arc<WorkProductId>, data: WorkProduct) {
131+
pub fn insert_work_product(&self, v: &WorkProductId, data: WorkProduct) {
133132
debug!("insert_work_product({:?}, {:?})", v, data);
134133
self.data.work_products.borrow_mut()
135134
.insert(v.clone(), data);
136135
}
137136

138137
/// Check whether a previous work product exists for `v` and, if
139138
/// so, return the path that leads to it. Used to skip doing work.
140-
pub fn previous_work_product(&self, v: &Arc<WorkProductId>) -> Option<WorkProduct> {
139+
pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
141140
self.data.previous_work_products.borrow()
142141
.get(v)
143142
.cloned()
144143
}
145144

146145
/// Access the map of work-products created during this run. Only
147146
/// used during saving of the dep-graph.
148-
pub fn work_products(&self) -> Ref<FxHashMap<Arc<WorkProductId>, WorkProduct>> {
147+
pub fn work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
149148
self.data.work_products.borrow()
150149
}
151150

152151
/// Access the map of work-products created during the cached run. Only
153152
/// used during saving of the dep-graph.
154-
pub fn previous_work_products(&self) -> Ref<FxHashMap<Arc<WorkProductId>, WorkProduct>> {
153+
pub fn previous_work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
155154
self.data.previous_work_products.borrow()
156155
}
157156
}

src/librustc_incremental/persist/data.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::hir::def_id::DefIndex;
1515
use rustc::hir::map::DefPathHash;
1616
use rustc::ich::Fingerprint;
1717
use rustc::middle::cstore::EncodedMetadataHash;
18-
use std::sync::Arc;
1918
use rustc_data_structures::fx::FxHashMap;
2019
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2120

@@ -98,7 +97,7 @@ pub struct SerializedHash {
9897
#[derive(Debug, RustcEncodable, RustcDecodable)]
9998
pub struct SerializedWorkProduct {
10099
/// node that produced the work-product
101-
pub id: Arc<WorkProductId>,
100+
pub id: WorkProductId,
102101

103102
/// work-product data itself
104103
pub work_product: WorkProduct,

src/librustc_incremental/persist/load.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_serialize::Decodable as RustcDecodable;
2222
use rustc_serialize::opaque::Decoder;
2323
use std::default::Default;
2424
use std::path::{Path};
25-
use std::sync::Arc;
2625

2726
use IncrementalHashesMap;
2827
use super::data::*;
@@ -327,7 +326,7 @@ fn transitive_dirty_nodes(edge_map: &FxHashMap<DepNode<DefPathHash>, Vec<DepNode
327326
/// otherwise no longer applicable.
328327
fn reconcile_work_products<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
329328
work_products: Vec<SerializedWorkProduct>,
330-
clean_work_products: &FxHashSet<Arc<WorkProductId>>) {
329+
clean_work_products: &FxHashSet<WorkProductId>) {
331330
debug!("reconcile_work_products({:?})", work_products);
332331
for swp in work_products {
333332
if !clean_work_products.contains(&swp.id) {
@@ -424,8 +423,8 @@ fn process_edges<'a, 'tcx, 'edges>(
424423
target: &'edges DepNode<DefPathHash>,
425424
edges: &'edges FxHashMap<DepNode<DefPathHash>, Vec<DepNode<DefPathHash>>>,
426425
dirty_raw_nodes: &DirtyNodes,
427-
clean_work_products: &mut FxHashSet<Arc<WorkProductId>>,
428-
dirty_work_products: &mut FxHashSet<Arc<WorkProductId>>,
426+
clean_work_products: &mut FxHashSet<WorkProductId>,
427+
dirty_work_products: &mut FxHashSet<WorkProductId>,
429428
extra_edges: &mut Vec<(&'edges DepNode<DefPathHash>, &'edges DepNode<DefPathHash>)>)
430429
{
431430
// If the target is dirty, skip the edge. If this is an edge

src/librustc_incremental/persist/work_product.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc::session::Session;
1616
use rustc::session::config::OutputType;
1717
use rustc::util::fs::link_or_copy;
1818
use std::path::PathBuf;
19-
use std::sync::Arc;
2019
use std::fs as std_fs;
2120

2221
pub fn save_trans_partition(sess: &Session,
@@ -30,7 +29,7 @@ pub fn save_trans_partition(sess: &Session,
3029
if sess.opts.incremental.is_none() {
3130
return;
3231
}
33-
let work_product_id = Arc::new(WorkProductId(cgu_name.to_string()));
32+
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
3433

3534
let saved_files: Option<Vec<_>> =
3635
files.iter()

src/librustc_trans/partitioning.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ use rustc::ty::{self, TyCtxt};
114114
use rustc::ty::item_path::characteristic_def_id_of_type;
115115
use rustc_incremental::IchHasher;
116116
use std::hash::Hash;
117-
use std::sync::Arc;
118117
use syntax::ast::NodeId;
119118
use syntax::symbol::{Symbol, InternedString};
120119
use trans_item::{TransItem, InstantiationMode};
@@ -164,8 +163,8 @@ impl<'tcx> CodegenUnit<'tcx> {
164163
&self.items
165164
}
166165

167-
pub fn work_product_id(&self) -> Arc<WorkProductId> {
168-
Arc::new(WorkProductId(self.name().to_string()))
166+
pub fn work_product_id(&self) -> WorkProductId {
167+
WorkProductId::from_cgu_name(self.name())
169168
}
170169

171170
pub fn work_product_dep_node(&self) -> DepNode<DefId> {

0 commit comments

Comments
 (0)