digitalmars.D.bugs - [Issue 12683] New: Elide postblit for returning passed in args by
- via Digitalmars-d-bugs (44/44) Apr 30 2014 https://issues.dlang.org/show_bug.cgi?id=12683
https://issues.dlang.org/show_bug.cgi?id=12683 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 same. 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. Rationale: 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 example: S s = makeS() .setVal(5) .setArg(2); 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