template statistics

Stefan Koch uplink.coder at googlemail.com
Sat Jun 6 13:23:38 UTC 2020


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.


More information about the Digitalmars-d mailing list