template statistics

Jean-Louis Leroy jl at leroy.nyc
Sat Jun 6 13:59:38 UTC 2020


On Saturday, 6 June 2020 at 13:23:38 UTC, Stefan Koch wrote:
> On Saturday, 6 June 2020 at 12:54:11 UTC, Jean-Louis Leroy 
> wrote:
>> On Tuesday, 2 June 2020 at 06:47:54 UTC, Walter Bright wrote:
>>> Many people are trying to figure out what templates are 
>>> blowing up their compile. This should help:
>>>
>>> https://github.com/dlang/dmd/pull/11208
>>
>> Looks super useful.
>>
>> I tried it on the test suite of openmethods and I see lots of 
>> duplicate entries, e.g.:
>>
>> [...]
>>        2        1   setName(NewValue...)
>>        5        5   UnpackDeepImpl(U...)
>>      121       40   Parameters(func...) if (func.length == 1 
>> && isCallable!func)
>>        8        8   UnpackDeepImpl(U...)
>>        2        2   argumentMixtureAt(int i)
>>        3        3   UnpackDeepImpl(U...)
>>        4        4   UnpackDeepImpl(U...)
>>        5        5   UnpackDeepImpl(U...)
>> [...]
>
> Duplicate entries mean different Template Declarations with the 
> same name.
> Usually those happen when templates are nested.
>
> Consider:
> template X(uint I1)
> {
>     template Y()
>     {
>        alias Y = I1;
>     }
>     alias X = Y!();
> }
>
> In this case the inner declaration is not dependent on any 
> parameter that was passed to it.
> But it is dependent on the context in which it is instantiated.
> Every Instance of X will create a new separate context, In 
> which a unique declaration of Y is formed.

I suspected something like this.

I am trying to aggregate the template stats across several 
translation units (in fact the test suite of openmethods), to 
measure whether an implementation is better or worse than another 
of the same thing. In your example, what happens if I make a copy 
of X, name it Z, but leave the body unchanged? I won't be able to 
distinguish the X.Ys from the Z.Ys. Even within the same 
template, imagine I put different definitions of Y inside a 
`static if else`. I could not tell how many times each was used. 
So maybe template stats should display the fully qualified name 
(including the module) along with the line and column numbers.

Maybe I'm missing something, I will try to find time to 
experiment more during the week-end.


More information about the Digitalmars-d mailing list