about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-05-29 17:10:08 +0000
committerbors <bors@rust-lang.org>2017-05-29 17:10:08 +0000
commitd78c2b483eda9538b55e2f79558032d9ccb286a0 (patch)
treee46c356a5fd26cdb8f82239c6887ffc76ca6f6fe
parent03bed655142dd5e42ba4539de53b3663d8a123e0 (diff)
parentc150301a5bae96c504c7b957d6b929a1ed1ba6fb (diff)
Auto merge of #42192 - michaelwoerister:no_deptracking_map_in_queries, r=nikomatsakis
incr.comp.: Remove DepGraph::write() and its callers

After months of yak shaving, we are finally there `:)`

The existence of `DepGraph::write()` was one of the two main ways for introducing cycles into the dep-graph -- something we need to avoid in the future. The other way, re-opening nodes to add more edges, is next on the list.

r? @nikomatsakis
-rw-r--r--src/librustc/dep_graph/dep_tracking_map.rs19
-rw-r--r--src/librustc/dep_graph/graph.rs6
-rw-r--r--src/librustc/ty/context.rs2
-rw-r--r--src/librustc/ty/maps.rs39
4 files changed, 27 insertions, 39 deletions
diff --git a/src/librustc/dep_graph/dep_tracking_map.rs b/src/librustc/dep_graph/dep_tracking_map.rs
index b6a2360211c..7a246c814d3 100644
--- a/src/librustc/dep_graph/dep_tracking_map.rs
+++ b/src/librustc/dep_graph/dep_tracking_map.rs
@@ -11,7 +11,6 @@
 use hir::def_id::DefId;
 use rustc_data_structures::fx::FxHashMap;
 use std::cell::RefCell;
-use std::collections::hash_map::Entry;
 use std::ops::Index;
 use std::hash::Hash;
 use std::marker::PhantomData;
@@ -50,29 +49,11 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
         self.graph.read(dep_node);
     }
 
-    /// Registers a (synthetic) write to the key `k`. Usually this is
-    /// invoked automatically by `insert`.
-    fn write(&self, k: &M::Key) {
-        let dep_node = M::to_dep_node(k);
-        self.graph.write(dep_node);
-    }
-
     pub fn get(&self, k: &M::Key) -> Option<&M::Value> {
         self.read(k);
         self.map.get(k)
     }
 
-    pub fn insert(&mut self, k: M::Key, v: M::Value) {
-        self.write(&k);
-        let old_value = self.map.insert(k, v);
-        assert!(old_value.is_none());
-    }
-
-    pub fn entry(&mut self, k: M::Key) -> Entry<M::Key, M::Value> {
-        self.write(&k);
-        self.map.entry(k)
-    }
-
     pub fn contains_key(&self, k: &M::Key) -> bool {
         self.read(k);
         self.map.contains_key(k)
diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs
index 8be5d4327e7..18eb4e5d0ad 100644
--- a/src/librustc/dep_graph/graph.rs
+++ b/src/librustc/dep_graph/graph.rs
@@ -117,12 +117,6 @@ impl DepGraph {
         }
     }
 
-    pub fn write(&self, v: DepNode<DefId>) {
-        if self.data.thread.is_enqueue_enabled() {
-            self.data.thread.enqueue(DepMessage::Write(v));
-        }
-    }
-
     /// 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).
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 64e16c41d11..7316d45dc21 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -689,7 +689,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
             export_map: resolutions.export_map,
             fulfilled_predicates: RefCell::new(fulfilled_predicates),
             hir: hir,
-            maps: maps::Maps::new(dep_graph, providers),
+            maps: maps::Maps::new(providers),
             mir_passes,
             freevars: RefCell::new(resolutions.freevars),
             maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs
index 757687f00a2..cfb9e648d3b 100644
--- a/src/librustc/ty/maps.rs
+++ b/src/librustc/ty/maps.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
+use dep_graph::{DepNode, DepTrackingMapConfig};
 use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
 use hir::def::Def;
 use hir;
@@ -27,9 +27,11 @@ use ty::fast_reject::SimplifiedType;
 use util::nodemap::{DefIdSet, NodeSet};
 
 use rustc_data_structures::indexed_vec::IndexVec;
+use rustc_data_structures::fx::FxHashMap;
 use std::cell::{RefCell, RefMut};
 use std::fmt::Debug;
 use std::hash::Hash;
+use std::marker::PhantomData;
 use std::mem;
 use std::collections::BTreeMap;
 use std::ops::Deref;
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {
     }
 }
 
+struct QueryMap<D: QueryDescription> {
+    phantom: PhantomData<D>,
+    map: FxHashMap<D::Key, D::Value>,
+}
+
+impl<M: QueryDescription> QueryMap<M> {
+    fn new() -> QueryMap<M> {
+        QueryMap {
+            phantom: PhantomData,
+            map: FxHashMap(),
+        }
+    }
+}
+
 pub struct CycleError<'a, 'tcx: 'a> {
     span: Span,
     cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
@@ -463,13 +479,12 @@ macro_rules! define_maps {
         }
 
         impl<$tcx> Maps<$tcx> {
-            pub fn new(dep_graph: DepGraph,
-                       providers: IndexVec<CrateNum, Providers<$tcx>>)
+            pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
                        -> Self {
                 Maps {
                     providers,
                     query_stack: RefCell::new(vec![]),
-                    $($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
+                    $($name: RefCell::new(QueryMap::new())),*
                 }
             }
         }
@@ -521,7 +536,7 @@ macro_rules! define_maps {
                        key,
                        span);
 
-                if let Some(result) = tcx.maps.$name.borrow().get(&key) {
+                if let Some(result) = tcx.maps.$name.borrow().map.get(&key) {
                     return Ok(f(result));
                 }
 
@@ -539,21 +554,19 @@ macro_rules! define_maps {
                     provider(tcx.global_tcx(), key)
                 })?;
 
-                Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result)))
+                Ok(f(tcx.maps.$name.borrow_mut().map.entry(key).or_insert(result)))
             }
 
             pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
                            -> Result<$V, CycleError<'a, $tcx>> {
+                // We register the `read` here, but not in `force`, since
+                // `force` does not give access to the value produced (and thus
+                // we actually don't read it).
+                tcx.dep_graph.read(Self::to_dep_node(&key));
                 Self::try_get_with(tcx, span, key, Clone::clone)
             }
 
             pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
-                // FIXME(eddyb) Move away from using `DepTrackingMap`
-                // so we don't have to explicitly ignore a false edge:
-                // we can't observe a value dependency, only side-effects,
-                // through `force`, and once everything has been updated,
-                // perhaps only diagnostics, if those, will remain.
-                let _ignore = tcx.dep_graph.in_ignore();
                 match Self::try_get_with(tcx, span, key, |_| ()) {
                     Ok(()) => {}
                     Err(e) => tcx.report_cycle(e)
@@ -644,7 +657,7 @@ macro_rules! define_map_struct {
             tcx: $tcx,
             input: $input,
             output: ($($output)*
-                     $(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
+                     $(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,)
         }
     };