@@ -426,13 +426,17 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
426
426
. expect ( "Should maintain the invariant that all used template param \
427
427
sets are `Some` upon entry of `constrain`") ;
428
428
429
+ debug ! ( "constrain {:?}" , id) ;
430
+ debug ! ( " initially, used set is {:?}" , used_by_this_id) ;
431
+
429
432
let original_len = used_by_this_id. len ( ) ;
430
433
431
434
let item = self . ctx . resolve_item ( id) ;
432
435
let ty_kind = item. as_type ( ) . map ( |ty| ty. kind ( ) ) ;
433
436
match ty_kind {
434
437
// Named template type parameters trivially use themselves.
435
438
Some ( & TypeKind :: Named ) => {
439
+ debug ! ( " named type, trivially uses itself" ) ;
436
440
used_by_this_id. insert ( id) ;
437
441
}
438
442
@@ -443,6 +447,9 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
443
447
// parameters, but we can push the issue down the line to them.
444
448
Some ( & TypeKind :: TemplateInstantiation ( ref inst) )
445
449
if !self . whitelisted_items . contains ( & inst. template_definition ( ) ) => {
450
+ debug ! ( " instantiation of blacklisted template, uses all template \
451
+ arguments") ;
452
+
446
453
let args = inst. template_arguments ( )
447
454
. iter ( )
448
455
. filter_map ( |a| a. as_named ( self . ctx , & ( ) ) ) ;
@@ -453,18 +460,29 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
453
460
// only used if the template declaration uses the
454
461
// corresponding template parameter.
455
462
Some ( & TypeKind :: TemplateInstantiation ( ref inst) ) => {
463
+ debug ! ( " template instantiation" ) ;
464
+
456
465
let decl = self . ctx . resolve_type ( inst. template_definition ( ) ) ;
457
466
let args = inst. template_arguments ( ) ;
458
467
459
468
let params = decl. self_template_params ( self . ctx )
460
469
. unwrap_or ( vec ! [ ] ) ;
461
470
471
+ let used_by_def = self . used [ & inst. template_definition ( ) ]
472
+ . as_ref ( )
473
+ . unwrap ( ) ;
474
+
462
475
for ( arg, param) in args. iter ( ) . zip ( params. iter ( ) ) {
463
- let used_by_def = self . used [ & inst. template_definition ( ) ]
464
- . as_ref ( )
465
- . unwrap ( ) ;
476
+ debug ! ( " instantiation's argument {:?} is used if definition's \
477
+ parameter {:?} is used",
478
+ arg,
479
+ param) ;
480
+
466
481
if used_by_def. contains ( param) {
482
+ debug ! ( " param is used by template definition" ) ;
483
+
467
484
if let Some ( named) = arg. as_named ( self . ctx , & ( ) ) {
485
+ debug ! ( " arg is a type parameter, marking used" ) ;
468
486
used_by_this_id. insert ( named) ;
469
487
}
470
488
}
@@ -474,6 +492,8 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
474
492
// Otherwise, add the union of each of its referent item's template
475
493
// parameter usage.
476
494
_ => {
495
+ debug ! ( " other item: join with successors' usage" ) ;
496
+
477
497
item. trace ( self . ctx , & mut |sub_id, edge_kind| {
478
498
// Ignore ourselves, since union with ourself is a
479
499
// no-op. Ignore edges that aren't relevant to the
@@ -492,11 +512,18 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
492
512
`Some`")
493
513
. iter ( )
494
514
. cloned ( ) ;
515
+
516
+ debug ! ( " union with {:?}'s usage: {:?}" ,
517
+ sub_id,
518
+ used_by_sub_id. clone( ) . collect:: <Vec <_>>( ) ) ;
519
+
495
520
used_by_this_id. extend ( used_by_sub_id) ;
496
521
} , & ( ) ) ;
497
522
}
498
523
}
499
524
525
+ debug ! ( " finally, used set is {:?}" , used_by_this_id) ;
526
+
500
527
let new_len = used_by_this_id. len ( ) ;
501
528
assert ! ( new_len >= original_len,
502
529
"This is the property that ensures this function is monotone -- \
@@ -515,6 +542,7 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
515
542
{
516
543
if let Some ( edges) = self . dependencies . get ( & item) {
517
544
for item in edges {
545
+ debug ! ( "enqueue {:?} into worklist" , item) ;
518
546
f ( * item) ;
519
547
}
520
548
}
0 commit comments