new should lower to a template function call
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jul 24 00:27:19 UTC 2020
On 7/23/20 2:15 AM, Petar Kirov [ZombineDev] wrote:
> On Thursday, 23 July 2020 at 06:13:52 UTC, Petar Kirov [ZombineDev] wrote:
>> On Thursday, 23 July 2020 at 05:12:30 UTC, Walter Bright wrote:
>>> On 7/22/2020 6:05 PM, Adam D. Ruppe 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
>>
>
> ... building upon the infrastructure in src/dmd/escape.d
That'd be awesome. The user just types new Whatever and the compiler
decides whether to lower or simply use the stack.
More information about the Digitalmars-d
mailing list