First Draft: Static Single Assignment
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Nov 21 15:04:27 UTC 2025
On 21/11/2025 10:48 PM, Peter C wrote:
> On Thursday, 20 November 2025 at 06:03:03 UTC, Walter Bright wrote:
>> On 11/15/2025 6:43 PM, Richard (Rikki) Andrew Cattermole wrote:
>>> Three things I'd like to see here:
>>>
>>> 1. Function parameters
>>
>> Yes
>>
>>
>>> 2. Fields
>>
>> Problematic, because one can modify it with some pointer manipulation
>>
>>
>>> 3. Globals
>>
>> Yes
>
> and forloops?
>
> -----
> module mymodule;
> @safe:
> private:
> import std;
>
> void main()
> {
> int[] arr = [100, 200, 300];
> int extra = 999;
>
> // Here, 'fixed' ensures that the loop variable remains bound
> // to the correct array element throughout its iteration.
> //
> foreach (fixed ref element; arr)
> {
> // element is now bound as an alias to arr[i]
>
> element = 500; // OK: modifying the value being referenced -> arr[i]
> element = extra; // ERROR: reassigning a fixed reference binding
> is not allowed.
> }
> }
>
> -----
Variables defined in a loop get extracted outside of it.
They shouldn't need a dedicated section, but good to bring it up!
More information about the dip.development
mailing list