pub incr_comp_hashes_time: Cell<Duration>,
// The number of incr. comp. hash computations performed
pub incr_comp_hashes_count: Cell<u64>,
+ // The number of bytes hashed when computing ICH values
+ pub incr_comp_bytes_hashed: Cell<u64>,
// The accumulated time spent on computing symbol hashes
pub symbol_hash_time: Cell<Duration>,
}
duration_to_secs_str(self.perf_stats.incr_comp_hashes_time.get()));
println!("Total number of incr. comp. hashes computed: {}",
self.perf_stats.incr_comp_hashes_count.get());
+ println!("Total number of bytes hashed for incr. comp.: {}",
+ self.perf_stats.incr_comp_bytes_hashed.get());
+ println!("Average bytes hashed per incr. comp. HIR node: {}",
+ self.perf_stats.incr_comp_bytes_hashed.get() /
+ self.perf_stats.incr_comp_hashes_count.get());
println!("Total time spent computing symbol hashes: {}",
duration_to_secs_str(self.perf_stats.symbol_hash_time.get()));
}
svh_time: Cell::new(Duration::from_secs(0)),
incr_comp_hashes_time: Cell::new(Duration::from_secs(0)),
incr_comp_hashes_count: Cell::new(0),
+ incr_comp_bytes_hashed: Cell::new(0),
symbol_hash_time: Cell::new(Duration::from_secs(0)),
}
};
--- /dev/null
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::hash::Hasher;
+use std::collections::hash_map::DefaultHasher;
+
+#[derive(Debug)]
+pub struct IchHasher {
+ // FIXME: this should use SHA1, not DefaultHasher. DefaultHasher is not
+ // built to avoid collisions.
+ state: DefaultHasher,
+ bytes_hashed: u64,
+}
+
+impl IchHasher {
+ pub fn new() -> IchHasher {
+ IchHasher {
+ state: DefaultHasher::new(),
+ bytes_hashed: 0
+ }
+ }
+
+ pub fn bytes_hashed(&self) -> u64 {
+ self.bytes_hashed
+ }
+}
+
+impl Hasher for IchHasher {
+ #[inline]
+ fn finish(&self) -> u64 {
+ self.state.finish()
+ }
+
+ #[inline]
+ fn write(&mut self, bytes: &[u8]) {
+ self.state.write(bytes);
+ self.bytes_hashed += bytes.len() as u64;
+ }
+}
use syntax::ast;
use std::cell::RefCell;
use std::hash::{Hash, Hasher};
-use std::collections::hash_map::DefaultHasher;
use rustc::dep_graph::DepNode;
use rustc::hir;
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use self::def_path_hash::DefPathHashes;
use self::svh_visitor::StrictVersionHashVisitor;
use self::caching_codemap_view::CachingCodemapView;
+use self::hasher::IchHasher;
mod def_path_hash;
mod svh_visitor;
mod caching_codemap_view;
+mod hasher;
pub struct IncrementalHashesMap {
hashes: FnvHashMap<DepNode<DefId>, u64>,
pub fn iter<'a>(&'a self) -> ::std::collections::hash_map::Iter<'a, DepNode<DefId>, u64> {
self.hashes.iter()
}
+
+ pub fn len(&self) -> usize {
+ self.hashes.len()
+ }
}
impl<'a> ::std::ops::Index<&'a DepNode<DefId>> for IncrementalHashesMap {
|v| visit::walk_crate(v, krate));
krate.visit_all_items(&mut visitor);
});
+
+ tcx.sess.perf_stats.incr_comp_hashes_count.set(visitor.hashes.len() as u64);
+
record_time(&tcx.sess.perf_stats.svh_time, || visitor.compute_crate_hash());
visitor.hashes
}
{
assert!(def_id.is_local());
debug!("HashItemsVisitor::calculate(def_id={:?})", def_id);
- // FIXME: this should use SHA1, not DefaultHasher. DefaultHasher is not
- // built to avoid collisions.
- let mut state = DefaultHasher::new();
+ let mut state = IchHasher::new();
walk_op(&mut StrictVersionHashVisitor::new(&mut state,
self.tcx,
&mut self.def_path_hashes,
let item_hash = state.finish();
self.hashes.insert(DepNode::Hir(def_id), item_hash);
debug!("calculate_item_hash: def_id={:?} hash={:?}", def_id, item_hash);
+
+ let bytes_hashed = self.tcx.sess.perf_stats.incr_comp_bytes_hashed.get() +
+ state.bytes_hashed();
+ self.tcx.sess.perf_stats.incr_comp_bytes_hashed.set(bytes_hashed);
}
fn compute_crate_hash(&mut self) {
let krate = self.tcx.map.krate();
- let mut crate_state = DefaultHasher::new();
+ let mut crate_state = IchHasher::new();
let crate_disambiguator = self.tcx.sess.local_crate_disambiguator();
"crate_disambiguator".hash(&mut crate_state);
use rustc::ty::TyCtxt;
use rustc_data_structures::fnv;
use std::hash::Hash;
-use std::collections::hash_map::DefaultHasher;
use super::def_path_hash::DefPathHashes;
use super::caching_codemap_view::CachingCodemapView;
+use super::hasher::IchHasher;
const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
"cfg",
pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> {
pub tcx: TyCtxt<'hash, 'tcx, 'tcx>,
- pub st: &'a mut DefaultHasher,
+ pub st: &'a mut IchHasher,
// collect a deterministic hash of def-ids that we have seen
def_path_hashes: &'a mut DefPathHashes<'hash, 'tcx>,
hash_spans: bool,
}
impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
- pub fn new(st: &'a mut DefaultHasher,
+ pub fn new(st: &'a mut IchHasher,
tcx: TyCtxt<'hash, 'tcx, 'tcx>,
def_path_hashes: &'a mut DefPathHashes<'hash, 'tcx>,
codemap: &'a mut CachingCodemapView<'tcx>,