Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Incremental] Cache hashes for AdDef and ty::Slice<T> #47373

Merged
merged 2 commits into from
Jan 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[incremental] Cache ty::Slice<T> hashes
Fixes #47294
  • Loading branch information
wesleywiser committed Jan 16, 2018
commit 45bd091e76db5a743a2f251612408e77a2610099
25 changes: 23 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
//! This module contains `HashStable` implementations for various data types
//! from rustc::ty in no particular order.

use ich::{StableHashingContext, NodeIdHashingMode};
use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
StableHasher, StableHasherResult};
use std::cell::RefCell;
use std::hash as std_hash;
use std::mem;
use middle::region;
Expand All @@ -26,7 +28,26 @@ for &'gcx ty::Slice<T>
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hasher: &mut StableHasher<W>) {
(&self[..]).hash_stable(hcx, hasher);
thread_local! {
static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
RefCell::new(FxHashMap());
}

let hash = CACHE.with(|cache| {
let key = (self.as_ptr() as usize, self.len());
if let Some(&hash) = cache.borrow().get(&key) {
return hash;
}

let mut hasher = StableHasher::new();
(&self[..]).hash_stable(hcx, &mut hasher);

let hash: Fingerprint = hasher.finish();
cache.borrow_mut().insert(key, hash);
hash
});

hash.hash_stable(hcx, hasher);
}
}

Expand Down