non-global template fix POC WIP

Suleyman sahmi.soulaimane at gmail.com
Fri Apr 12 23:37:57 UTC 2019


Hello,

I finished working on my solution I should be pretty solid now 
with a good number of unitests and corner cases covered. waiting 
for your replies.

link: https://github.com/dlang/dmd/pull/9282

I dropped the initial strategy instead I decided to use a static 
array of two pointer `void*[2]*` and making this one a closure 
variable thus it will be GC-allocated only when the function 
escapes.

example:
```
struct S
{
     auto func(alias a)() { ++a; }
}

void noClosure()
{
     int a;       // stack allocated
     auto s = S();
                 // v implicit var `void*[2] __this;` stack 
allocated
     s.func!a(); // no closure made
}

void withClosure()
{
     int a;               // closure var GC allocated
     auto s = S();
                          // v implicit closure var `void*[2] 
__this;` GC allocated
     auto dg = &s.func!a; // closure made
}
```




More information about the Digitalmars-d mailing list