Implicit conversion on the left side of a vector assignment?
I just stumbled into the following:
import core.simd;
double test(double x, double2 y)
{
x += y;
return x;
}
with -O3 compiles to
double example.test(double, __vector(double[2])):
ret
At first I would expect a type error, and if not then a change in x. But perhaps this is handled via implicit conversion of x to double2, then opOpAssign on two double2 variables. This would explain no change in x.
This behavior would not be surprising for x + y, or even more so for 1.0 + y (implicit conversion is great). And compilation breaks with x = y. I guess I would expect += to be more like =.
But perhaps this is handled via implicit conversion of
xtodouble2
Yeah, that's what's happening in the frontend - this is the -vcg-ast output (with DMD too), which you can also easily check with the AST button on run.dlang.io:
double test(double x, __vector(double[2]) y)
{
cast(__vector(double[2]))x += y;
return x;
}
This behavior would not be surprising for
x + y, or even more so for1.0 + y(implicit conversion is great). And compilation breaks withx = y. I guess I would expect+=to be more like=.
Indeed x += y should modify x, see https://dlang.org/spec/expression.html#assignment_operator_expressions
"a op= b is semantically equivalent to a = cast(typeof(a))(a op b)"