@@ -136,6 +136,43 @@ impl DepGraph {
136
136
DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
137
137
}
138
138
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
+
139
176
pub fn assert_ignored ( & self )
140
177
{
141
178
if let Some ( ..) = self . data {
@@ -203,6 +240,8 @@ impl DepGraph {
203
240
|_key| Some ( TaskDeps {
204
241
#[ cfg( debug_assertions) ]
205
242
node : Some ( _key) ,
243
+ #[ cfg( debug_assertions) ]
244
+ no_deps : false ,
206
245
reads : SmallVec :: new ( ) ,
207
246
read_set : Default :: default ( ) ,
208
247
} ) ,
@@ -345,6 +384,8 @@ impl DepGraph {
345
384
let task_deps = Lock :: new ( TaskDeps {
346
385
#[ cfg( debug_assertions) ]
347
386
node : None ,
387
+ #[ cfg( debug_assertions) ]
388
+ no_deps : false ,
348
389
reads : SmallVec :: new ( ) ,
349
390
read_set : Default :: default ( ) ,
350
391
} ) ;
@@ -1109,6 +1150,14 @@ impl DepGraphData {
1109
1150
let icx = if let Some ( icx) = icx { icx } else { return } ;
1110
1151
if let Some ( task_deps) = icx. task_deps {
1111
1152
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
+
1112
1161
if cfg ! ( debug_assertions) {
1113
1162
self . current . lock ( ) . total_read_count += 1 ;
1114
1163
}
@@ -1140,6 +1189,8 @@ impl DepGraphData {
1140
1189
pub struct TaskDeps {
1141
1190
#[ cfg( debug_assertions) ]
1142
1191
node : Option < DepNode > ,
1192
+ #[ cfg( debug_assertions) ]
1193
+ no_deps : bool ,
1143
1194
reads : SmallVec < [ DepNodeIndex ; 8 ] > ,
1144
1195
read_set : FxHashSet < DepNodeIndex > ,
1145
1196
}
0 commit comments