Better formatting and sorting of template instance diagnostics

Per Nordlöw per.nordlow at gmail.com
Mon Jul 27 13:05:12 UTC 2020


I'm experimenting with better formatting for template instance 
diagnostics (-vtemplates) at

https://github.com/dlang/dmd/pull/11463

.

The main use case is to make it easier to pin down sources of 
unnecessary template instances in runtime and phobos triggered by 
`-unittest` when building

     import std;

without any other code.

One key question is whether this is sufficient information or if 
we need the top-level template instance that triggers an 
instantiation deeper down.

Currently sorts on descending number of unique instances. Should 
we sort on total instances instances instead?

What about hiding this behind a value of flag `-vtemplates`, for 
instance `-vtemplates=gnu`?

Sample output:

```
phobos/std/meta.d(1811): vtemplate: found 193 total (187 unique) 
instantiation(s) of template `isSame(ab...) if (ab.length == 2)`, 
instances are:
phobos/std/meta.d(287): vtemplate: instance `isSame!(BigInt, 
byte)`
phobos/std/meta.d(287): vtemplate: instance `isSame!(BigInt, 
ubyte)`
...
druntime/import/object.d(2952): vtemplate: found 147 total (147 
unique) instantiation(s) of template `RTInfo(T)`, instances are:
phobos/std/traits.d(189): vtemplate: instance 
`RTInfo!(Demangle!uint)`
phobos/std/conv.d(4501): vtemplate: instance `RTInfo!(S)`
...
```

I've disabled the diagnostics output tests in 
`test/compilable/vtemplates.d` for now until we settle on a good 
formatting.

Should I use `WIP: ` or `[WIP] ` as title prefix? I see that both 
are used in other PRs.

Feedback is highly appreciated.


More information about the Digitalmars-d mailing list