-preview=in might break code

kinke noone at nowhere.com
Sat Oct 3 14:08:27 UTC 2020


On Saturday, 3 October 2020 at 12:09:34 UTC, Mathias LANG wrote:
> 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.

The idea is that `in` is explicit, and users of a function with 
`in` params should think of such params as `const T& 
__restrict__` in C++ terms, which should clarify the potential 
aliasing problem. Whether the thing is optimized to pass-by-value 
then shouldn't make any observable difference for the caller.

> 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.

I don't recall that, are you sure it wasn't someone else? I'd 
rather have it based on the parameter type alone.


More information about the Digitalmars-d mailing list