]> git.lizzy.rs Git - rust.git/commitdiff
Clean up the collector
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 8 Feb 2020 04:18:34 +0000 (05:18 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 14 Mar 2020 21:52:29 +0000 (22:52 +0100)
src/librustc/hir/map/collector.rs
src/librustc/hir/map/hir_id_validator.rs
src/librustc/hir/map/mod.rs
src/librustc/hir/mod.rs
src/librustc/ty/context.rs
src/librustc_interface/passes.rs

index 5c2808fee0d9923d7c005ee0e529cec6a640733c..b9ab43ed289ca193de064daf8fb7d65b28f0b4b8 100644 (file)
@@ -1,7 +1,6 @@
 use crate::arena::Arena;
-use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
 use crate::hir::map::definitions::{self, DefPathHash};
-use crate::hir::map::{Entry, HirEntryMap, Map};
+use crate::hir::map::{Entry, Map};
 use crate::hir::{HirItem, HirOwner, HirOwnerItems};
 use crate::ich::StableHashingContext;
 use crate::middle::cstore::CrateStore;
@@ -35,70 +34,38 @@ pub(super) struct NodeCollector<'a, 'hir> {
     owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
     owner_items_map: FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
 
-    /// The node map
-    map: HirEntryMap<'hir>,
     /// The parent of this node
     parent_node: hir::HirId,
 
-    // These fields keep track of the currently relevant DepNodes during
-    // the visitor's traversal.
     current_dep_node_owner: DefIndex,
-    current_signature_dep_index: DepNodeIndex,
-    current_full_dep_index: DepNodeIndex,
-    currently_in_body: bool,
 
-    dep_graph: &'a DepGraph,
     definitions: &'a definitions::Definitions,
     hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
 
     hcx: StableHashingContext<'a>,
 
     // We are collecting `DepNode::HirBody` hashes here so we can compute the
-    // crate hash from then later on.
+    // crate hash from them later on.
     hir_body_nodes: Vec<(DefPathHash, Fingerprint)>,
 }
 
-fn input_dep_node_and_hash(
-    dep_graph: &DepGraph,
+fn hash(
     hcx: &mut StableHashingContext<'_>,
-    dep_node: DepNode,
     input: impl for<'a> HashStable<StableHashingContext<'a>>,
-) -> (DepNodeIndex, Fingerprint) {
-    let dep_node_index = dep_graph.input_task(dep_node, &mut *hcx, &input).1;
-
-    let hash = if dep_graph.is_fully_enabled() {
-        dep_graph.fingerprint_of(dep_node_index)
-    } else {
-        let mut stable_hasher = StableHasher::new();
-        input.hash_stable(hcx, &mut stable_hasher);
-        stable_hasher.finish()
-    };
-
-    (dep_node_index, hash)
+) -> Fingerprint {
+    let mut stable_hasher = StableHasher::new();
+    input.hash_stable(hcx, &mut stable_hasher);
+    stable_hasher.finish()
 }
 
-fn alloc_hir_dep_nodes(
-    dep_graph: &DepGraph,
+fn hash_body(
     hcx: &mut StableHashingContext<'_>,
     def_path_hash: DefPathHash,
     item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
     hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
-) -> (DepNodeIndex, DepNodeIndex) {
-    let sig = dep_graph
-        .input_task(
-            DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
-            &mut *hcx,
-            HirItemLike { item_like: &item_like, hash_bodies: false },
-        )
-        .1;
-    let (full, hash) = input_dep_node_and_hash(
-        dep_graph,
-        hcx,
-        DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
-        HirItemLike { item_like: &item_like, hash_bodies: true },
-    );
+) {
+    let hash = hash(hcx, HirItemLike { item_like: &item_like });
     hir_body_nodes.push((def_path_hash, hash));
-    (sig, full)
 }
 
 fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> {
@@ -121,7 +88,6 @@ pub(super) fn root(
         sess: &'a Session,
         arena: &'hir Arena<'hir>,
         krate: &'hir Crate<'hir>,
-        dep_graph: &'a DepGraph,
         definitions: &'a definitions::Definitions,
         hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
         mut hcx: StableHashingContext<'a>,
@@ -130,8 +96,7 @@ pub(super) fn root(
 
         let mut hir_body_nodes = Vec::new();
 
-        // Allocate `DepNode`s for the root module.
-        let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
+        {
             let Crate {
                 ref item,
                 // These fields are handled separately:
@@ -147,40 +112,31 @@ pub(super) fn root(
                 proc_macros: _,
             } = *krate;
 
-            alloc_hir_dep_nodes(
-                dep_graph,
-                &mut hcx,
-                root_mod_def_path_hash,
-                item,
-                &mut hir_body_nodes,
-            )
+            hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)
         };
 
         let mut collector = NodeCollector {
             arena,
             krate,
             source_map: sess.source_map(),
-            map: IndexVec::from_elem_n(IndexVec::new(), definitions.def_index_count()),
             parent_node: hir::CRATE_HIR_ID,
-            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,
             hir_to_node_id,
             hcx,
             hir_body_nodes,
-            owner_map: FxHashMap::default(),
-            owner_items_map: FxHashMap::default(),
+            owner_map: FxHashMap::with_capacity_and_hasher(
+                definitions.def_index_count(),
+                Default::default(),
+            ),
+            owner_items_map: FxHashMap::with_capacity_and_hasher(
+                definitions.def_index_count(),
+                Default::default(),
+            ),
         };
         collector.insert_entry(
             hir::CRATE_HIR_ID,
-            Entry {
-                parent: hir::CRATE_HIR_ID,
-                dep_node: root_mod_sig_dep_index,
-                node: Node::Crate(&krate.item),
-            },
+            Entry { parent: hir::CRATE_HIR_ID, node: Node::Crate(&krate.item) },
         );
 
         collector
@@ -192,7 +148,6 @@ pub(super) fn finalize_and_compute_crate_hash(
         cstore: &dyn CrateStore,
         commandline_args_hash: u64,
     ) -> (
-        HirEntryMap<'hir>,
         FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
         FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
         Svh,
@@ -239,7 +194,7 @@ pub(super) fn finalize_and_compute_crate_hash(
         let crate_hash: Fingerprint = stable_hasher.finish();
 
         let svh = Svh::new(crate_hash.to_smaller_hash());
-        (self.map, self.owner_map, self.owner_items_map, svh)
+        (self.owner_map, self.owner_items_map, svh)
     }
 
     fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
@@ -266,26 +221,10 @@ fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
             items.items[id.local_id] =
                 Some(HirItem { parent: entry.parent.local_id, node: entry.node });
         }
-
-        debug!("hir_map: {:?} => {:?}", id, entry);
-        let local_map = &mut self.map[id.owner];
-        let len = local_map.len();
-        if i >= len {
-            local_map.extend(repeat(None).take(i - len + 1));
-        }
-        local_map[id.local_id] = Some(entry);
     }
 
     fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
-        let entry = Entry {
-            parent: self.parent_node,
-            dep_node: if self.currently_in_body {
-                self.current_full_dep_index
-            } else {
-                self.current_signature_dep_index
-            },
-            node,
-        };
+        let entry = Entry { parent: self.parent_node, node };
 
         // Make sure that the DepNode of some node coincides with the HirId
         // owner of that node.
@@ -340,29 +279,14 @@ fn with_dep_node_owner<
         f: F,
     ) {
         let prev_owner = self.current_dep_node_owner;
-        let prev_signature_dep_index = self.current_signature_dep_index;
-        let prev_full_dep_index = self.current_full_dep_index;
-        let prev_in_body = self.currently_in_body;
 
         let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
 
-        let (signature_dep_index, full_dep_index) = alloc_hir_dep_nodes(
-            self.dep_graph,
-            &mut self.hcx,
-            def_path_hash,
-            item_like,
-            &mut self.hir_body_nodes,
-        );
-        self.current_signature_dep_index = signature_dep_index;
-        self.current_full_dep_index = full_dep_index;
+        hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes);
 
         self.current_dep_node_owner = dep_node_owner;
-        self.currently_in_body = false;
         f(self);
-        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;
     }
 }
 
@@ -391,10 +315,7 @@ fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
     }
 
     fn visit_nested_body(&mut self, id: BodyId) {
-        let prev_in_body = self.currently_in_body;
-        self.currently_in_body = true;
         self.visit_body(self.krate.body(id));
-        self.currently_in_body = prev_in_body;
     }
 
     fn visit_param(&mut self, param: &'hir Param<'hir>) {
@@ -617,11 +538,8 @@ fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef<'hir>) {
     }
 }
 
-// This is a wrapper structure that allows determining if span values within
-// the wrapped item should be hashed or not.
 struct HirItemLike<T> {
     item_like: T,
-    hash_bodies: bool,
 }
 
 impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
@@ -629,7 +547,7 @@ impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
     T: HashStable<StableHashingContext<'hir>>,
 {
     fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
-        hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
+        hcx.while_hashing_hir_bodies(true, |hcx| {
             self.item_like.hash_stable(hcx, hasher);
         });
     }
index ef000f23d8baf26fab15582c9d669b7056523e05..0c6415a1308a5be761df4e7f1defb3797ce12166 100644 (file)
@@ -8,8 +8,8 @@
 use rustc_hir::{HirId, ItemLocalId};*/
 
 pub fn check_crate(hir_map: &EarlyMap<'_>, sess: &rustc_session::Session) {
-    hir_map.dep_graph.assert_ignored();
-    /*
+    /*hir_map.dep_graph.assert_ignored();
+
     let errors = Lock::new(Vec::new());
 
     par_iter(&hir_map.krate.modules).for_each(|(module_id, _)| {
index 7604aeb8766261341b704e70b8e77885f30ecc23..96ee938a1725840110ac0c9a40c45a7e8b4a7ffa 100644 (file)
@@ -4,7 +4,6 @@
 };
 
 use crate::arena::Arena;
-use crate::dep_graph::{DepGraph, DepNodeIndex};
 use crate::hir::{HirOwner, HirOwnerItems};
 use crate::middle::cstore::CrateStoreDyn;
 use crate::ty::query::Providers;
@@ -18,7 +17,6 @@
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
 use rustc_hir::print::Nested;
 use rustc_hir::*;
-use rustc_index::vec::IndexVec;
 use rustc_span::hygiene::MacroKind;
 use rustc_span::source_map::Spanned;
 use rustc_span::symbol::kw;
@@ -34,7 +32,6 @@
 #[derive(Copy, Clone, Debug)]
 pub struct Entry<'hir> {
     parent: HirId,
-    dep_node: DepNodeIndex,
     node: Node<'hir>,
 }
 
@@ -132,26 +129,16 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
     }
 }
 
-/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
-/// but it is implemented as 2 layers of arrays.
-/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
-/// - which is `B = IndexVec<ItemLocalId, Option<Entry<'hir>>` which gives you the `Entry`.
-pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Option<Entry<'hir>>>>;
-
 /// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
 pub struct EarlyMap<'hir> {
     pub krate: &'hir Crate<'hir>,
 
-    pub dep_graph: DepGraph,
-
     /// The SVH of the local crate.
     pub crate_hash: Svh,
 
     pub(super) owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
     pub(super) owner_items_map: FxHashMap<DefIndex, &'hir HirOwnerItems<'hir>>,
 
-    pub(super) map: HirEntryMap<'hir>,
-
     pub(crate) definitions: &'hir Definitions,
 
     /// The reverse mapping of `node_to_hir_id`.
@@ -164,8 +151,6 @@ pub struct Map<'hir> {
 
     pub(super) krate: &'hir Crate<'hir>,
 
-    pub dep_graph: DepGraph,
-
     /// The SVH of the local crate.
     pub crate_hash: Svh,
 
@@ -383,15 +368,11 @@ fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
     fn get_entry(&self, id: HirId) -> Entry<'hir> {
         if id.local_id == ItemLocalId::from_u32_const(0) {
             let owner = self.tcx.hir_owner(id.owner_def_id());
-            Entry { parent: owner.parent, node: owner.node, dep_node: DepNodeIndex::INVALID }
+            Entry { parent: owner.parent, node: owner.node }
         } else {
             let owner = self.tcx.hir_owner_items(id.owner_def_id());
             let item = owner.items[id.local_id].as_ref().unwrap();
-            Entry {
-                parent: HirId { owner: id.owner, local_id: item.parent },
-                node: item.node,
-                dep_node: DepNodeIndex::INVALID,
-            }
+            Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node }
         }
     }
 
@@ -1069,7 +1050,6 @@ pub fn map_crate<'hir>(
     arena: &'hir Arena<'hir>,
     cstore: &CrateStoreDyn,
     krate: &'hir Crate<'hir>,
-    dep_graph: DepGraph,
     definitions: Definitions,
 ) -> EarlyMap<'hir> {
     let _prof_timer = sess.prof.generic_activity("build_hir_map");
@@ -1081,11 +1061,11 @@ pub fn map_crate<'hir>(
         .map(|(node_id, &hir_id)| (hir_id, node_id))
         .collect();
 
-    let (map, owner_map, owner_items_map, crate_hash) = {
+    let (owner_map, owner_items_map, crate_hash) = {
         let hcx = crate::ich::StableHashingContext::new(sess, krate, &definitions, cstore);
 
         let mut collector =
-            NodeCollector::root(sess, arena, krate, &dep_graph, &definitions, &hir_to_node_id, hcx);
+            NodeCollector::root(sess, arena, krate, &definitions, &hir_to_node_id, hcx);
         intravisit::walk_crate(&mut collector, krate);
 
         let crate_disambiguator = sess.local_crate_disambiguator();
@@ -1095,9 +1075,7 @@ pub fn map_crate<'hir>(
 
     let map = EarlyMap {
         krate,
-        dep_graph,
         crate_hash,
-        map,
         owner_map,
         owner_items_map: owner_items_map.into_iter().map(|(k, v)| (k, &*v)).collect(),
         hir_to_node_id,
index 34cfff999a71cefb9eb441537a40c06310d0a622..590ad1b69956d4329fe244f90d4a3863346f3302 100644 (file)
@@ -100,8 +100,6 @@ pub fn provide(providers: &mut Providers<'_>) {
             tcx,
             krate: early.krate,
 
-            dep_graph: early.dep_graph,
-
             crate_hash: early.crate_hash,
 
             owner_map: early.owner_map,
index cff93015d047f78ab3287edc69f4910228bdd554..0d6c185e8ed1304dd3ede329d75d2242cc436319 100644 (file)
@@ -1121,6 +1121,7 @@ pub fn create_global_ctxt(
         arena: &'tcx WorkerLocal<Arena<'tcx>>,
         resolutions: ty::ResolverOutputs,
         hir: hir_map::EarlyMap<'tcx>,
+        dep_graph: DepGraph,
         on_disk_query_result_cache: query::OnDiskCache<'tcx>,
         crate_name: &str,
         output_filenames: &OutputFilenames,
@@ -1132,7 +1133,6 @@ pub fn create_global_ctxt(
         let common_types = CommonTypes::new(&interners);
         let common_lifetimes = CommonLifetimes::new(&interners);
         let common_consts = CommonConsts::new(&interners, &common_types);
-        let dep_graph = hir.dep_graph.clone();
         let definitions = hir.definitions;
         let cstore = resolutions.cstore;
         let crates = cstore.crates_untracked();
index 7035b956c9d8544137facbfe62e12dcab5177973..c1a373bb06b2b83c5dd3596ca2707af62e367b57 100644 (file)
@@ -716,7 +716,7 @@ pub fn create_global_ctxt<'tcx>(
     let defs = mem::take(&mut resolver_outputs.definitions);
 
     // Construct the HIR map.
-    let hir_map = map::map_crate(sess, &**arena, &*resolver_outputs.cstore, krate, dep_graph, defs);
+    let hir_map = map::map_crate(sess, &**arena, &*resolver_outputs.cstore, krate, defs);
 
     let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
 
@@ -743,6 +743,7 @@ pub fn create_global_ctxt<'tcx>(
                 arena,
                 resolver_outputs,
                 hir_map,
+                dep_graph,
                 query_result_on_disk_cache,
                 &crate_name,
                 &outputs,