Skip to content

Commit 69c9d9b

Browse files
committed
ignore reads of tracked state when there is no current task
I realized that, even in the current system, such reads can't really do any harm. Because they are not part of a task, they will occur no matter what (only tasks can be skipped). If you leak the data you read into a task, that is bad, but that is equally bad if you are in a task. *Writes* to tracked state, on the other hand, should never occur except from within a task (and the task then records what things you read to compute it). Once we complete the shift to on-demand, these properties will hold by construction (because the on-demand struct enforces stateless tasks where leaks are impossible -- except by having shared mutable state in the tcx).
1 parent a3a5ff9 commit 69c9d9b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: src/librustc/dep_graph/edges.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ impl<D: Clone + Debug + Eq + Hash> DepGraphEdges<D> {
101101
}
102102

103103
/// Indicates that the current task `C` reads `v` by adding an
104-
/// edge from `v` to `C`. If there is no current task, panics. If
105-
/// you want to suppress this edge, use `ignore`.
104+
/// edge from `v` to `C`. If there is no current task, has no
105+
/// effect. Note that *reading* from tracked state is harmless if
106+
/// you are not in a task; what is bad is *writing* to tracked
107+
/// state (and leaking data that you read into a tracked task).
106108
pub fn read(&mut self, v: DepNode<D>) {
107-
let source = self.make_node(v);
108-
self.add_edge_from_current_node(|current| (source, current))
109+
if self.current_node().is_some() {
110+
let source = self.make_node(v);
111+
self.add_edge_from_current_node(|current| (source, current))
112+
}
109113
}
110114

111115
/// Indicates that the current task `C` writes `v` by adding an

Diff for: src/librustc/dep_graph/shadow.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ impl ShadowGraph {
8080

8181
let mut stack = self.stack.borrow_mut();
8282
match *message {
83-
DepMessage::Read(ref n) => self.check_edge(Some(Some(n)), top(&stack)),
83+
// It is ok to READ shared state outside of a
84+
// task. That can't do any harm (at least, the only
85+
// way it can do harm is by leaking that data into a
86+
// query or task, which would be a problem
87+
// anyway). What would be bad is WRITING to that
88+
// state.
89+
DepMessage::Read(_) => { }
8490
DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))),
8591
DepMessage::PushTask(ref n) => stack.push(Some(n.clone())),
8692
DepMessage::PushIgnore => stack.push(None),
@@ -116,7 +122,7 @@ impl ShadowGraph {
116122
(None, None) => unreachable!(),
117123

118124
// nothing on top of the stack
119-
(None, Some(n)) | (Some(n), None) => bug!("read/write of {:?} but no current task", n),
125+
(None, Some(n)) | (Some(n), None) => bug!("write of {:?} but no current task", n),
120126

121127
// this corresponds to an Ignore being top of the stack
122128
(Some(None), _) | (_, Some(None)) => (),

0 commit comments

Comments
 (0)