Hi,
I've been working on this PR for a while now and after seeing it fail some tests in phobos (for example, this one), my mentors for SAoC 2021, Razvan Nitu and Eduard Staniloiu, and I figured out that, when lowered using const
or immutable
arguments, _d_arrayctor
becomes a strongly pure function. For instance, in the code snippet below
struct S {};
const S[2] b;
const S[2] a = b;
the line const S[2] a = b
is lowered to _d_arrayctor(a, b)
, which is the intended behaviour.
However, since, in this case, _d_arrayctor
is strongly pure and since its return value is ignored, the compiler issues the warning in the failed test above. In addition, its strong purity might also cause calls to _d_arrayctor
to be removed by the compiler as part of the optimisation phase.
In order to avoid such unwanted events, the only solution we could come up with was to force _d_arrayctor
to be weakly pure instead. We achieved this by adding a third pointer-type parameter, as implemented in this PR. But this is merely a stop-gap solution, because it acts against the language, by denying one of its properties: purity.
We also tried changing the type of either to
or the from
parameters to a mutable void[]
, but in this case the compiler was unable to instantiate the function's template correctly. So this solution didn't work.
Have you faced this issue before? What were your solutions?
Thanks,
Teodor