mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-23 22:14:15 +00:00
incr.comp.: Store result fingerprints in DepGraph.
This commit is contained in:
parent
25bc69ec20
commit
c4d1651266
@ -387,6 +387,17 @@ impl DefId {
|
||||
}
|
||||
}
|
||||
|
||||
impl DepKind {
|
||||
#[inline]
|
||||
pub fn fingerprint_needed_for_crate_hash(self) -> bool {
|
||||
match self {
|
||||
DepKind::HirBody |
|
||||
DepKind::Krate => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_dep_nodes!( <'tcx>
|
||||
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
|
||||
// distinct from the krate module). This is basically a hash of
|
||||
@ -401,13 +412,13 @@ define_dep_nodes!( <'tcx>
|
||||
// edges yourself for the individual items that you read.
|
||||
[input] Krate,
|
||||
|
||||
// Represents the HIR node with the given node-id
|
||||
[input] Hir(DefId),
|
||||
|
||||
// Represents the body of a function or method. The def-id is that of the
|
||||
// function/method.
|
||||
[input] HirBody(DefId),
|
||||
|
||||
// Represents the HIR node with the given node-id
|
||||
[input] Hir(DefId),
|
||||
|
||||
// Represents metadata from an extern crate.
|
||||
[input] MetaData(DefId),
|
||||
|
||||
|
@ -26,7 +26,8 @@ use super::edges::{DepGraphEdges, DepNodeIndex};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DepGraph {
|
||||
data: Option<Rc<DepGraphData>>
|
||||
data: Option<Rc<DepGraphData>>,
|
||||
fingerprints: Rc<RefCell<FxHashMap<DepNode, Fingerprint>>>
|
||||
}
|
||||
|
||||
struct DepGraphData {
|
||||
@ -57,7 +58,8 @@ impl DepGraph {
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
fingerprints: Rc::new(RefCell::new(FxHashMap())),
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,11 +141,27 @@ impl DepGraph {
|
||||
|
||||
let mut stable_hasher = StableHasher::new();
|
||||
result.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
let _: Fingerprint = stable_hasher.finish();
|
||||
|
||||
assert!(self.fingerprints
|
||||
.borrow_mut()
|
||||
.insert(key, stable_hasher.finish())
|
||||
.is_none());
|
||||
|
||||
(result, dep_node_index)
|
||||
} else {
|
||||
(task(cx, arg), DepNodeIndex::INVALID)
|
||||
if key.kind.fingerprint_needed_for_crate_hash() {
|
||||
let mut hcx = cx.create_stable_hashing_context();
|
||||
let result = task(cx, arg);
|
||||
let mut stable_hasher = StableHasher::new();
|
||||
result.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
assert!(self.fingerprints
|
||||
.borrow_mut()
|
||||
.insert(key, stable_hasher.finish())
|
||||
.is_none());
|
||||
(result, DepNodeIndex::INVALID)
|
||||
} else {
|
||||
(task(cx, arg), DepNodeIndex::INVALID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,6 +213,10 @@ impl DepGraph {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
|
||||
self.fingerprints.borrow().get(dep_node).cloned()
|
||||
}
|
||||
|
||||
/// Indicates that a previous work product exists for `v`. This is
|
||||
/// invoked during initial start-up based on what nodes are clean
|
||||
/// (and what files exist in the incr. directory).
|
||||
|
@ -16,6 +16,9 @@ use std::iter::repeat;
|
||||
use syntax::ast::{NodeId, CRATE_NODE_ID};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use ich::StableHashingContext;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
|
||||
|
||||
/// A Visitor that walks over the HIR and collects Nodes into a HIR map
|
||||
pub(super) struct NodeCollector<'a, 'hir> {
|
||||
/// The crate
|
||||
@ -26,36 +29,99 @@ pub(super) struct NodeCollector<'a, 'hir> {
|
||||
parent_node: NodeId,
|
||||
|
||||
current_dep_node_owner: DefIndex,
|
||||
current_dep_node_index: DepNodeIndex,
|
||||
current_signature_dep_index: DepNodeIndex,
|
||||
current_full_dep_index: DepNodeIndex,
|
||||
currently_in_body: bool,
|
||||
|
||||
dep_graph: &'a DepGraph,
|
||||
definitions: &'a definitions::Definitions,
|
||||
|
||||
hcx: StableHashingContext<'a>,
|
||||
|
||||
hir_body_nodes: Vec<DefPathHash>,
|
||||
}
|
||||
|
||||
impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
pub(super) fn root(krate: &'hir Crate,
|
||||
dep_graph: &'a DepGraph,
|
||||
definitions: &'a definitions::Definitions)
|
||||
dep_graph: &'a DepGraph,
|
||||
definitions: &'a definitions::Definitions,
|
||||
hcx: StableHashingContext<'a>)
|
||||
-> NodeCollector<'a, 'hir> {
|
||||
let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX);
|
||||
let root_mod_dep_node = root_mod_def_path_hash.to_dep_node(DepKind::Hir);
|
||||
let root_mod_dep_node_index = dep_graph.alloc_input_node(root_mod_dep_node);
|
||||
|
||||
// Allocate DepNodes for the root module
|
||||
let (root_mod_sig_dep_index, root_mod_full_dep_index);
|
||||
{
|
||||
let Crate {
|
||||
ref module,
|
||||
// Crate attributes are not copied over to the root `Mod`, so hash
|
||||
// them explicitly here.
|
||||
ref attrs,
|
||||
span,
|
||||
|
||||
// These fields are handled separately:
|
||||
exported_macros: _,
|
||||
items: _,
|
||||
trait_items: _,
|
||||
impl_items: _,
|
||||
bodies: _,
|
||||
trait_impls: _,
|
||||
trait_default_impl: _,
|
||||
body_ids: _,
|
||||
} = *krate;
|
||||
|
||||
root_mod_sig_dep_index = dep_graph.with_task(
|
||||
root_mod_def_path_hash.to_dep_node(DepKind::Hir),
|
||||
&hcx,
|
||||
HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
|
||||
identity_fn
|
||||
).1;
|
||||
root_mod_full_dep_index = dep_graph.with_task(
|
||||
root_mod_def_path_hash.to_dep_node(DepKind::HirBody),
|
||||
&hcx,
|
||||
HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
|
||||
identity_fn
|
||||
).1;
|
||||
}
|
||||
|
||||
let hir_body_nodes = vec![root_mod_def_path_hash];
|
||||
|
||||
let mut collector = NodeCollector {
|
||||
krate,
|
||||
map: vec![],
|
||||
parent_node: CRATE_NODE_ID,
|
||||
current_dep_node_index: root_mod_dep_node_index,
|
||||
current_signature_dep_index: root_mod_sig_dep_index,
|
||||
current_full_dep_index: root_mod_full_dep_index,
|
||||
current_dep_node_owner: CRATE_DEF_INDEX,
|
||||
currently_in_body: false,
|
||||
dep_graph,
|
||||
definitions,
|
||||
hcx,
|
||||
hir_body_nodes,
|
||||
};
|
||||
collector.insert_entry(CRATE_NODE_ID, RootCrate(root_mod_dep_node_index));
|
||||
collector.insert_entry(CRATE_NODE_ID, RootCrate(root_mod_sig_dep_index));
|
||||
|
||||
collector
|
||||
}
|
||||
|
||||
pub(super) fn into_map(self) -> Vec<MapEntry<'hir>> {
|
||||
pub(super) fn finalize_and_compute_crate_hash(self,
|
||||
crate_disambiguator: &str)
|
||||
-> Vec<MapEntry<'hir>> {
|
||||
let mut node_hashes: Vec<_> = self
|
||||
.hir_body_nodes
|
||||
.iter()
|
||||
.map(|&def_path_hash| {
|
||||
let dep_node = def_path_hash.to_dep_node(DepKind::HirBody);
|
||||
(def_path_hash, self.dep_graph.fingerprint_of(&dep_node))
|
||||
})
|
||||
.collect();
|
||||
|
||||
node_hashes.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
|
||||
|
||||
self.dep_graph.with_task(DepNode::new_no_params(DepKind::Krate),
|
||||
&self.hcx,
|
||||
(node_hashes, crate_disambiguator),
|
||||
identity_fn);
|
||||
self.map
|
||||
}
|
||||
|
||||
@ -70,7 +136,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
|
||||
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
|
||||
let parent = self.parent_node;
|
||||
let dep_node_index = self.current_dep_node_index;
|
||||
let dep_node_index = if self.currently_in_body {
|
||||
self.current_full_dep_index
|
||||
} else {
|
||||
self.current_signature_dep_index
|
||||
};
|
||||
|
||||
let entry = match node {
|
||||
NodeItem(n) => EntryItem(parent, dep_node_index, n),
|
||||
@ -91,6 +161,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
NodeTyParam(n) => EntryTyParam(parent, dep_node_index, n),
|
||||
NodeVisibility(n) => EntryVisibility(parent, dep_node_index, n),
|
||||
NodeLocal(n) => EntryLocal(parent, dep_node_index, n),
|
||||
NodeMacroDef(n) => EntryMacroDef(dep_node_index, n),
|
||||
};
|
||||
|
||||
// Make sure that the DepNode of some node coincides with the HirId
|
||||
@ -127,22 +198,41 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
self.parent_node = parent_node;
|
||||
}
|
||||
|
||||
fn with_dep_node_owner<F: FnOnce(&mut Self)>(&mut self,
|
||||
fn with_dep_node_owner<T: HashStable<StableHashingContext<'a>>,
|
||||
F: FnOnce(&mut Self)>(&mut self,
|
||||
dep_node_owner: DefIndex,
|
||||
item_like: &T,
|
||||
f: F) {
|
||||
let prev_owner = self.current_dep_node_owner;
|
||||
let prev_index = self.current_dep_node_index;
|
||||
let prev_signature_dep_index = self.current_signature_dep_index;
|
||||
let prev_full_dep_index = self.current_signature_dep_index;
|
||||
let prev_in_body = self.currently_in_body;
|
||||
|
||||
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
|
||||
|
||||
self.current_signature_dep_index = self.dep_graph.with_task(
|
||||
def_path_hash.to_dep_node(DepKind::Hir),
|
||||
&self.hcx,
|
||||
HirItemLike { item_like, hash_bodies: false },
|
||||
identity_fn
|
||||
).1;
|
||||
|
||||
self.current_full_dep_index = self.dep_graph.with_task(
|
||||
def_path_hash.to_dep_node(DepKind::HirBody),
|
||||
&self.hcx,
|
||||
HirItemLike { item_like, hash_bodies: true },
|
||||
identity_fn
|
||||
).1;
|
||||
|
||||
self.hir_body_nodes.push(def_path_hash);
|
||||
|
||||
// When we enter a new owner (item, impl item, or trait item), we always
|
||||
// start out again with DepKind::Hir.
|
||||
let new_dep_node = self.definitions
|
||||
.def_path_hash(dep_node_owner)
|
||||
.to_dep_node(DepKind::Hir);
|
||||
self.current_dep_node_index = self.dep_graph.alloc_input_node(new_dep_node);
|
||||
self.current_dep_node_owner = dep_node_owner;
|
||||
self.currently_in_body = false;
|
||||
f(self);
|
||||
self.current_dep_node_index = prev_index;
|
||||
self.currently_in_body = prev_in_body;
|
||||
self.current_dep_node_owner = prev_owner;
|
||||
self.current_full_dep_index = prev_full_dep_index;
|
||||
self.current_signature_dep_index = prev_signature_dep_index;
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,24 +259,17 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
}
|
||||
|
||||
fn visit_nested_body(&mut self, id: BodyId) {
|
||||
// When we enter a body, we switch to DepKind::HirBody.
|
||||
// Note that current_dep_node_index might already be DepKind::HirBody,
|
||||
// e.g. when entering the body of a closure that is already part of a
|
||||
// surrounding body. That's expected and not a problem.
|
||||
let prev_index = self.current_dep_node_index;
|
||||
let new_dep_node = self.definitions
|
||||
.def_path_hash(self.current_dep_node_owner)
|
||||
.to_dep_node(DepKind::HirBody);
|
||||
self.current_dep_node_index = self.dep_graph.alloc_input_node(new_dep_node);
|
||||
let prev_in_body = self.currently_in_body;
|
||||
self.currently_in_body = true;
|
||||
self.visit_body(self.krate.body(id));
|
||||
self.current_dep_node_index = prev_index;
|
||||
self.currently_in_body = prev_in_body;
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &'hir Item) {
|
||||
debug!("visit_item: {:?}", i);
|
||||
debug_assert_eq!(i.hir_id.owner,
|
||||
self.definitions.opt_def_index(i.id).unwrap());
|
||||
self.with_dep_node_owner(i.hir_id.owner, |this| {
|
||||
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
|
||||
this.insert(i.id, NodeItem(i));
|
||||
this.with_parent(i.id, |this| {
|
||||
match i.node {
|
||||
@ -222,7 +305,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
|
||||
debug_assert_eq!(ti.hir_id.owner,
|
||||
self.definitions.opt_def_index(ti.id).unwrap());
|
||||
self.with_dep_node_owner(ti.hir_id.owner, |this| {
|
||||
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
|
||||
this.insert(ti.id, NodeTraitItem(ti));
|
||||
|
||||
this.with_parent(ti.id, |this| {
|
||||
@ -234,7 +317,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
|
||||
debug_assert_eq!(ii.hir_id.owner,
|
||||
self.definitions.opt_def_index(ii.id).unwrap());
|
||||
self.with_dep_node_owner(ii.hir_id.owner, |this| {
|
||||
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
|
||||
this.insert(ii.id, NodeImplItem(ii));
|
||||
|
||||
this.with_parent(ii.id, |this| {
|
||||
@ -328,7 +411,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
|
||||
self.insert_entry(macro_def.id, NotPresent);
|
||||
let def_index = self.definitions.opt_def_index(macro_def.id).unwrap();
|
||||
|
||||
self.with_dep_node_owner(def_index, macro_def, |this| {
|
||||
this.insert(macro_def.id, NodeMacroDef(macro_def));
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
|
||||
@ -375,3 +462,25 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
self.visit_nested_impl_item(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn identity_fn<T>(_: &StableHashingContext, item_like: T) -> T {
|
||||
item_like
|
||||
}
|
||||
|
||||
struct HirItemLike<T> {
|
||||
item_like: T,
|
||||
hash_bodies: bool,
|
||||
}
|
||||
|
||||
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
|
||||
where T: HashStable<StableHashingContext<'hir>>
|
||||
{
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'hir>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
|
||||
self.item_like.hash_stable(hcx, hasher);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ pub enum Node<'hir> {
|
||||
NodePat(&'hir Pat),
|
||||
NodeBlock(&'hir Block),
|
||||
NodeLocal(&'hir Local),
|
||||
NodeMacroDef(&'hir MacroDef),
|
||||
|
||||
/// NodeStructCtor represents a tuple struct.
|
||||
NodeStructCtor(&'hir VariantData),
|
||||
@ -93,6 +94,8 @@ enum MapEntry<'hir> {
|
||||
EntryVisibility(NodeId, DepNodeIndex, &'hir Visibility),
|
||||
EntryLocal(NodeId, DepNodeIndex, &'hir Local),
|
||||
|
||||
EntryMacroDef(DepNodeIndex, &'hir MacroDef),
|
||||
|
||||
/// Roots for node trees. The DepNodeIndex is the dependency node of the
|
||||
/// crate's root module.
|
||||
RootCrate(DepNodeIndex),
|
||||
@ -127,6 +130,7 @@ impl<'hir> MapEntry<'hir> {
|
||||
EntryLocal(id, _, _) => id,
|
||||
|
||||
NotPresent |
|
||||
EntryMacroDef(..) |
|
||||
RootCrate(_) => return None,
|
||||
})
|
||||
}
|
||||
@ -151,6 +155,7 @@ impl<'hir> MapEntry<'hir> {
|
||||
EntryTyParam(_, _, n) => NodeTyParam(n),
|
||||
EntryVisibility(_, _, n) => NodeVisibility(n),
|
||||
EntryLocal(_, _, n) => NodeLocal(n),
|
||||
EntryMacroDef(_, n) => NodeMacroDef(n),
|
||||
|
||||
NotPresent |
|
||||
RootCrate(_) => return None
|
||||
@ -285,20 +290,12 @@ impl<'hir> Map<'hir> {
|
||||
EntryVisibility(_, dep_node_index, _) |
|
||||
EntryExpr(_, dep_node_index, _) |
|
||||
EntryLocal(_, dep_node_index, _) |
|
||||
EntryMacroDef(dep_node_index, _) |
|
||||
RootCrate(dep_node_index) => {
|
||||
self.dep_graph.read_index(dep_node_index);
|
||||
}
|
||||
NotPresent => {
|
||||
// Some nodes, notably macro definitions, are not
|
||||
// present in the map for whatever reason, but
|
||||
// they *do* have def-ids. So if we encounter an
|
||||
// empty hole, check for that case.
|
||||
if let Some(def_index) = self.definitions.opt_def_index(id) {
|
||||
let def_path_hash = self.definitions.def_path_hash(def_index);
|
||||
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::Hir));
|
||||
} else {
|
||||
bug!("called HirMap::read() with invalid NodeId")
|
||||
}
|
||||
bug!("called HirMap::read() with invalid NodeId")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -875,6 +872,7 @@ impl<'hir> Map<'hir> {
|
||||
Some(EntryVisibility(_, _, &Visibility::Restricted { ref path, .. })) => path.span,
|
||||
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
|
||||
Some(EntryLocal(_, _, local)) => local.span,
|
||||
Some(EntryMacroDef(_, macro_def)) => macro_def.span,
|
||||
|
||||
Some(RootCrate(_)) => self.forest.krate.span,
|
||||
Some(NotPresent) | None => {
|
||||
@ -1012,15 +1010,22 @@ impl Named for StructField { fn name(&self) -> Name { self.name } }
|
||||
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
|
||||
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
|
||||
|
||||
pub fn map_crate<'hir>(forest: &'hir mut Forest,
|
||||
pub fn map_crate<'hir>(sess: &::session::Session,
|
||||
cstore: &::middle::cstore::CrateStore,
|
||||
forest: &'hir mut Forest,
|
||||
definitions: &'hir Definitions)
|
||||
-> Map<'hir> {
|
||||
let map = {
|
||||
let hcx = ::ich::StableHashingContext::new(sess, &forest.krate, definitions, cstore);
|
||||
|
||||
let mut collector = NodeCollector::root(&forest.krate,
|
||||
&forest.dep_graph,
|
||||
&definitions);
|
||||
&definitions,
|
||||
hcx);
|
||||
intravisit::walk_crate(&mut collector, &forest.krate);
|
||||
collector.into_map()
|
||||
|
||||
let crate_disambiguator = sess.local_crate_disambiguator().as_str();
|
||||
collector.finalize_and_compute_crate_hash(&crate_disambiguator)
|
||||
};
|
||||
|
||||
if log_enabled!(::log::LogLevel::Debug) {
|
||||
@ -1103,6 +1108,7 @@ impl<'a> print::State<'a> {
|
||||
// printing.
|
||||
NodeStructCtor(_) => bug!("cannot print isolated StructCtor"),
|
||||
NodeLocal(a) => self.print_local_decl(&a),
|
||||
NodeMacroDef(_) => bug!("cannot print MacroDef"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1219,6 +1225,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
||||
Some(NodeVisibility(ref vis)) => {
|
||||
format!("visibility {:?}{}", vis, id_str)
|
||||
}
|
||||
Some(NodeMacroDef(_)) => {
|
||||
format!("macro {}{}", path_str(), id_str)
|
||||
}
|
||||
None => {
|
||||
format!("unknown node{}", id_str)
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ struct CacheEntry {
|
||||
file_index: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CachingCodemapView<'cm> {
|
||||
codemap: &'cm CodeMap,
|
||||
line_cache: [CacheEntry; 3],
|
||||
|
@ -43,6 +43,7 @@ thread_local!(static IGNORED_ATTR_NAMES: RefCell<FxHashSet<Symbol>> =
|
||||
/// enough information to transform DefIds and HirIds into stable DefPaths (i.e.
|
||||
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
|
||||
/// things (e.g. each DefId/DefPath is only hashed once).
|
||||
#[derive(Clone)]
|
||||
pub struct StableHashingContext<'gcx> {
|
||||
sess: &'gcx Session,
|
||||
definitions: &'gcx Definitions,
|
||||
@ -264,6 +265,18 @@ impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'gcx> StableHashingContextProvider for StableHashingContext<'gcx> {
|
||||
type ContextType = StableHashingContext<'gcx>;
|
||||
fn create_stable_hashing_context(&self) -> Self::ContextType {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gcx> ::dep_graph::DepGraphSafe for StableHashingContext<'gcx> {
|
||||
}
|
||||
|
||||
|
||||
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::BodyId {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'gcx>,
|
||||
|
@ -691,7 +691,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::TraitItem {
|
||||
hcx: &mut StableHashingContext<'gcx>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::TraitItem {
|
||||
id,
|
||||
id: _,
|
||||
hir_id: _,
|
||||
name,
|
||||
ref attrs,
|
||||
@ -700,7 +700,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::TraitItem {
|
||||
} = *self;
|
||||
|
||||
hcx.hash_hir_item_like(attrs, |hcx| {
|
||||
id.hash_stable(hcx, hasher);
|
||||
name.hash_stable(hcx, hasher);
|
||||
attrs.hash_stable(hcx, hasher);
|
||||
node.hash_stable(hcx, hasher);
|
||||
@ -725,7 +724,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::ImplItem {
|
||||
hcx: &mut StableHashingContext<'gcx>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::ImplItem {
|
||||
id,
|
||||
id: _,
|
||||
hir_id: _,
|
||||
name,
|
||||
ref vis,
|
||||
@ -736,7 +735,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::ImplItem {
|
||||
} = *self;
|
||||
|
||||
hcx.hash_hir_item_like(attrs, |hcx| {
|
||||
id.hash_stable(hcx, hasher);
|
||||
name.hash_stable(hcx, hasher);
|
||||
vis.hash_stable(hcx, hasher);
|
||||
defaultness.hash_stable(hcx, hasher);
|
||||
|
@ -310,7 +310,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
hir_map::NodeVariant(_) |
|
||||
hir_map::NodeStructCtor(_) |
|
||||
hir_map::NodeField(_) |
|
||||
hir_map::NodeTy(_) => {}
|
||||
hir_map::NodeTy(_) |
|
||||
hir_map::NodeMacroDef(_) => {}
|
||||
_ => {
|
||||
bug!("found unexpected thingy in worklist: {}",
|
||||
self.tcx.hir.node_to_string(search_item))
|
||||
|
@ -1236,6 +1236,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
self.hir.definitions(),
|
||||
self.cstore)
|
||||
}
|
||||
|
||||
pub fn precompute_in_scope_traits_hashes(self) {
|
||||
for &def_index in self.trait_map.keys() {
|
||||
self.in_scope_traits_map(def_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
|
@ -175,7 +175,7 @@ pub fn compile_input(sess: &Session,
|
||||
// Construct the HIR map
|
||||
let hir_map = time(sess.time_passes(),
|
||||
"indexing hir",
|
||||
|| hir_map::map_crate(&mut hir_forest, &defs));
|
||||
|| hir_map::map_crate(sess, cstore, &mut hir_forest, &defs));
|
||||
|
||||
{
|
||||
let _ignore = hir_map.dep_graph.in_ignore();
|
||||
|
@ -18,7 +18,6 @@ use rustc_data_structures::flock;
|
||||
use rustc_serialize::Decodable;
|
||||
use rustc_serialize::opaque::Decoder;
|
||||
|
||||
use IncrementalHashesMap;
|
||||
use super::data::*;
|
||||
use super::fs::*;
|
||||
use super::file_format;
|
||||
@ -28,18 +27,14 @@ use std::fmt::Debug;
|
||||
|
||||
pub struct HashContext<'a, 'tcx: 'a> {
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
incremental_hashes_map: &'a IncrementalHashesMap,
|
||||
metadata_hashes: FxHashMap<DefId, Fingerprint>,
|
||||
crate_hashes: FxHashMap<CrateNum, Svh>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> HashContext<'a, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
incremental_hashes_map: &'a IncrementalHashesMap)
|
||||
-> Self {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
|
||||
HashContext {
|
||||
tcx,
|
||||
incremental_hashes_map,
|
||||
metadata_hashes: FxHashMap(),
|
||||
crate_hashes: FxHashMap(),
|
||||
}
|
||||
@ -47,15 +42,12 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
|
||||
|
||||
pub fn hash(&mut self, dep_node: &DepNode) -> Option<Fingerprint> {
|
||||
match dep_node.kind {
|
||||
DepKind::Krate => {
|
||||
Some(self.incremental_hashes_map[dep_node])
|
||||
}
|
||||
|
||||
// HIR nodes (which always come from our crate) are an input:
|
||||
DepKind::Krate |
|
||||
DepKind::InScopeTraits |
|
||||
DepKind::Hir |
|
||||
DepKind::HirBody => {
|
||||
Some(self.incremental_hashes_map[dep_node])
|
||||
Some(self.tcx.dep_graph.fingerprint_of(dep_node).unwrap())
|
||||
}
|
||||
|
||||
// MetaData from other crates is an *input* to us.
|
||||
|
@ -42,6 +42,7 @@ pub type DirtyNodes = FxHashMap<DepNodeIndex, DepNodeIndex>;
|
||||
/// more general overview.
|
||||
pub fn load_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
incremental_hashes_map: &IncrementalHashesMap) {
|
||||
tcx.precompute_in_scope_traits_hashes();
|
||||
if tcx.sess.incr_session_load_dep_graph() {
|
||||
let _ignore = tcx.dep_graph.in_ignore();
|
||||
load_dep_graph_if_exists(tcx, incremental_hashes_map);
|
||||
@ -150,7 +151,6 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
// Compute the set of nodes from the old graph where some input
|
||||
// has changed or been removed.
|
||||
let dirty_raw_nodes = initial_dirty_nodes(tcx,
|
||||
incremental_hashes_map,
|
||||
&serialized_dep_graph.nodes,
|
||||
&serialized_dep_graph.hashes);
|
||||
let dirty_raw_nodes = transitive_dirty_nodes(&serialized_dep_graph,
|
||||
@ -202,11 +202,10 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
/// Computes which of the original set of def-ids are dirty. Stored in
|
||||
/// a bit vector where the index is the DefPathIndex.
|
||||
fn initial_dirty_nodes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
incremental_hashes_map: &IncrementalHashesMap,
|
||||
nodes: &IndexVec<DepNodeIndex, DepNode>,
|
||||
serialized_hashes: &[(DepNodeIndex, Fingerprint)])
|
||||
-> DirtyNodes {
|
||||
let mut hcx = HashContext::new(tcx, incremental_hashes_map);
|
||||
let mut hcx = HashContext::new(tcx);
|
||||
let mut dirty_nodes = FxHashMap();
|
||||
|
||||
for &(dep_node_index, prev_hash) in serialized_hashes {
|
||||
|
@ -51,7 +51,7 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
eprintln!("incremental: {} edges in dep-graph", query.graph.len_edges());
|
||||
}
|
||||
|
||||
let mut hcx = HashContext::new(tcx, &incremental_hashes_map);
|
||||
let mut hcx = HashContext::new(tcx);
|
||||
let preds = Predecessors::new(&query, &mut hcx);
|
||||
let mut current_metadata_hashes = FxHashMap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user