DIP1000 scope inference

Dukc ajieskola at gmail.com
Thu Oct 27 07:00:44 UTC 2022


On Thursday, 27 October 2022 at 00:57:47 UTC, Walter Bright wrote:
> Therefore, I suggest the following:
>
>     [1,2,3] is always allocated on the stack

Please no. Far too much breakage for the value (even without 
going to the question whether it'd be added value in the first 
place).

> 2. allocating on the heap means it is unusable in @nogc code

The compiler will error, and the programmer can manually fix it. 
No silent errors. `@nogc` code is still a bit of a special case, 
GC-using code is the normal we want to optimise the language for.

> 3. when writing expressions, the only way to get it on the 
> stack is to assign it to a scope variable, which is 
> inconvenient and inefficient

The compiler is still free to optimise those as a stack 
allocation, if it can prove there's no escaping of the data. 
`scope` is just used to enforce that being the case in `@safe`, 
or giving the compiler the permission to assume that being the 
case in `@trusted` and `@system`.


More information about the Digitalmars-d mailing list