-preview=in might break code
Steven Schveighoffer
schveiguy at gmail.com
Mon Oct 5 02:21:01 UTC 2020
On 10/4/20 10:19 AM, Iain Buclaw wrote:
> 3. There is no danger of ref/non-ref mismatches in ABI, because `in`
> parameters that are inferred `ref` are going to be passed in memory anyway.
>
> In the following:
> ```
> alias A = void delegate(in long);
> alias B = void delegate(const long);
> ```
> Either `long` always gets passed in memory, or always gets passed in
> registers, in both cases, they are always going to be covariant. The
> same remains true whatever type you replace `long` with.
As the change says, it's up to the back end to decide but is currently
types over 2 machine word size. So this means on 32-bit systems, 80-bit
reals would be passed by reference for example.
In practice, I don't know what this means for future or other platform
compilers.
But as a trivial counter-example, "the same remains true whatever type
you replace `long` with" isn't correct:
struct S
{
size_t[3] data;
}
alias A = void delegate(in S);
alias B = void delegate(const S);
static assert(is(A : B)); // fails with -preview=in
One can imagine this being a sticking point where code that builds fine
on 64-bit systems because of the "lucky chance" that a struct can be
passed by value is not true on a 32-bit system.
I just found it odd that this was touted as a benefit.
-Steve
More information about the Digitalmars-d
mailing list