@@ -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 {
@@ -426,10 +481,11 @@ define_dep_nodes!(
426
481
trait DepNodeParams < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > {
427
482
const CAN_RECONSTRUCT_QUERY_KEY : bool ;
428
483
fn to_fingerprint ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Fingerprint ;
484
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String ;
429
485
}
430
486
431
487
impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a , T > DepNodeParams < ' a , ' gcx , ' tcx > for T
432
- where T : HashStable < StableHashingContext < ' a , ' gcx , ' tcx > >
488
+ where T : HashStable < StableHashingContext < ' a , ' gcx , ' tcx > > + fmt :: Debug
433
489
{
434
490
default const CAN_RECONSTRUCT_QUERY_KEY : bool = false;
435
491
@@ -441,6 +497,10 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
441
497
442
498
hasher. finish ( )
443
499
}
500
+
501
+ default fn to_debug_str ( & self , _: TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
502
+ format ! ( "{:?}" , * self )
503
+ }
444
504
}
445
505
446
506
impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefId , ) {
@@ -449,6 +509,68 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
449
509
fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
450
510
tcx. def_path_hash ( self . 0 ) . 0
451
511
}
512
+
513
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
514
+ tcx. item_path_str ( self . 0 )
515
+ }
516
+ }
517
+
518
+ impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefId , DefId ) {
519
+ const CAN_RECONSTRUCT_QUERY_KEY : bool = false ;
520
+
521
+ // We actually would not need to specialize the implementation of this
522
+ // method but it's faster to combine the hashes than to instantiate a full
523
+ // hashing context and stable-hashing state.
524
+ fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
525
+ let ( def_id_0, def_id_1) = * self ;
526
+
527
+ let def_path_hash_0 = tcx. def_path_hash ( def_id_0) ;
528
+ let def_path_hash_1 = tcx. def_path_hash ( def_id_1) ;
529
+
530
+ def_path_hash_0. 0 . combine ( def_path_hash_1. 0 )
531
+ }
532
+
533
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
534
+ let ( def_id_0, def_id_1) = * self ;
535
+
536
+ format ! ( "({}, {})" ,
537
+ tcx. def_path( def_id_0) . to_string( tcx) ,
538
+ tcx. def_path( def_id_1) . to_string( tcx) )
539
+ }
540
+ }
541
+
542
+
543
+ impl < ' a , ' gcx : ' tcx + ' a , ' tcx : ' a > DepNodeParams < ' a , ' gcx , ' tcx > for ( DefIdList , ) {
544
+ const CAN_RECONSTRUCT_QUERY_KEY : bool = false ;
545
+
546
+ // We actually would not need to specialize the implementation of this
547
+ // method but it's faster to combine the hashes than to instantiate a full
548
+ // hashing context and stable-hashing state.
549
+ fn to_fingerprint ( & self , tcx : TyCtxt ) -> Fingerprint {
550
+ let mut fingerprint = Fingerprint :: zero ( ) ;
551
+
552
+ for & def_id in self . 0 . iter ( ) {
553
+ let def_path_hash = tcx. def_path_hash ( def_id) ;
554
+ fingerprint = fingerprint. combine ( def_path_hash. 0 ) ;
555
+ }
556
+
557
+ fingerprint
558
+ }
559
+
560
+ fn to_debug_str ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> String {
561
+ use std:: fmt:: Write ;
562
+
563
+ let mut s = String :: new ( ) ;
564
+ write ! ( & mut s, "[" ) . unwrap ( ) ;
565
+
566
+ for & def_id in self . 0 . iter ( ) {
567
+ write ! ( & mut s, "{}" , tcx. def_path( def_id) . to_string( tcx) ) . unwrap ( ) ;
568
+ }
569
+
570
+ write ! ( & mut s, "]" ) . unwrap ( ) ;
571
+
572
+ s
573
+ }
452
574
}
453
575
454
576
/// A "work product" corresponds to a `.o` (or other) file that we
0 commit comments