Skip to content

Commit 6d5ec58

Browse files
committedDec 11, 2016
Auto merge of #38272 - michaelwoerister:incr-symbol-visibility, r=nikomatsakis
incr.comp.: Take symbol visibility into account for CGU hashes r? @nikomatsakis
2 parents fd5dc05 + 90f0de8 commit 6d5ec58

File tree

5 files changed

+79
-13
lines changed

5 files changed

+79
-13
lines changed
 

‎src/librustc_incremental/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub mod ich;
4848
pub use assert_dep_graph::assert_dep_graph;
4949
pub use calculate_svh::compute_incremental_hashes_map;
5050
pub use calculate_svh::IncrementalHashesMap;
51+
pub use calculate_svh::hasher::IchHasher;
5152
pub use persist::load_dep_graph;
5253
pub use persist::save_dep_graph;
5354
pub use persist::save_trans_partition;

‎src/librustc_trans/base.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
16101610

16111611
let symbol_map = Rc::new(symbol_map);
16121612

1613-
let previous_work_products = trans_reuse_previous_work_products(tcx,
1613+
let previous_work_products = trans_reuse_previous_work_products(&shared_ccx,
16141614
&codegen_units,
16151615
&symbol_map);
16161616

@@ -1630,7 +1630,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
16301630

16311631
ModuleTranslation {
16321632
name: String::from(ccx.codegen_unit().name()),
1633-
symbol_name_hash: ccx.codegen_unit().compute_symbol_name_hash(tcx, &symbol_map),
1633+
symbol_name_hash: ccx.codegen_unit()
1634+
.compute_symbol_name_hash(&shared_ccx,
1635+
&symbol_map),
16341636
source: source,
16351637
}
16361638
})
@@ -1962,7 +1964,7 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
19621964

19631965
/// For each CGU, identify if we can reuse an existing object file (or
19641966
/// maybe other context).
1965-
fn trans_reuse_previous_work_products(tcx: TyCtxt,
1967+
fn trans_reuse_previous_work_products(scx: &SharedCrateContext,
19661968
codegen_units: &[CodegenUnit],
19671969
symbol_map: &SymbolMap)
19681970
-> Vec<Option<WorkProduct>> {
@@ -1972,16 +1974,16 @@ fn trans_reuse_previous_work_products(tcx: TyCtxt,
19721974
.map(|cgu| {
19731975
let id = cgu.work_product_id();
19741976

1975-
let hash = cgu.compute_symbol_name_hash(tcx, symbol_map);
1977+
let hash = cgu.compute_symbol_name_hash(scx, symbol_map);
19761978

19771979
debug!("trans_reuse_previous_work_products: id={:?} hash={}", id, hash);
19781980

1979-
if let Some(work_product) = tcx.dep_graph.previous_work_product(&id) {
1981+
if let Some(work_product) = scx.dep_graph().previous_work_product(&id) {
19801982
if work_product.input_hash == hash {
19811983
debug!("trans_reuse_previous_work_products: reusing {:?}", work_product);
19821984
return Some(work_product);
19831985
} else {
1984-
if tcx.sess.opts.debugging_opts.incremental_info {
1986+
if scx.sess().opts.debugging_opts.incremental_info {
19851987
println!("incremental: CGU `{}` invalidated because of \
19861988
changed partitioning hash.",
19871989
cgu.name());

‎src/librustc_trans/context.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
use llvm;
1212
use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef};
13-
use rustc::dep_graph::{DepNode, DepTrackingMap, DepTrackingMapConfig, WorkProduct};
13+
use rustc::dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig,
14+
WorkProduct};
1415
use middle::cstore::LinkMeta;
1516
use rustc::hir::def::ExportMap;
1617
use rustc::hir::def_id::DefId;
@@ -551,6 +552,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
551552
&self.tcx.sess
552553
}
553554

555+
pub fn dep_graph<'a>(&'a self) -> &'a DepGraph {
556+
&self.tcx.dep_graph
557+
}
558+
554559
pub fn stats<'a>(&'a self) -> &'a Stats {
555560
&self.stats
556561
}

‎src/librustc_trans/partitioning.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ use rustc::hir::map::DefPathData;
126126
use rustc::session::config::NUMBERED_CODEGEN_UNIT_MARKER;
127127
use rustc::ty::TyCtxt;
128128
use rustc::ty::item_path::characteristic_def_id_of_type;
129+
use rustc_incremental::IchHasher;
129130
use std::cmp::Ordering;
130-
use std::hash::{Hash, Hasher};
131+
use std::hash::Hash;
131132
use std::sync::Arc;
132-
use std::collections::hash_map::DefaultHasher;
133133
use symbol_map::SymbolMap;
134134
use syntax::ast::NodeId;
135135
use syntax::symbol::{Symbol, InternedString};
@@ -188,14 +188,30 @@ impl<'tcx> CodegenUnit<'tcx> {
188188
DepNode::WorkProduct(self.work_product_id())
189189
}
190190

191-
pub fn compute_symbol_name_hash(&self, tcx: TyCtxt, symbol_map: &SymbolMap) -> u64 {
192-
let mut state = DefaultHasher::new();
193-
let all_items = self.items_in_deterministic_order(tcx, symbol_map);
191+
pub fn compute_symbol_name_hash(&self,
192+
scx: &SharedCrateContext,
193+
symbol_map: &SymbolMap) -> u64 {
194+
let mut state = IchHasher::new();
195+
let exported_symbols = scx.exported_symbols();
196+
let all_items = self.items_in_deterministic_order(scx.tcx(), symbol_map);
194197
for (item, _) in all_items {
195198
let symbol_name = symbol_map.get(item).unwrap();
199+
symbol_name.len().hash(&mut state);
196200
symbol_name.hash(&mut state);
201+
let exported = match item {
202+
TransItem::Fn(ref instance) => {
203+
let node_id = scx.tcx().map.as_local_node_id(instance.def);
204+
node_id.map(|node_id| exported_symbols.contains(&node_id))
205+
.unwrap_or(false)
206+
}
207+
TransItem::Static(node_id) => {
208+
exported_symbols.contains(&node_id)
209+
}
210+
TransItem::DropGlue(..) => false,
211+
};
212+
exported.hash(&mut state);
197213
}
198-
state.finish()
214+
state.finish().to_smaller_hash()
199215
}
200216

201217
pub fn items_in_deterministic_order(&self,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// revisions: rpass1 rpass2
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(private_no_mangle_fns)]
15+
16+
#![rustc_partition_reused(module="change_symbol_export_status", cfg="rpass2")]
17+
#![rustc_partition_translated(module="change_symbol_export_status-mod1", cfg="rpass2")]
18+
19+
20+
// This test case makes sure that a change in symbol visibility is detected by
21+
// our dependency tracking. We do this by changing a module's visibility to
22+
// `private` in rpass2, causing the contained function to go from `default` to
23+
// `hidden` visibility.
24+
// The function is marked with #[no_mangle] so it is considered for exporting
25+
// even from an executable. Plain Rust functions are only exported from Rust
26+
// libraries, which our test infrastructure does not support.
27+
28+
#[cfg(rpass1)]
29+
pub mod mod1 {
30+
#[no_mangle]
31+
pub fn foo() {}
32+
}
33+
34+
#[cfg(rpass2)]
35+
mod mod1 {
36+
#[no_mangle]
37+
pub fn foo() {}
38+
}
39+
40+
fn main() {
41+
mod1::foo();
42+
}

0 commit comments

Comments
 (0)