-preview=in might break code

Iain Buclaw ibuclaw at gdcproject.org
Mon Oct 5 06:49:00 UTC 2020


On Monday, 5 October 2020 at 02:21:01 UTC, Steven Schveighoffer 
wrote:
> 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
>

What did I say about the fault lies with the DMD compiler and not 
the D language specification?  S can't be both pass in memory and 
in registers at the same time.

Your example is not a problem with '-preview=in', and shouldn't 
be construed as one.


More information about the Digitalmars-d mailing list