new should lower to a template function call

Petar Petar
Thu Jul 23 10:19:41 UTC 2020


On Thursday, 23 July 2020 at 10:08:08 UTC, Walter Bright wrote:
> On 7/22/2020 11:13 PM, Petar Kirov [ZombineDev] wrote:
>>> The compiler already does this if the variable being new`d is 
>>> `scope`.
>> 
>> LDC has an optimization pass [1] which promotes heap 
>> allocations to stack allocations, without  the user having to 
>> manually use the `scope` storage class for function-local 
>> variables.
>> Do you think we could formalize this optimization and move it 
>> up the pipeline into the front-end, so that it's guaranteed to 
>> be performed by all 3 compilers?
>> 
>> [1]: 
>> https://github.com/ldc-developers/ldc/blob/v1.23.0-beta1/gen/passes/GarbageCollect2Stack.cpp
>
> It's a good idea, but I'd consider it a low priority since it 
> is so easy to add scope.
>
> As for guaranteeing stack placement in the language spec, it's 
> usually regarded as being in the QoI (Quality of 
> Implementation) domain.

I agree that it's not a high priority. Migrating more druntime 
hook to templates is more impactful as it unlocks various 
opportunities, whereas an optimization like this has a relatively 
fixed improvement potential.


More information about the Digitalmars-d mailing list