-preview=in might break code

Johan j at j.nl
Sun Oct 4 18:02:12 UTC 2020


On Sunday, 4 October 2020 at 14:58:13 UTC, Iain Buclaw wrote:
> 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.

I agree.

Throughout this thread, I notice the confounding of two different 
concepts which are both referred to as "passing by reference".

Please separate _very clearly_
(A) the concept of passing by reference as per D language 
semantics, from
(B) the concept of passing by reference on machine instruction 
level.
It would be horrible if A becomes platform/compiler dependent for 
`in` parameters.
But B is an implementation detail that is at the discretion of 
the compiler implementer about which the D language user has no 
say (as Iain already mentioned, there is no D ABI spec and DMD, 
LDC, and GDC all make different ABI choices).

My worry from reading this thread is that `-preview=in` is making 
A platform/compiler dependent, to give users the feel that they 
get some control over B. I very much hope I am wrong.

-Johan



More information about the Digitalmars-d mailing list