Skip to content

Commit 19c6bfb

Browse files
committed
add comments and remove unused code paths
1 parent e07e715 commit 19c6bfb

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

src/librustc/dep_graph/graph.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,37 @@ impl DepGraph {
7777
op()
7878
}
7979

80+
/// Starts a new dep-graph task. Dep-graph tasks are specified
81+
/// using a free function (`task`) and **not** a closure -- this
82+
/// is intentional because we want to exercise tight control over
83+
/// what state they have access to. In particular, we want to
84+
/// prevent implicit 'leaks' of tracked state into the task (which
85+
/// could then be read without generating correct edges in the
86+
/// dep-graph -- see the [README] for more details on the
87+
/// dep-graph). To this end, the task function gets exactly two
88+
/// pieces of state: the context `cx` and an argument `arg`. Both
89+
/// of these bits of state must be of some type that implements
90+
/// `DepGraphSafe` and hence does not leak.
91+
///
92+
/// The choice of two arguments is not fundamental. One argument
93+
/// would work just as well, since multiple values can be
94+
/// collected using tuples. However, using two arguments works out
95+
/// to be quite convenient, since it is common to need a context
96+
/// (`cx`) and some argument (e.g., a `DefId` identifying what
97+
/// item to process).
98+
///
99+
/// For cases where you need some other number of arguments:
100+
///
101+
/// - If you only need one argument, just use `()` for the `arg`
102+
/// parameter.
103+
/// - If you need 3+ arguments, use a tuple for the
104+
/// `arg` parameter.
105+
///
106+
/// [README]: README.md
80107
pub fn with_task<C, A, R>(&self, key: DepNode<DefId>, cx: C, arg: A, task: fn(C, A) -> R) -> R
81108
where C: DepGraphSafe, A: DepGraphSafe
82109
{
83110
let _task = self.in_task(key);
84-
cx.read(self);
85-
arg.read(self);
86111
task(cx, arg)
87112
}
88113

src/librustc/dep_graph/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ mod edges;
1515
mod graph;
1616
mod query;
1717
mod raii;
18-
#[macro_use]
1918
mod safe;
2019
mod shadow;
2120
mod thread;

src/librustc/dep_graph/safe.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,51 @@ use hir::def_id::DefId;
1313
use syntax::ast::NodeId;
1414
use ty::TyCtxt;
1515

16-
use super::graph::DepGraph;
17-
18-
/// The `DepGraphSafe` auto trait is used to specify what kinds of
19-
/// values are safe to "leak" into a task. The idea is that this
20-
/// should be only be implemented for things like the tcx, which will
21-
/// create reads in the dep-graph whenever the trait loads anything
22-
/// that might depend on the input program.
16+
/// The `DepGraphSafe` trait is used to specify what kinds of values
17+
/// are safe to "leak" into a task. The idea is that this should be
18+
/// only be implemented for things like the tcx as well as various id
19+
/// types, which will create reads in the dep-graph whenever the trait
20+
/// loads anything that might depend on the input program.
2321
pub trait DepGraphSafe {
24-
fn read(&self, graph: &DepGraph);
2522
}
2623

24+
/// A `BodyId` on its own doesn't give access to any particular state.
25+
/// You must fetch the state from the various maps or generate
26+
/// on-demand queries, all of which create reads.
2727
impl DepGraphSafe for BodyId {
28-
fn read(&self, _graph: &DepGraph) {
29-
// a BodyId on its own doesn't give access to any particular state
30-
}
3128
}
3229

30+
/// A `NodeId` on its own doesn't give access to any particular state.
31+
/// You must fetch the state from the various maps or generate
32+
/// on-demand queries, all of which create reads.
3333
impl DepGraphSafe for NodeId {
34-
fn read(&self, _graph: &DepGraph) {
35-
// a DefId doesn't give any particular state
36-
}
3734
}
3835

36+
/// A `DefId` on its own doesn't give access to any particular state.
37+
/// You must fetch the state from the various maps or generate
38+
/// on-demand queries, all of which create reads.
3939
impl DepGraphSafe for DefId {
40-
fn read(&self, _graph: &DepGraph) {
41-
// a DefId doesn't give any particular state
42-
}
4340
}
4441

42+
/// The type context itself can be used to access all kinds of tracked
43+
/// state, but those accesses should always generate read events.
4544
impl<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> {
46-
fn read(&self, _graph: &DepGraph) {
47-
}
4845
}
4946

47+
/// Tuples make it easy to build up state.
5048
impl<A, B> DepGraphSafe for (A, B)
5149
where A: DepGraphSafe, B: DepGraphSafe
5250
{
53-
fn read(&self, graph: &DepGraph) {
54-
self.0.read(graph);
55-
self.1.read(graph);
56-
}
5751
}
5852

53+
/// No data here! :)
5954
impl DepGraphSafe for () {
60-
fn read(&self, _graph: &DepGraph) {
61-
}
6255
}
6356

64-
/// A convenient override. We should phase out usage of this over
65-
/// time.
57+
/// A convenient override that lets you pass arbitrary state into a
58+
/// task. Every use should be accompanied by a comment explaining why
59+
/// it makes sense (or how it could be refactored away in the future).
6660
pub struct AssertDepGraphSafe<T>(pub T);
61+
6762
impl<T> DepGraphSafe for AssertDepGraphSafe<T> {
68-
fn read(&self, _graph: &DepGraph) {
69-
}
7063
}

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ mod macros;
7070
pub mod diagnostics;
7171

7272
pub mod cfg;
73-
#[macro_use]
7473
pub mod dep_graph;
7574
pub mod hir;
7675
pub mod infer;

src/librustc_trans/context.rs

-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ pub struct CrateContext<'a, 'tcx: 'a> {
276276
}
277277

278278
impl<'a, 'tcx> DepGraphSafe for CrateContext<'a, 'tcx> {
279-
fn read(&self, _graph: &DepGraph) {
280-
}
281279
}
282280

283281
pub struct CrateContextIterator<'a, 'tcx: 'a> {

0 commit comments

Comments
 (0)