From 4a494ed8df3e3fadf59a25f70265c067b36f94b6 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 9 Dec 2016 17:13:13 -0500 Subject: [PATCH] incr.comp.: Take symbol visibility into account for CGU hashes. --- src/librustc_incremental/lib.rs | 1 + src/librustc_trans/base.rs | 14 ++++++++------ src/librustc_trans/context.rs | 7 ++++++- src/librustc_trans/partitioning.rs | 28 ++++++++++++++++++++++------ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index b72766bccea..3cb5244413b 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -48,6 +48,7 @@ pub mod ich; pub use assert_dep_graph::assert_dep_graph; pub use calculate_svh::compute_incremental_hashes_map; pub use calculate_svh::IncrementalHashesMap; +pub use calculate_svh::hasher::IchHasher; pub use persist::load_dep_graph; pub use persist::save_dep_graph; pub use persist::save_trans_partition; diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 5b79f040d0f..f70c24c3ccb 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1610,7 +1610,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let symbol_map = Rc::new(symbol_map); - let previous_work_products = trans_reuse_previous_work_products(tcx, + let previous_work_products = trans_reuse_previous_work_products(&shared_ccx, &codegen_units, &symbol_map); @@ -1630,7 +1630,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ModuleTranslation { name: String::from(ccx.codegen_unit().name()), - symbol_name_hash: ccx.codegen_unit().compute_symbol_name_hash(tcx, &symbol_map), + symbol_name_hash: ccx.codegen_unit() + .compute_symbol_name_hash(&shared_ccx, + &symbol_map), source: source, } }) @@ -1962,7 +1964,7 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { /// For each CGU, identify if we can reuse an existing object file (or /// maybe other context). -fn trans_reuse_previous_work_products(tcx: TyCtxt, +fn trans_reuse_previous_work_products(scx: &SharedCrateContext, codegen_units: &[CodegenUnit], symbol_map: &SymbolMap) -> Vec> { @@ -1972,16 +1974,16 @@ fn trans_reuse_previous_work_products(tcx: TyCtxt, .map(|cgu| { let id = cgu.work_product_id(); - let hash = cgu.compute_symbol_name_hash(tcx, symbol_map); + let hash = cgu.compute_symbol_name_hash(scx, symbol_map); debug!("trans_reuse_previous_work_products: id={:?} hash={}", id, hash); - if let Some(work_product) = tcx.dep_graph.previous_work_product(&id) { + if let Some(work_product) = scx.dep_graph().previous_work_product(&id) { if work_product.input_hash == hash { debug!("trans_reuse_previous_work_products: reusing {:?}", work_product); return Some(work_product); } else { - if tcx.sess.opts.debugging_opts.incremental_info { + if scx.sess().opts.debugging_opts.incremental_info { println!("incremental: CGU `{}` invalidated because of \ changed partitioning hash.", cgu.name()); diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 262b8362397..8b98eb57814 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -10,7 +10,8 @@ use llvm; use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef}; -use rustc::dep_graph::{DepNode, DepTrackingMap, DepTrackingMapConfig, WorkProduct}; +use rustc::dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig, + WorkProduct}; use middle::cstore::LinkMeta; use rustc::hir::def::ExportMap; use rustc::hir::def_id::DefId; @@ -551,6 +552,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { &self.tcx.sess } + pub fn dep_graph<'a>(&'a self) -> &'a DepGraph { + &self.tcx.dep_graph + } + pub fn stats<'a>(&'a self) -> &'a Stats { &self.stats } diff --git a/src/librustc_trans/partitioning.rs b/src/librustc_trans/partitioning.rs index a36960993e4..d93bbec7efa 100644 --- a/src/librustc_trans/partitioning.rs +++ b/src/librustc_trans/partitioning.rs @@ -126,10 +126,10 @@ use rustc::hir::map::DefPathData; use rustc::session::config::NUMBERED_CODEGEN_UNIT_MARKER; use rustc::ty::TyCtxt; use rustc::ty::item_path::characteristic_def_id_of_type; +use rustc_incremental::IchHasher; use std::cmp::Ordering; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; use std::sync::Arc; -use std::collections::hash_map::DefaultHasher; use symbol_map::SymbolMap; use syntax::ast::NodeId; use syntax::symbol::{Symbol, InternedString}; @@ -188,14 +188,30 @@ impl<'tcx> CodegenUnit<'tcx> { DepNode::WorkProduct(self.work_product_id()) } - pub fn compute_symbol_name_hash(&self, tcx: TyCtxt, symbol_map: &SymbolMap) -> u64 { - let mut state = DefaultHasher::new(); - let all_items = self.items_in_deterministic_order(tcx, symbol_map); + pub fn compute_symbol_name_hash(&self, + scx: &SharedCrateContext, + symbol_map: &SymbolMap) -> u64 { + let mut state = IchHasher::new(); + let exported_symbols = scx.exported_symbols(); + let all_items = self.items_in_deterministic_order(scx.tcx(), symbol_map); for (item, _) in all_items { let symbol_name = symbol_map.get(item).unwrap(); + symbol_name.len().hash(&mut state); symbol_name.hash(&mut state); + let exported = match item { + TransItem::Fn(ref instance) => { + let node_id = scx.tcx().map.as_local_node_id(instance.def); + node_id.map(|node_id| exported_symbols.contains(&node_id)) + .unwrap_or(false) + } + TransItem::Static(node_id) => { + exported_symbols.contains(&node_id) + } + TransItem::DropGlue(..) => false, + }; + exported.hash(&mut state); } - state.finish() + state.finish().to_smaller_hash() } pub fn items_in_deterministic_order(&self,