On Sunday, 1 March 2015 at 07:04:09 UTC, Zach the Mystic wrote:
class RcType {...}
void fun(RcType1 c, RcType1 d);
auto x = new RcType;
fun(x, x);
If the compiler were smart, it would realize that by splitting
parameters this way, it's actually adding an additional
reference to x. The function should get one x for free, and
then force an opAdd/opRelease, for every additional x (or x
derivative) it detects in the same call.
One more tidbit:
class RcType {
RcType r;
...
}
void fun(RcType x, RcType y);
auto z = new RcType;
z.r = new RcType;
fun(z, z.r);
From within fun(), z can alias z.r, but z.r can't possibly alias
z. Thus, only z.r needs to be preserved. The algorithm should go
"For each parameter, add one ref/release cycle for every other
parameter which could possibly generate an alias to it".
We're approaching optimal here. This is feeling good to me.