New Issue: Copy elision for an 'inout' actual?

16595, “vasslitvinov”, “Copy elision for an ‘inout’ actual?”, “2020-10-15T21:10:55Z”

Consider this snippet:

var r: R; // a record
myfun(r);
writeln(r);

// where:
proc myfun(inout formalArg) {...} // does not reference 'r' directly

We could elide the copy from r into formalArg on the way in and another one back into r on the way out. Instead we can do move-initialization formalArg<–r and move-initialization r<–formalArg, respectively.

How important is it to do copy elision in this case and how can we generalize it to more cases?

For reference, our current interpretation of the inout intent is that the above is equivalent to:

var r: R; // a record

var formalTemp = r; // copy initialization, can use 'init='
myfun1(formalTemp);
r = formalTemp;     // assignment
formalTemp.deinit();

writeln(r);

// where:
proc myfun1(ref formalArg) {...} // same as myfun, except uses ref intent