diff --git a/src/librustc/dep_graph/dep_tracking_map.rs b/src/librustc/dep_graph/dep_tracking_map.rs index b6a2360211cac..7a246c814d3ec 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 DepTrackingMap { 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 { - 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 8be5d4327e72e..18eb4e5d0ad73 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) { - 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 64e16c41d1132..7316d45dc21ae 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 757687f00a20c..cfb9e648d3b7e 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 { + phantom: PhantomData, + map: FxHashMap, +} + +impl QueryMap { + fn new() -> QueryMap { + 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>) + pub fn new(providers: IndexVec>) -> 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>>,) + $(#[$attr])* $($pub)* $name: RefCell>>,) } };