-preview=in might break code

Mathias LANG geod24 at gmail.com
Sat Oct 3 12:09:34 UTC 2020


On Saturday, 3 October 2020 at 05:02:36 UTC, Andrei Alexandrescu 
wrote:
> [...]
>
> Wait a SECOND! Are we really in the market of developing and 
> deploying language features that come unglued at the slightest 
> and subtlest misuse? We most certainly shouldn't.

I agree. What I don't agree with is that this aliasing is a 
"slight and subtle misuse". I went through the 64 projects and 
their dependencies that are on Buildkite, and didn't see a hint 
of this pattern emerging. Nor did it in any other code I've 
surveyed in the almost 5 months the PR was open.

> I sincerely congratulated Mathias and the other participants 
> for working on this. It's an important topic. Knowing that all 
> those involved are very good at what they do, and without 
> having looked closely, I was sure they got something really 
> nice going that avoids this absolutely blatant semantic 
> grenade. And now I see this is exactly it - we got a -preview 
> of a grenade. How is this possible? How can we sleep at night 
> now?
>
> Again: take a step back and reconsider, why did this pass 
> muster?

Maybe because the people that want to use this actually know this 
is nowhere near as big of an issue as some people try to make it 
look.

Also because some of the criticism is based on the rather loose 
definition of the promotion to value at the moment. That 
definition is intentionally loose, not because it needs to be, 
but because the feature is in `-preview` and the rules need to 
take into account all platforms that D support, something that 
cannot be done in DMD alone.

> This is important, folks. It's really important as parameter 
> passing goes to the core of what the virtual machine does. You 
> can't say, meh, let's just fudge it here, and whatever is 
> surprising it's on the user.
>
> Please, we really need to put back the toothpaste in the tube 
> here. I could on everybody's clear head here to reconsider this.

Perhaps you don't know this, but the very first implementation, 
the one I had when I opened the PR on April 3rd actually always 
used `ref`. It had quite a few issues. @Kinke suggested an 
alternative, and that alternative brought many benefits with it, 
for a very minor downside, which can easily be mitigated: if your 
function's semantic really depend on mutation through an alias 
propagating (or not) to an `in` parameter, then you can use 
`__traits(isRef, paramname)` to check it.
Later on, on July 31st, I brought the topic to the forum, which 
pressed on another suggestion @Kinke has made, using the full 
function type instead of just the parameter type. At the time, 
you also made mention of this issue, and it was considered.

I wonder, did you try to adapt one of your projects to `in` ? Not 
merely throwing the switch, but also adding a couple `in` here 
and there, were it makes sense.

Not that this `-preview` is the only one that has ever been 
usable from release day (perhaps `markdown` was as well, but it 
only affected documentation generation). All the other previews 
would fail on your project because druntime and Phobos were never 
adapted after the switch was merged. `-preview=in` not only works 
with druntime/phobos, but many libraries from Buildkite were also 
adapted to work with or without it 
(https://github.com/dlang/dmd/pull/11632). I was expecting this 
would increase user engagement, allow to gather feedback, use 
cases, and lead to a healthy discussion, just like it allowed to 
refine the implementation. But I wasn't expecting FUD to be 
spread over a `-preview` before people even tried it.


More information about the Digitalmars-d mailing list