Automatically using stack allocations instead of GC

Nicholas Wilson iamthewilsonator at hotmail.com
Mon Oct 23 12:49:18 UTC 2017


On Monday, 23 October 2017 at 10:42:44 UTC, Dmitry Olshansky 
wrote:
> On Monday, 23 October 2017 at 09:06:21 UTC, Per Nordlöw wrote:
>> Are there any plans (or is it already happening) to make 
>> D-compilers automatically use stack allocations when possible 
>> in cases like
>>
>> int foo()
>> {
>>     auto x = [1, 2]; // should be allocated on the stack
>>     return y = x[0] + x[1];
>> }
>>
>> where allocations are "small enough" and cannot escape the 
>> current scope?
>>
>> And how does/should/will this interact with `@nogc`?
> LDC does something like that IIRC.

It does. 
https://github.com/ldc-developers/ldc/blob/master/gen/passes/GarbageCollect2Stack.cpp
It is enabled by default at -O2 or higher (but not -Os or -Oz).


More information about the Digitalmars-d mailing list