-preview=in might break code
Iain Buclaw
ibuclaw at gdcproject.org
Mon Oct 5 06:23:07 UTC 2020
On Sunday, 4 October 2020 at 20:42:17 UTC, kinke wrote:
> On Sunday, 4 October 2020 at 20:06:49 UTC, Iain Buclaw wrote:
>> If I'd be pressed to bullet point it, I'd put down the
>> following.
>>
>> When an parameter is annotation with `in`:
>> - The parameter is not modifiable.
>> - All memory reachable from the parameter can not be clobbered
>> (overwritten).
>> - The parameter does not escape.
>> - Copy constructors are elided by passing by-ref.
>> - Other forms of copy elision may occur if doing so does not
>> change program behaviour.
>>
>> Is that simple enough for an end-user?
>
> I think that's a pretty good summary, although I'd loosen point
> 2 to the object itself, not all memory reachable from it.
>
2. Assumes memory reachable from the parameter will not be
clobbered (overwritten).
Basically, this:
s.a = 0xacce55ed;
fun(s);
assert(s.a == 0xacce55ed);
The caller can and will optimize based on this assumption never
being false.
More information about the Digitalmars-d
mailing list