I dun a DIP, possibly the best DIP ever

Stefan Koch uplink.coder at googlemail.com
Sat Apr 25 10:06:02 UTC 2020


On Saturday, 25 April 2020 at 09:35:45 UTC, user1234 wrote:
> On Saturday, 25 April 2020 at 09:33:19 UTC, Walter Bright wrote:
>> On 4/24/2020 1:55 PM, Walter Bright wrote:
>>> Another approach to resolving the original problem (template 
>>> instantiation bloat) is for the compiler to recognize 
>>> templates like AliasSeq as "special" and implement them 
>>> directly.
>>> 
>>> For example, AliasSeq is defined as:
>>> 
>>>    template AliasSeq(TList...) { alias AliasSeq = TList; }
>>> 
>>> This pattern is so simple it can be recognized by the 
>>> compiler. (Having std.meta.AliasSeq being a special name 
>>> known to the compiler is not necessary.)
>>
>> Giving this a try:
>>
>> https://github.com/dlang/dmd/pull/11057
>
> Nice to see the idea applied. Can you give numbers, i.e from 
> benchmarks ?

this is for the following code:

---
template Add3(alias y)
{
     enum Add3 = y + 3;
}

enum x = staticMap!(Add3,
AliasSeq!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, /*goes towards 4096*/); 
// this line was abbreviated.
);
pragma(msg, x.length + x[$-1]);

dmd fresh from walters branch release build with ldmd(ldc) 1.20
time:
0m0.230s
time for a fresh dmd build under the same condtions with that 
patch reverted:
0m0.265s
time for doing it with our "..." patch:
0.030s

these numbers are just a best out of 3 messurement so please only 
see them as a rough guide.


More information about the Digitalmars-d mailing list