#7240: Stack trace truncated too much with indirect recursion
------------------------------+---------------------------------------------
 Reporter:  nomeata           |          Owner:  nomeata         
     Type:  bug               |         Status:  new             
 Priority:  normal            |      Component:  Profiling       
  Version:  7.4.1             |       Keywords:                  
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown      |       Testcase:                  
Blockedby:                    |       Blocking:                  
  Related:                    |  
------------------------------+---------------------------------------------

Comment(by nomeata):

 I started looking into this. Modifying ```checkLoop``` to only truncate if
 there is a real loop at the top (e.g. ```<a,b,c,b>``` does not get
 truncated yet, but ```<a,b,c,b,c>``` does get truncated to ```<a,b,c>```):

 {{{
 static CostCentreStack *
 checkLoop (CostCentreStack *ccs, CostCentre *cc)
 {
     CostCentreStack *init_start, *top_seg, *bottom_seg;

     init_start = ccs;
     // Find previous instances of cc on the stack
     while (init_start != EMPTY_STACK) {
         if (init_start->cc == cc) {
             // Compare the stack from here with the the top
             top_seg = ccs;
             bottom_seg = init_start->prevStack;
             while (bottom_seg != EMPTY_STACK && top_seg->cc ==
 bottom_seg->cc) {
                 // top_set != EMPTY_STACK as bottom_seg is definitely
 below of
                 // it and not empty
                 top_seg = top_seg->prevStack;
                 bottom_seg = bottom_seg->prevStack;
             }

             if (top_seg == init_start) {
                 // We found that the segment above init_start equals the
 segment below it,
                 // so we truncate to it.
                 return init_start;
             }
             // Otherwise, we try to find a larger repeating initial
 segment.
         }
         init_start = init_start->prevStack;
     }
     return NULL;
 }
 }}}

 The problem is that it does not play well with ```enterFunCCS```. I have
 an example program with some recursion, where the untruncated version
 would be ```<CAF,main,r,g,r,g,r,g,r,g,r,g,s,f>```, and one would expect,
 with the above code, that this gets compactified to
 ```<CAF,main,r,g,s,f>```. But what I observe is
 ```<CAF,main,r,g,r,s,f>```.

 Judging from the traces, this is due to ```enterFunCCC```. Where in the
 untruncating code it is called with ccsfun=```<CAF,main,r,g,r,g>``` and
 rCCCS=```<CAF,main,r,g,r>``` (yielding ```<CAF,main,r,g,r,g>```), now it
 receives the shortened ccsfun=```<CAF,main,r,g>``` and adds the ```r```
 back in, yielding ``<CAF,main,r,g,r>```. On this then ```s``` and ```f```
 are pushed.

 I wonder if such an effect can also occur with the current, simpler
 truncating routine.

 BTW, have you considered not truncating upon push at all, and then
 simplifying the stack trace on display? This would not lose any
 information and the ```enterFunCCS``` logic would work just fine. But
 maybe the overhead is too large? In that case, would a RTS flag (“precise
 recursive call stack”) be useful?

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7240#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to