check stack discipline of tasks

This commit is contained in:
Niko Matsakis 2016-09-12 17:43:44 -04:00
parent c2ffa2f938
commit 9ca578687b

View File

@ -17,8 +17,10 @@
//! runtime impact. Therefore, it is largely compiled out if //! runtime impact. Therefore, it is largely compiled out if
//! debug-assertions are not enabled. //! debug-assertions are not enabled.
//! //!
//! The basic sanity check, always enabled, is that there is always a //! The basic sanity check, enabled if you have debug assertions
//! task (or ignore) on the stack when you do read/write. //! enabled, is that there is always a task (or ignore) on the stack
//! when you do read/write, and that the tasks are pushed/popped
//! according to a proper stack discipline.
//! //!
//! Optionally, if you specify RUST_FORBID_DEP_GRAPH_EDGE, you can //! Optionally, if you specify RUST_FORBID_DEP_GRAPH_EDGE, you can
//! specify an edge filter to be applied to each edge as it is //! specify an edge filter to be applied to each edge as it is
@ -81,13 +83,23 @@ impl ShadowGraph {
DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))), DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))),
DepMessage::PushTask(ref n) => stack.push(Some(n.clone())), DepMessage::PushTask(ref n) => stack.push(Some(n.clone())),
DepMessage::PushIgnore => stack.push(None), DepMessage::PushIgnore => stack.push(None),
DepMessage::PopTask(_) | DepMessage::PopTask(ref n) => {
match stack.pop() {
Some(Some(m)) => {
if *n != m {
bug!("stack mismatch: found {:?} expected {:?}", m, n)
}
}
Some(None) => bug!("stack mismatch: found Ignore expected {:?}", n),
None => bug!("stack mismatch: found empty stack, expected {:?}", n),
}
}
DepMessage::PopIgnore => { DepMessage::PopIgnore => {
// we could easily check that the stack is match stack.pop() {
// well-formed here, but since we use closures and Some(Some(m)) => bug!("stack mismatch: found {:?} expected ignore", m),
// RAII accessors, this bug basically never Some(None) => (),
// happens, so it seems not worth the overhead None => bug!("stack mismatch: found empty stack, expected ignore"),
stack.pop(); }
} }
DepMessage::Query => (), DepMessage::Query => (),
} }