Skip to content

Commit 753590f

Browse files
committed
add a debugging mechanism to forbid edges
It is useful to track down an errant edge that is being added. This is not a perfect mechanism, since it doesn't consider (e.g.) if we are in an ignored task, but it's helpful enough for now.
1 parent c6363b8 commit 753590f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ struct DepGraphData {
3838

3939
/// Work-products that we generate in this run.
4040
work_products: RefCell<FnvHashMap<Arc<WorkProductId>, WorkProduct>>,
41+
42+
/// Tracks nodes that are forbidden to read/write; see
43+
/// `DepGraph::forbid`. Used for debugging only.
44+
forbidden: RefCell<Vec<DepNode<DefId>>>,
4145
}
4246

4347
impl DepGraph {
@@ -46,7 +50,8 @@ impl DepGraph {
4650
data: Rc::new(DepGraphData {
4751
thread: DepGraphThreadData::new(enabled),
4852
previous_work_products: RefCell::new(FnvHashMap()),
49-
work_products: RefCell::new(FnvHashMap())
53+
work_products: RefCell::new(FnvHashMap()),
54+
forbidden: RefCell::new(Vec::new()),
5055
})
5156
}
5257
}
@@ -70,6 +75,15 @@ impl DepGraph {
7075
raii::DepTask::new(&self.data.thread, key)
7176
}
7277

78+
/// Debugging aid -- forbid reads/writes to `key` while the return
79+
/// value is in scope. Note that this is only available when debug
80+
/// assertions are enabled -- you should not check in code that
81+
/// invokes this function.
82+
#[cfg(debug_assertions)]
83+
pub fn forbid<'graph>(&'graph self, key: DepNode<DefId>) -> raii::Forbid<'graph> {
84+
raii::Forbid::new(&self.data.forbidden, key)
85+
}
86+
7387
pub fn with_ignore<OP,R>(&self, op: OP) -> R
7488
where OP: FnOnce() -> R
7589
{
@@ -85,10 +99,12 @@ impl DepGraph {
8599
}
86100

87101
pub fn read(&self, v: DepNode<DefId>) {
102+
debug_assert!(!self.data.forbidden.borrow().contains(&v));
88103
self.data.thread.enqueue(DepMessage::Read(v));
89104
}
90105

91106
pub fn write(&self, v: DepNode<DefId>) {
107+
debug_assert!(!self.data.forbidden.borrow().contains(&v));
92108
self.data.thread.enqueue(DepMessage::Write(v));
93109
}
94110

src/librustc/dep_graph/raii.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12+
use std::cell::RefCell;
1213
use super::DepNode;
1314
use super::thread::{DepGraphThreadData, DepMessage};
1415

@@ -47,3 +48,20 @@ impl<'graph> Drop for IgnoreTask<'graph> {
4748
self.data.enqueue(DepMessage::PopIgnore);
4849
}
4950
}
51+
52+
pub struct Forbid<'graph> {
53+
forbidden: &'graph RefCell<Vec<DepNode<DefId>>>
54+
}
55+
56+
impl<'graph> Forbid<'graph> {
57+
pub fn new(forbidden: &'graph RefCell<Vec<DepNode<DefId>>>, node: DepNode<DefId>) -> Self {
58+
forbidden.borrow_mut().push(node);
59+
Forbid { forbidden: forbidden }
60+
}
61+
}
62+
63+
impl<'graph> Drop for Forbid<'graph> {
64+
fn drop(&mut self) {
65+
self.forbidden.borrow_mut().pop();
66+
}
67+
}

0 commit comments

Comments
 (0)