www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - auto remove unused function arguments from call chain

reply Newbie2019 <newbie2019 gmail.com> writes:
Is it possible to add optimization to remove unused  function 
arguments in binary generate ?

for example:

```d


void doWork(int args, string file, size_t line) {
     version(DEV_DEBUG) {
        Log.i("info from file %s line %d", file, line);
     }
    do_the_real_work();
}


void myApp(string file = __FILE__, size_t line = __LINE__){
     doWork(args, file, line);
}
```


when build without version DEV_DEBUG, the file and line is never 
used.  will ldc able to auto remove it from the binary code ?
Nov 15 2019
parent reply Johan Engelen <j j.nl> writes:
On Saturday, 16 November 2019 at 04:22:17 UTC, Newbie2019 wrote:
 when build without version DEV_DEBUG, the file and line is 
 never used.  will ldc able to auto remove it from the binary 
 code ?
In general, no. Because the function signature must be obeyed such that the function can be called from anywhere without knowing the optimizations inside of it. If the function is internal to a module and the function is not exported, then yes the optimization is perhaps legal. So LTO might be allowed (and able) to do it, but I don't know. -Johan
Nov 16 2019
parent reply Newbie2019 <newbie2019 gmail.com> writes:
On Saturday, 16 November 2019 at 11:25:35 UTC, Johan Engelen 
wrote:
 In general, no. Because the function signature must be obeyed 
 such that the function can be called from anywhere without 
 knowing the optimizations inside of it.
 If the function is internal to a module and the function is not 
 exported, then yes the optimization is perhaps legal. So LTO 
 might be allowed (and able) to do it, but I don't know.

 -Johan
most of them are internal to a module for debug. Is LDC already do it, or could be done in future?
Nov 16 2019
parent reply Boris Carvajal <boris2.9 gmail.com> writes:
On Sunday, 17 November 2019 at 06:42:48 UTC, Newbie2019 wrote:
 On Saturday, 16 November 2019 at 11:25:35 UTC, Johan Engelen 
 wrote:
 In general, no. Because the function signature must be obeyed 
 such that the function can be called from anywhere without 
 knowing the optimizations inside of it.
 If the function is internal to a module and the function is 
 not exported, then yes the optimization is perhaps legal. So 
 LTO might be allowed (and able) to do it, but I don't know.

 -Johan
most of them are internal to a module for debug. Is LDC already do it, or could be done in future?
Already, just check in https://d.godbolt.org This was asked a few months before: https://forum.dlang.org/post/zuunbgthdschuncmaduo forum.dlang.org
Nov 17 2019
parent Newbie2019 <newbie2019 gmail.com> writes:
On Sunday, 17 November 2019 at 11:40:27 UTC, Boris Carvajal wrote:
 Already, just check in https://d.godbolt.org

 This was asked a few months before:
 https://forum.dlang.org/post/zuunbgthdschuncmaduo forum.dlang.org
Thanks for the tips, I forget I has asked before. So it only work if the target function is inlined ?
Nov 19 2019