Rollup merge of #51982 - michaelwoerister:hash-modules-properly, r=nikomatsakis

incr.comp.: Take names of children into account when computing the ICH of a module's HIR.

Fixes #40876. Red-green tracking does not make this a problem anymore. We should verify this via a perf-run though.

r? @nikomatsakis
This commit is contained in:
Pietro Albini 2018-07-03 11:31:10 +02:00 committed by GitHub
commit b69058daa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 11 deletions

View File

@ -23,6 +23,7 @@ use rustc_data_structures::indexed_vec::{IndexVec};
use rustc_data_structures::stable_hasher::StableHasher;
use serialize::{Encodable, Decodable, Encoder, Decoder};
use session::CrateDisambiguator;
use std::borrow::Borrow;
use std::fmt::Write;
use std::hash::Hash;
use syntax::ast;
@ -389,6 +390,13 @@ pub struct DefPathHash(pub Fingerprint);
impl_stable_hash_for!(tuple_struct DefPathHash { fingerprint });
impl Borrow<Fingerprint> for DefPathHash {
#[inline]
fn borrow(&self) -> &Fingerprint {
&self.0
}
}
impl Definitions {
/// Create new empty definition map.
pub fn new() -> Definitions {

View File

@ -45,6 +45,18 @@ impl Fingerprint {
)
}
// Combines two hashes in an order independent way. Make sure this is what
// you want.
#[inline]
pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint {
let a = (self.1 as u128) << 64 | self.0 as u128;
let b = (other.1 as u128) << 64 | other.0 as u128;
let c = a.wrapping_add(b);
Fingerprint((c >> 64) as u64, c as u64)
}
pub fn to_hex(&self) -> String {
format!("{:x}{:x}", self.0, self.1)
}

View File

@ -14,7 +14,7 @@
use hir;
use hir::map::DefPathHash;
use hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX};
use ich::{StableHashingContext, NodeIdHashingMode};
use ich::{StableHashingContext, NodeIdHashingMode, Fingerprint};
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
StableHasher, StableHasherResult};
use std::mem;
@ -755,13 +755,34 @@ impl_stable_hash_for!(enum hir::ImplPolarity {
Negative
});
impl_stable_hash_for!(struct hir::Mod {
inner,
// We are not hashing the IDs of the items contained in the module.
// This is harmless and matches the current behavior but it's not
// actually correct. See issue #40876.
item_ids -> _,
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Mod {
inner: ref inner_span,
ref item_ids,
} = *self;
inner_span.hash_stable(hcx, hasher);
// Combining the DefPathHashes directly is faster than feeding them
// into the hasher. Because we use a commutative combine, we also don't
// have to sort the array.
let item_ids_hash = item_ids
.iter()
.map(|id| {
let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx);
debug_assert_eq!(local_id, hir::ItemLocalId(0));
def_path_hash.0
}).fold(Fingerprint::ZERO, |a, b| {
a.combine_commutative(b)
});
item_ids.len().hash_stable(hcx, hasher);
item_ids_hash.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::ForeignMod {
abi,

View File

@ -25,11 +25,10 @@ use monomorphize::Instance;
use type_of::LayoutLlvmExt;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::mir::mono::{Linkage, Visibility};
use rustc::ty::TypeFoldable;
use rustc::ty::layout::LayoutOf;
use syntax::attr;
use std::fmt;
pub use rustc::mir::mono::MonoItem;
@ -173,7 +172,7 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
// visibility as we're going to link this object all over the place but
// don't want the symbols to get exported.
if linkage != Linkage::Internal && linkage != Linkage::Private &&
attr::contains_name(cx.tcx.hir.krate_attrs(), "compiler_builtins") {
cx.tcx.is_compiler_builtins(LOCAL_CRATE) {
unsafe {
llvm::LLVMRustSetVisibility(lldecl, llvm::Visibility::Hidden);
}