Re: How to find what is causing a closure allocation

2019-10-02 Thread Boris Carvajal via Digitalmars-d-learn

On Wednesday, 2 October 2019 at 15:19:43 UTC, John Colvin wrote:
I have a function that allocates a closure somewhere in it (as 
shown by the result of -profile=gc).


I can't make the function nogc as it calls a lot of other GC 
using code.


profilegc.log only gives me the line number of the function 
signature, which doesn't give me any hint as to where in the 
function the closure is allocated.


Anyone have any nice tricks to help narrow this down.


This hack seems to show the detailed info of @nogc also in normal 
code.



diff --git a/src/dmd/func.d b/src/dmd/func.d
index 832cd0bf7..e1fad8cdc 100644
--- a/src/dmd/func.d
+++ b/src/dmd/func.d
@@ -1975,7 +1975,7 @@ extern (C++) class FuncDeclaration : 
Declaration

 else
 {
 printGCUsage(loc, "using closure causes GC 
allocation");

-return false;
+//return false;
 }

 FuncDeclarations a;




Re: How to find what is causing a closure allocation

2019-10-02 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 2 October 2019 at 15:19:43 UTC, John Colvin wrote:
profilegc.log only gives me the line number of the function 
signature, which doesn't give me any hint as to where in the 
function the closure is allocated.


You'll wanna check any nested functions declared in that 
function. Kinda easier said than done with text tools (I should 
make a helper tool to do this more reliably like dscanner style), 
but they will have either the symbol { (hence why it is such a 
pain) or => and will reference a local variable in the function.


So it is kinda sucky but first is prolly search =>, maybe get 
lucky, then just start going down the { symbols and find a thing 
there.


It is tedious but it shouldn't be too bad, at least if the 
compile is quick enough that you can comment the body, recompile 
and see if the -vgc still lists the function, or have a reliable 
way of scanning for local variables.


How to find what is causing a closure allocation

2019-10-02 Thread John Colvin via Digitalmars-d-learn
I have a function that allocates a closure somewhere in it (as 
shown by the result of -profile=gc).


I can't make the function nogc as it calls a lot of other GC 
using code.


profilegc.log only gives me the line number of the function 
signature, which doesn't give me any hint as to where in the 
function the closure is allocated.


Anyone have any nice tricks to help narrow this down.