-preview=in might break code
Iain Buclaw
ibuclaw at gdcproject.org
Sun Oct 4 14:58:13 UTC 2020
On Sunday, 4 October 2020 at 09:15:36 UTC, Joseph Rushton
Wakeling wrote:
>
> Platform-dependent, yes -- but the behavioural difference here
> can be 100% anticipated from the language rules (and hence,
> from the code), no?
>
> Isn't the issue with `-preview="in"` as currently implemented
> that _there is no way_ for the reader of the code to anticipate
> when ref will be used and when not?
As it is an optimization, I think that's best left to the
interpretation of the compiler/compiler author, however
optimizations should never break the semantic guarantee.
```
void fun1(const long[16] a, ref long[16] b, in long[16] c, out
long[16] d);
fun1(var, var, var, var);
void fun2(in long[16] a, int b);
fun2(var, var[0]);
```
In the above, all parameters are passed in memory as per ABI
requirements. The difference lies in whether or not `var` is
passed by reference directly or a via a temporary copy.
When it comes to `in` parameters, I'm of the opinion that a
temporary should be passed if the type is trivially copy-able.
But as an optimization, if we look at the signature and determine
that it's not possible for any parameters to be aliasing each
other, then why not pass the `in` parameter as `ref`?
More information about the Digitalmars-d
mailing list