mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
incr.comp.: Make WorkProductId opaque so we don't accidentally rely on being able to reconstruct obj-file names from one.
This commit is contained in:
parent
7fc84907dc
commit
12e5b699a4
@ -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<D: Clone + Debug> {
|
||||
|
||||
/// Represents some artifact that we save to disk. Note that these
|
||||
/// do not have a def-id as part of their identifier.
|
||||
WorkProduct(Arc<WorkProductId>),
|
||||
WorkProduct(WorkProductId),
|
||||
|
||||
// Represents different phases in the compiler.
|
||||
RegionMaps(D),
|
||||
@ -318,7 +320,16 @@ impl<D: Clone + Debug> DepNode<D> {
|
||||
/// 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 {
|
||||
|
@ -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<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
|
||||
previous_work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
|
||||
|
||||
/// Work-products that we generate in this run.
|
||||
work_products: RefCell<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
|
||||
work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
|
||||
}
|
||||
|
||||
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<WorkProductId>, 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<WorkProductId>, 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<WorkProductId>) -> Option<WorkProduct> {
|
||||
pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
|
||||
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<FxHashMap<Arc<WorkProductId>, WorkProduct>> {
|
||||
pub fn work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
|
||||
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<FxHashMap<Arc<WorkProductId>, WorkProduct>> {
|
||||
pub fn previous_work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
|
||||
self.data.previous_work_products.borrow()
|
||||
}
|
||||
}
|
||||
|
@ -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<WorkProductId>,
|
||||
pub id: WorkProductId,
|
||||
|
||||
/// work-product data itself
|
||||
pub work_product: WorkProduct,
|
||||
|
@ -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<DepNode<DefPathHash>, Vec<DepNode
|
||||
/// otherwise no longer applicable.
|
||||
fn reconcile_work_products<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
work_products: Vec<SerializedWorkProduct>,
|
||||
clean_work_products: &FxHashSet<Arc<WorkProductId>>) {
|
||||
clean_work_products: &FxHashSet<WorkProductId>) {
|
||||
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<DefPathHash>,
|
||||
edges: &'edges FxHashMap<DepNode<DefPathHash>, Vec<DepNode<DefPathHash>>>,
|
||||
dirty_raw_nodes: &DirtyNodes,
|
||||
clean_work_products: &mut FxHashSet<Arc<WorkProductId>>,
|
||||
dirty_work_products: &mut FxHashSet<Arc<WorkProductId>>,
|
||||
clean_work_products: &mut FxHashSet<WorkProductId>,
|
||||
dirty_work_products: &mut FxHashSet<WorkProductId>,
|
||||
extra_edges: &mut Vec<(&'edges DepNode<DefPathHash>, &'edges DepNode<DefPathHash>)>)
|
||||
{
|
||||
// If the target is dirty, skip the edge. If this is an edge
|
||||
|
@ -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<Vec<_>> =
|
||||
files.iter()
|
||||
|
@ -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<WorkProductId> {
|
||||
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<DefId> {
|
||||
|
Loading…
Reference in New Issue
Block a user