Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding where <<loop>> happened

Tags:

If we get a <<loop>>, it means that Haskell had managed to detect an infinite loop. Is there a way to get ghc to tell us where this loop happened? It seems that Haskell should have this information somewhere.

like image 693
yong Avatar asked Aug 18 '14 08:08

yong


1 Answers

Compile your app with -prof and -fprof-auto(if you're using Cabal, use --enable-executable-profiling and --ghc-options=-fprof-auto) and then run it with +RTS -xc. It'll print a stack trace when errors happen. This should help you narrow your scope.

Example:

➜  haskell  cat loop.hs  myFun :: Int myFun =     let g = g + 1     in g + 10  main = print myFun ➜  haskell  ghc loop.hs -prof -fprof-auto [1 of 1] Compiling Main             ( loop.hs, loop.o ) Linking loop ... ➜  haskell  ./loop +RTS -xc                              *** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:    Main.myFun.g,   called from Main.myFun,   called from Main.CAF *** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:    Main.myFun.g,   called from Main.myFun,   called from Main.CAF loop: <<loop>> 
like image 143
sinan Avatar answered Nov 11 '22 11:11

sinan