@@ -67,6 +67,7 @@ use ich::Fingerprint;
67
67
use ty:: TyCtxt ;
68
68
use rustc_data_structures:: stable_hasher:: { StableHasher , HashStable } ;
69
69
use ich:: StableHashingContext ;
70
+ use std:: fmt;
70
71
use std:: hash:: Hash ;
71
72
72
73
// erase!() just makes tokens go away. It's used to specify which macro argument
@@ -145,7 +146,7 @@ macro_rules! define_dep_nodes {
145
146
) ,*
146
147
}
147
148
148
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ,
149
+ #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ,
149
150
RustcEncodable , RustcDecodable ) ]
150
151
pub struct DepNode {
151
152
pub kind: DepKind ,
@@ -166,21 +167,45 @@ macro_rules! define_dep_nodes {
166
167
let tupled_args = ( $( $tuple_arg, ) * ) ;
167
168
let hash = DepNodeParams :: to_fingerprint( & tupled_args,
168
169
tcx) ;
169
- return DepNode {
170
+ let dep_node = DepNode {
170
171
kind: DepKind :: $variant,
171
172
hash
172
173
} ;
174
+
175
+ if cfg!( debug_assertions) &&
176
+ !dep_node. kind. can_reconstruct_query_key( ) &&
177
+ ( tcx. sess. opts. debugging_opts. incremental_info ||
178
+ tcx. sess. opts. debugging_opts. query_dep_graph)
179
+ {
180
+ tcx. dep_graph. register_dep_node_debug_str( dep_node, || {
181
+ tupled_args. to_debug_str( tcx)
182
+ } ) ;
183
+ }
184
+
185
+ return dep_node;
173
186
} ) *
174
187
175
188
// struct args
176
189
$( {
177
190
let tupled_args = ( $( $struct_arg_name, ) * ) ;
178
191
let hash = DepNodeParams :: to_fingerprint( & tupled_args,
179
192
tcx) ;
180
- return DepNode {
193
+ let dep_node = DepNode {
181
194
kind: DepKind :: $variant,
182
195
hash
183
196
} ;
197
+
198
+ if cfg!( debug_assertions) &&
199
+ !dep_node. kind. can_reconstruct_query_key( ) &&
200
+ ( tcx. sess. opts. debugging_opts. incremental_info ||
201
+ tcx. sess. opts. debugging_opts. query_dep_graph)
202
+ {
203
+ tcx. dep_graph. register_dep_node_debug_str( dep_node, || {
204
+ tupled_args. to_debug_str( tcx)
205
+ } ) ;
206
+ }
207
+
208
+ return dep_node;
184
209
} ) *
185
210
186
211
DepNode {
@@ -267,6 +292,36 @@ macro_rules! define_dep_nodes {
267
292
) ;
268
293
}
269
294
295
+ impl fmt:: Debug for DepNode {
296
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
297
+ write ! ( f, "{:?}" , self . kind) ?;
298
+
299
+ if !self . kind . has_params ( ) {
300
+ return Ok ( ( ) ) ;
301
+ }
302
+
303
+ write ! ( f, "(" ) ?;
304
+
305
+ :: ty:: tls:: with_opt ( |opt_tcx| {
306
+ if let Some ( tcx) = opt_tcx {
307
+ if let Some ( def_id) = self . extract_def_id ( tcx) {
308
+ write ! ( f, "{}" , tcx. item_path_str( def_id) ) ?;
309
+ } else if let Some ( ref s) = tcx. dep_graph . dep_node_debug_str ( * self ) {
310
+ write ! ( f, "{}" , s) ?;
311
+ } else {
312
+ write ! ( f, "{:?}" , self . hash) ?;
313
+ }
314
+ } else {
315
+ write ! ( f, "{:?}" , self . hash) ?;
316
+ }
317
+ Ok ( ( ) )
318
+ } ) ?;
319
+
320
+ write ! ( f, ")" )
321
+ }
322
+ }
323
+
324
+
270
325
impl DefPathHash {
271
326
#[ inline]
272
327
pub fn to_dep_node ( self , kind : DepKind ) -> DepNode {
@@ -434,10 +489,11 @@ define_dep_nodes!(
434
489
trait DepNodeParams < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > {
435
490
const CAN_RECONSTRUCT_QUERY_KEY : bool ;
436
491
fn to_fingerprint ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Fingerprint ;
492
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String ;
437
493
}
438
494
439
495
impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a , T > DepNodeParams < ' a , ' gcx , ' tcx > for T
440
- where T : HashStable < StableHashingContext < ' a , ' gcx , ' tcx > >
496
+ where T : HashStable < StableHashingContext < ' a , ' gcx , ' tcx > > + fmt :: Debug
441
497
{
442
498
default const CAN_RECONSTRUCT_QUERY_KEY : bool = false;
443
499
@@ -449,6 +505,10 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
449
505
450
506
hasher. finish ( )
451
507
}
508
+
509
+ default fn to_debug_str ( & self , _: TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
510
+ format ! ( "{:?}" , * self )
511
+ }
452
512
}
453
513
454
514
impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefId , ) {
@@ -457,6 +517,62 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
457
517
fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
458
518
tcx. def_path_hash ( self . 0 ) . 0
459
519
}
520
+
521
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
522
+ tcx. item_path_str ( self . 0 )
523
+ }
524
+ }
525
+
526
+ impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefId , DefId ) {
527
+ const CAN_RECONSTRUCT_QUERY_KEY : bool = false ;
528
+
529
+ fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
530
+ let ( def_id_0, def_id_1) = * self ;
531
+
532
+ let def_path_hash_0 = tcx. def_path_hash ( def_id_0) ;
533
+ let def_path_hash_1 = tcx. def_path_hash ( def_id_1) ;
534
+
535
+ def_path_hash_0. 0 . combine ( def_path_hash_1. 0 )
536
+ }
537
+
538
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
539
+ let ( def_id_0, def_id_1) = * self ;
540
+
541
+ format ! ( "({}, {})" ,
542
+ tcx. def_path( def_id_0) . to_string( tcx) ,
543
+ tcx. def_path( def_id_1) . to_string( tcx) )
544
+ }
545
+ }
546
+
547
+
548
+ impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefIdList , ) {
549
+ const CAN_RECONSTRUCT_QUERY_KEY : bool = false ;
550
+
551
+ fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
552
+ let mut fingerprint = Fingerprint :: zero ( ) ;
553
+
554
+ for & def_id in self . 0 . iter ( ) {
555
+ let def_path_hash = tcx. def_path_hash ( def_id) ;
556
+ fingerprint = fingerprint. combine ( def_path_hash. 0 ) ;
557
+ }
558
+
559
+ fingerprint
560
+ }
561
+
562
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
563
+ use std:: fmt:: Write ;
564
+
565
+ let mut s = String :: new ( ) ;
566
+ write ! ( & mut s, "[" ) . unwrap ( ) ;
567
+
568
+ for & def_id in self . 0 . iter ( ) {
569
+ write ! ( & mut s, "{}" , tcx. def_path( def_id) . to_string( tcx) ) . unwrap ( ) ;
570
+ }
571
+
572
+ write ! ( & mut s, "]" ) . unwrap ( ) ;
573
+
574
+ s
575
+ }
460
576
}
461
577
462
578
/// A "work product" corresponds to a `.o` (or other) file that we
0 commit comments