@@ -136,6 +136,43 @@ impl DepGraph {
136136 DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
137137 }
138138
139+ pub fn debug_assert_no_deps < OP , R > ( op : OP ) -> R
140+ where OP : FnOnce ( ) -> R
141+ {
142+ if cfg ! ( debug_assertions) {
143+ ty:: tls:: with_context ( |icx| {
144+ let task_deps = Lock :: new ( TaskDeps {
145+ #[ cfg( debug_assertions) ]
146+ node : None ,
147+ #[ cfg( debug_assertions) ]
148+ no_deps : true ,
149+ reads : SmallVec :: new ( ) ,
150+ read_set : Default :: default ( ) ,
151+ } ) ;
152+ let icx = ty:: tls:: ImplicitCtxt {
153+ task_deps : Some ( & task_deps) ,
154+ ..icx. clone ( )
155+ } ;
156+
157+ let r = ty:: tls:: enter_context ( & icx, |_| {
158+ op ( )
159+ } ) ;
160+
161+ for read in & task_deps. lock ( ) . reads {
162+ icx. tcx . dep_graph . data . as_ref ( ) . map ( |graph| {
163+ eprintln ! ( "read: {:?}" , graph. current. lock( ) . data[ * read] . node) ;
164+ } ) ;
165+ }
166+ // Ensure no dependencies were recorded
167+ assert_eq ! ( task_deps. into_inner( ) . reads, SmallVec :: <[ DepNodeIndex ; 8 ] >:: new( ) ) ;
168+
169+ r
170+ } )
171+ } else {
172+ op ( )
173+ }
174+ }
175+
139176 pub fn assert_ignored ( & self )
140177 {
141178 if let Some ( ..) = self . data {
@@ -203,6 +240,8 @@ impl DepGraph {
203240 |_key| Some ( TaskDeps {
204241 #[ cfg( debug_assertions) ]
205242 node : Some ( _key) ,
243+ #[ cfg( debug_assertions) ]
244+ no_deps : false ,
206245 reads : SmallVec :: new ( ) ,
207246 read_set : Default :: default ( ) ,
208247 } ) ,
@@ -345,6 +384,8 @@ impl DepGraph {
345384 let task_deps = Lock :: new ( TaskDeps {
346385 #[ cfg( debug_assertions) ]
347386 node : None ,
387+ #[ cfg( debug_assertions) ]
388+ no_deps : false ,
348389 reads : SmallVec :: new ( ) ,
349390 read_set : Default :: default ( ) ,
350391 } ) ;
@@ -1109,6 +1150,14 @@ impl DepGraphData {
11091150 let icx = if let Some ( icx) = icx { icx } else { return } ;
11101151 if let Some ( task_deps) = icx. task_deps {
11111152 let mut task_deps = task_deps. lock ( ) ;
1153+
1154+ #[ cfg( debug_assertions) ]
1155+ {
1156+ if task_deps. no_deps {
1157+ panic ! ( "tried to add dependency, but no dependencies are allowed" ) ;
1158+ }
1159+ }
1160+
11121161 if cfg ! ( debug_assertions) {
11131162 self . current . lock ( ) . total_read_count += 1 ;
11141163 }
@@ -1140,6 +1189,8 @@ impl DepGraphData {
11401189pub struct TaskDeps {
11411190 #[ cfg( debug_assertions) ]
11421191 node : Option < DepNode > ,
1192+ #[ cfg( debug_assertions) ]
1193+ no_deps : bool ,
11431194 reads : SmallVec < [ DepNodeIndex ; 8 ] > ,
11441195 read_set : FxHashSet < DepNodeIndex > ,
11451196}
0 commit comments