whoCreated produces an uninformative stack trace when an exception is raised in a CAF
Consider the following program:
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Exception
import GHC.Stack
{-# NOINLINE caf #-}
caf :: [Int]
caf = [1..500]
{-# NOINLINE caf_exc #-}
caf_exc :: Int
caf_exc = caf !! 1000
{-# NOINLINE foo #-}
foo :: Int -> Int
foo 0 = caf_exc
foo n = foo $ n - 1
{-# NOINLINE bar #-}
bar :: Int -> Int
bar n = bar' n
where
bar' 0 = foo n
bar' m = bar' $ m - 1
main :: IO ()
main = print (bar 10) `catch`
\(e :: SomeException) -> do stacktrace <- whoCreated e
print stacktrace
By default, when built with profiling, whoCreated
in the example above produces a quite uninformative stack trace:
$ ./caf-nostack
["GHC.List.CAF (<entire-module>)"]
However, if you run the program with +RTS -xc
, you'll see that it prints a stack trace with much more context:
$ ./caf-nostack +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
GHC.List.CAF
--> evaluated by: Main.caf_exc,
called from Main.CAF
--> evaluated by: Main.foo,
called from Main.bar.bar',
called from Main.bar,
called from Main.main,
called from Main.CAF
--> evaluated by: Main.main
["GHC.List.CAF (<entire-module>)"]
It'd be nice if whoCreated
produced something closer to the +RTS -xc
output in this case.
Cabalised test project: https://github.com/23Skidoo/caf-nostack
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |