Skip to content

Commit 9ca5786

Browse files
committed
check stack discipline of tasks
1 parent c2ffa2f commit 9ca5786

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/librustc/dep_graph/shadow.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
//! runtime impact. Therefore, it is largely compiled out if
1818
//! debug-assertions are not enabled.
1919
//!
20-
//! The basic sanity check, always enabled, is that there is always a
21-
//! task (or ignore) on the stack when you do read/write.
20+
//! The basic sanity check, enabled if you have debug assertions
21+
//! enabled, is that there is always a task (or ignore) on the stack
22+
//! when you do read/write, and that the tasks are pushed/popped
23+
//! according to a proper stack discipline.
2224
//!
2325
//! Optionally, if you specify RUST_FORBID_DEP_GRAPH_EDGE, you can
2426
//! specify an edge filter to be applied to each edge as it is
@@ -81,13 +83,23 @@ impl ShadowGraph {
8183
DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))),
8284
DepMessage::PushTask(ref n) => stack.push(Some(n.clone())),
8385
DepMessage::PushIgnore => stack.push(None),
84-
DepMessage::PopTask(_) |
86+
DepMessage::PopTask(ref n) => {
87+
match stack.pop() {
88+
Some(Some(m)) => {
89+
if *n != m {
90+
bug!("stack mismatch: found {:?} expected {:?}", m, n)
91+
}
92+
}
93+
Some(None) => bug!("stack mismatch: found Ignore expected {:?}", n),
94+
None => bug!("stack mismatch: found empty stack, expected {:?}", n),
95+
}
96+
}
8597
DepMessage::PopIgnore => {
86-
// we could easily check that the stack is
87-
// well-formed here, but since we use closures and
88-
// RAII accessors, this bug basically never
89-
// happens, so it seems not worth the overhead
90-
stack.pop();
98+
match stack.pop() {
99+
Some(Some(m)) => bug!("stack mismatch: found {:?} expected ignore", m),
100+
Some(None) => (),
101+
None => bug!("stack mismatch: found empty stack, expected ignore"),
102+
}
91103
}
92104
DepMessage::Query => (),
93105
}

0 commit comments

Comments
 (0)