Skip to content

Commit c150301

Browse files
Remove DepGraph::write() and its callers.
1 parent 9111927 commit c150301

File tree

4 files changed

+27
-39
lines changed

4 files changed

+27
-39
lines changed

src/librustc/dep_graph/dep_tracking_map.rs

-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use hir::def_id::DefId;
1212
use rustc_data_structures::fx::FxHashMap;
1313
use std::cell::RefCell;
14-
use std::collections::hash_map::Entry;
1514
use std::ops::Index;
1615
use std::hash::Hash;
1716
use std::marker::PhantomData;
@@ -50,29 +49,11 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
5049
self.graph.read(dep_node);
5150
}
5251

53-
/// Registers a (synthetic) write to the key `k`. Usually this is
54-
/// invoked automatically by `insert`.
55-
fn write(&self, k: &M::Key) {
56-
let dep_node = M::to_dep_node(k);
57-
self.graph.write(dep_node);
58-
}
59-
6052
pub fn get(&self, k: &M::Key) -> Option<&M::Value> {
6153
self.read(k);
6254
self.map.get(k)
6355
}
6456

65-
pub fn insert(&mut self, k: M::Key, v: M::Value) {
66-
self.write(&k);
67-
let old_value = self.map.insert(k, v);
68-
assert!(old_value.is_none());
69-
}
70-
71-
pub fn entry(&mut self, k: M::Key) -> Entry<M::Key, M::Value> {
72-
self.write(&k);
73-
self.map.entry(k)
74-
}
75-
7657
pub fn contains_key(&self, k: &M::Key) -> bool {
7758
self.read(k);
7859
self.map.contains_key(k)

src/librustc/dep_graph/graph.rs

-6
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ impl DepGraph {
117117
}
118118
}
119119

120-
pub fn write(&self, v: DepNode<DefId>) {
121-
if self.data.thread.is_enqueue_enabled() {
122-
self.data.thread.enqueue(DepMessage::Write(v));
123-
}
124-
}
125-
126120
/// Indicates that a previous work product exists for `v`. This is
127121
/// invoked during initial start-up based on what nodes are clean
128122
/// (and what files exist in the incr. directory).

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
689689
export_map: resolutions.export_map,
690690
fulfilled_predicates: RefCell::new(fulfilled_predicates),
691691
hir: hir,
692-
maps: maps::Maps::new(dep_graph, providers),
692+
maps: maps::Maps::new(providers),
693693
mir_passes,
694694
freevars: RefCell::new(resolutions.freevars),
695695
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,

src/librustc/ty/maps.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
11+
use dep_graph::{DepNode, DepTrackingMapConfig};
1212
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1313
use hir::def::Def;
1414
use hir;
@@ -27,9 +27,11 @@ use ty::fast_reject::SimplifiedType;
2727
use util::nodemap::{DefIdSet, NodeSet};
2828

2929
use rustc_data_structures::indexed_vec::IndexVec;
30+
use rustc_data_structures::fx::FxHashMap;
3031
use std::cell::{RefCell, RefMut};
3132
use std::fmt::Debug;
3233
use std::hash::Hash;
34+
use std::marker::PhantomData;
3335
use std::mem;
3436
use std::collections::BTreeMap;
3537
use std::ops::Deref;
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {
180182
}
181183
}
182184

185+
struct QueryMap<D: QueryDescription> {
186+
phantom: PhantomData<D>,
187+
map: FxHashMap<D::Key, D::Value>,
188+
}
189+
190+
impl<M: QueryDescription> QueryMap<M> {
191+
fn new() -> QueryMap<M> {
192+
QueryMap {
193+
phantom: PhantomData,
194+
map: FxHashMap(),
195+
}
196+
}
197+
}
198+
183199
pub struct CycleError<'a, 'tcx: 'a> {
184200
span: Span,
185201
cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
@@ -463,13 +479,12 @@ macro_rules! define_maps {
463479
}
464480

465481
impl<$tcx> Maps<$tcx> {
466-
pub fn new(dep_graph: DepGraph,
467-
providers: IndexVec<CrateNum, Providers<$tcx>>)
482+
pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
468483
-> Self {
469484
Maps {
470485
providers,
471486
query_stack: RefCell::new(vec![]),
472-
$($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
487+
$($name: RefCell::new(QueryMap::new())),*
473488
}
474489
}
475490
}
@@ -521,7 +536,7 @@ macro_rules! define_maps {
521536
key,
522537
span);
523538

524-
if let Some(result) = tcx.maps.$name.borrow().get(&key) {
539+
if let Some(result) = tcx.maps.$name.borrow().map.get(&key) {
525540
return Ok(f(result));
526541
}
527542

@@ -539,21 +554,19 @@ macro_rules! define_maps {
539554
provider(tcx.global_tcx(), key)
540555
})?;
541556

542-
Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result)))
557+
Ok(f(tcx.maps.$name.borrow_mut().map.entry(key).or_insert(result)))
543558
}
544559

545560
pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
546561
-> Result<$V, CycleError<'a, $tcx>> {
562+
// We register the `read` here, but not in `force`, since
563+
// `force` does not give access to the value produced (and thus
564+
// we actually don't read it).
565+
tcx.dep_graph.read(Self::to_dep_node(&key));
547566
Self::try_get_with(tcx, span, key, Clone::clone)
548567
}
549568

550569
pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) {
551-
// FIXME(eddyb) Move away from using `DepTrackingMap`
552-
// so we don't have to explicitly ignore a false edge:
553-
// we can't observe a value dependency, only side-effects,
554-
// through `force`, and once everything has been updated,
555-
// perhaps only diagnostics, if those, will remain.
556-
let _ignore = tcx.dep_graph.in_ignore();
557570
match Self::try_get_with(tcx, span, key, |_| ()) {
558571
Ok(()) => {}
559572
Err(e) => tcx.report_cycle(e)
@@ -644,7 +657,7 @@ macro_rules! define_map_struct {
644657
tcx: $tcx,
645658
input: $input,
646659
output: ($($output)*
647-
$(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
660+
$(#[$attr])* $($pub)* $name: RefCell<QueryMap<queries::$name<$tcx>>>,)
648661
}
649662
};
650663

0 commit comments

Comments
 (0)