Skip to content

Commit 6e4f8cb

Browse files
fitzgenKowasaki
authored andcommitted
Add debug!(..) logging for the template type parameters analysis
This commit adds a bunch of debug logging to the template type parameters analysis. I've essentially adding this same code and then never committed it, like three or four different times. Because I keep re-writing it, I think it is worth keeping around in a more permanent fashion.
1 parent 59d8c44 commit 6e4f8cb

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/ir/named.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,17 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
426426
.expect("Should maintain the invariant that all used template param \
427427
sets are `Some` upon entry of `constrain`");
428428

429+
debug!("constrain {:?}", id);
430+
debug!(" initially, used set is {:?}", used_by_this_id);
431+
429432
let original_len = used_by_this_id.len();
430433

431434
let item = self.ctx.resolve_item(id);
432435
let ty_kind = item.as_type().map(|ty| ty.kind());
433436
match ty_kind {
434437
// Named template type parameters trivially use themselves.
435438
Some(&TypeKind::Named) => {
439+
debug!(" named type, trivially uses itself");
436440
used_by_this_id.insert(id);
437441
}
438442

@@ -443,6 +447,9 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
443447
// parameters, but we can push the issue down the line to them.
444448
Some(&TypeKind::TemplateInstantiation(ref inst))
445449
if !self.whitelisted_items.contains(&inst.template_definition()) => {
450+
debug!(" instantiation of blacklisted template, uses all template \
451+
arguments");
452+
446453
let args = inst.template_arguments()
447454
.iter()
448455
.filter_map(|a| a.as_named(self.ctx, &()));
@@ -453,18 +460,29 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
453460
// only used if the template declaration uses the
454461
// corresponding template parameter.
455462
Some(&TypeKind::TemplateInstantiation(ref inst)) => {
463+
debug!(" template instantiation");
464+
456465
let decl = self.ctx.resolve_type(inst.template_definition());
457466
let args = inst.template_arguments();
458467

459468
let params = decl.self_template_params(self.ctx)
460469
.unwrap_or(vec![]);
461470

471+
let used_by_def = self.used[&inst.template_definition()]
472+
.as_ref()
473+
.unwrap();
474+
462475
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+
466481
if used_by_def.contains(param) {
482+
debug!(" param is used by template definition");
483+
467484
if let Some(named) = arg.as_named(self.ctx, &()) {
485+
debug!(" arg is a type parameter, marking used");
468486
used_by_this_id.insert(named);
469487
}
470488
}
@@ -474,6 +492,8 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
474492
// Otherwise, add the union of each of its referent item's template
475493
// parameter usage.
476494
_ => {
495+
debug!(" other item: join with successors' usage");
496+
477497
item.trace(self.ctx, &mut |sub_id, edge_kind| {
478498
// Ignore ourselves, since union with ourself is a
479499
// no-op. Ignore edges that aren't relevant to the
@@ -492,11 +512,18 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
492512
`Some`")
493513
.iter()
494514
.cloned();
515+
516+
debug!(" union with {:?}'s usage: {:?}",
517+
sub_id,
518+
used_by_sub_id.clone().collect::<Vec<_>>());
519+
495520
used_by_this_id.extend(used_by_sub_id);
496521
}, &());
497522
}
498523
}
499524

525+
debug!(" finally, used set is {:?}", used_by_this_id);
526+
500527
let new_len = used_by_this_id.len();
501528
assert!(new_len >= original_len,
502529
"This is the property that ensures this function is monotone -- \
@@ -515,6 +542,7 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
515542
{
516543
if let Some(edges) = self.dependencies.get(&item) {
517544
for item in edges {
545+
debug!("enqueue {:?} into worklist", item);
518546
f(*item);
519547
}
520548
}

0 commit comments

Comments
 (0)