Auto merge of #43612 - michaelwoerister:fix-cgu-hashing, r=eddyb
incr.comp.: Properly incorporate symbol linkage and visibility into CGU hash. This PR fixes the way the CGU hash for incr. comp. is computed. The CGU hash represents which `TransItems` are emitted into which codegen unit with which linkage and visibility. Before the new, LLVM-independent symbol internalizer the CGU hash did not accurately contain `TransItem` linkage and visibility because we would not enable symbol internalization in incremental mode anyway. The new internalizer is also run in incremental mode which uncovered the inaccuracy of CGU hashing. Luckily, the fix is rather simple. r? @eddyb cc @nikomatsakis
This commit is contained in:
commit
22f256f69e
2 changed files with 5 additions and 18 deletions
|
|
@ -1172,7 +1172,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
|
||||
let cgu_name = String::from(cgu.name());
|
||||
let cgu_id = cgu.work_product_id();
|
||||
let symbol_name_hash = cgu.compute_symbol_name_hash(scx, &exported_symbols);
|
||||
let symbol_name_hash = cgu.compute_symbol_name_hash(scx);
|
||||
|
||||
// Check whether there is a previous work-product we can
|
||||
// re-use. Not only must the file exist, and the inputs not
|
||||
|
|
|
|||
|
|
@ -174,29 +174,16 @@ impl<'tcx> CodegenUnit<'tcx> {
|
|||
}
|
||||
|
||||
pub fn compute_symbol_name_hash<'a>(&self,
|
||||
scx: &SharedCrateContext<'a, 'tcx>,
|
||||
exported_symbols: &ExportedSymbols)
|
||||
scx: &SharedCrateContext<'a, 'tcx>)
|
||||
-> u64 {
|
||||
let mut state = IchHasher::new();
|
||||
let exported_symbols = exported_symbols.local_exports();
|
||||
let all_items = self.items_in_deterministic_order(scx.tcx());
|
||||
for (item, _) in all_items {
|
||||
for (item, (linkage, visibility)) in all_items {
|
||||
let symbol_name = item.symbol_name(scx.tcx());
|
||||
symbol_name.len().hash(&mut state);
|
||||
symbol_name.hash(&mut state);
|
||||
let exported = match item {
|
||||
TransItem::Fn(ref instance) => {
|
||||
let node_id =
|
||||
scx.tcx().hir.as_local_node_id(instance.def_id());
|
||||
node_id.map(|node_id| exported_symbols.contains(&node_id))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
TransItem::Static(node_id) => {
|
||||
exported_symbols.contains(&node_id)
|
||||
}
|
||||
TransItem::GlobalAsm(..) => true,
|
||||
};
|
||||
exported.hash(&mut state);
|
||||
linkage.hash(&mut state);
|
||||
visibility.hash(&mut state);
|
||||
}
|
||||
state.finish().to_smaller_hash()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue