Choosing an Approach for the Template Lowering of _d_arrayctor
Stanislav Blinov
stanislav.blinov at gmail.com
Thu Nov 25 14:59:54 UTC 2021
On Thursday, 25 November 2021 at 14:35:56 UTC, Teodor Dutu wrote:
> On Thursday, 25 November 2021 at 14:24:59 UTC, Stanislav Blinov
> wrote:
>> On Thursday, 25 November 2021 at 13:28:18 UTC, Teodor Dutu
>> wrote:
>>
>>> A third approach, which I call the **hack** approach, is very
>>> close to the one using the template. The difference is that
>>> the hack adds a third, unused, pointer-type parameter...
>>
>> Hm... if you're going to have a pointer parameter, why not
>> instead simply keep the two parameter variant but pass the
>> first parameter by reference?
>
> The first iteration of `_d_arrayctor` was like this, as
> implemented by [this
> PR](https://github.com/dlang/druntime/pull/2655). The problem
> with it was that it made the compiler issue some warnings when
> testing phobos, because the lowering of something like `S[3]
> dst = src;` looked like this: `_d_arrayctor(dst[], src[])`.
> `_d_arrayctor` was strongly pure and, since the return value of
> the function was ignored, the compiler deemed the whole
> function call useless.
If you take the first parameter by reference, that shouldn't
happen. I.e. in
```d
void _d_arrayctor(A,B)(return ref A to, scope B from)
if (is(A : X[]) && is (B : Y[]) &&
is(immutable(typeof(A.init[0])) == immutable(typeof(B.init[0]))))
{ /* ... */ }
```
`A` would be a static array, taken by reference.
More information about the Digitalmars-d
mailing list