www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12683] New: Elide postblit for returning passed in args by


          Issue ID: 12683
           Summary: Elide postblit for returning passed in args by value
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: monarchdodra gmail.com

Reduced test case:
auto pipe(T)(T t)
    return t; //HERE

It is my understanding that the compiler can't elide the copy entirely, since
the location of the argument and the location of the return value are not the

However, I think the compiler should be able to elide the call to the postblit
entirelly: It should simply move the bits in "t" to its final destination, and
avoid calling the dtor on the original object.

1. Performance:
 - There are *tons* of functions that return its args. "D" makes it legal to
move things around, so we should exploit it.
 - More performance. There are "even more" tons of if trivial "helper"
functions, such as "binaryFun"/"lambda" that would benefit from this.

2. It's the next logical step for factory/"named constructor" idiom. For
S s = makeS()

Currently, in the above code, if "S" has a postblit, then it will be called on
those two extra function calls.

Furthermore, this improvement is necessary to allow support for "unique
objects" that have disabled postblit. Currently, code that takes an argument,
mutates it, then returns it, can't operate on unique types, even if the
original object is an RValue.

Apr 30 2014