|
17 | 17 | //! runtime impact. Therefore, it is largely compiled out if |
18 | 18 | //! debug-assertions are not enabled. |
19 | 19 | //! |
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. |
22 | 24 | //! |
23 | 25 | //! Optionally, if you specify RUST_FORBID_DEP_GRAPH_EDGE, you can |
24 | 26 | //! specify an edge filter to be applied to each edge as it is |
@@ -81,13 +83,23 @@ impl ShadowGraph { |
81 | 83 | DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))), |
82 | 84 | DepMessage::PushTask(ref n) => stack.push(Some(n.clone())), |
83 | 85 | 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 | + } |
85 | 97 | 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 | + } |
91 | 103 | } |
92 | 104 | DepMessage::Query => (), |
93 | 105 | } |
|
0 commit comments