Skip to content

Instantly share code, notes, and snippets.

@TomMD
Created August 9, 2017 04:45
Show Gist options
  • Save TomMD/7d1fb8dc762fc37bf80b7b7dd447e29a to your computer and use it in GitHub Desktop.
Save TomMD/7d1fb8dc762fc37bf80b7b7dd447e29a to your computer and use it in GitHub Desktop.
GHC Stack on `error` with ghc 8.2
I was told compiling with `prof` will make the new GHC call stacks more informative (which seems odd) so I made this test.
Consider `so.hs`:
> import GHC.Stack
>
> main :: IO ()
> main = f
>
> f, g, h :: IO ()
> f = g
> g = h
> h = error "oh nos!"
```
tommd@HalfAndHalf /tmp% ghc -O0 -fforce-recomp so.hs && ./so
[1 of 1] Compiling Main ( so.hs, so.o )
Linking so ...
so: oh nos!
CallStack (from HasCallStack):
error, called at so.hs:9:5 in main:Main
tommd@HalfAndHalf /tmp% ghc -O0 -fforce-recomp -prof so.hs && ./so
[1 of 1] Compiling Main ( so.hs, so.o )
Linking so ...
so: oh nos!
CallStack (from HasCallStack):
error, called at so.hs:9:5 in main:Main
CallStack (from -prof):
Main.CAF (<entire-module>)
```
So that wasn't too interesting, but if we do the normal thing and use `HasCallStack => IO ()` as the types then we'd get:
```
tommd@HalfAndHalf /tmp% ghc -O0 -fforce-recomp so.hs && ./so
[1 of 1] Compiling Main ( so.hs, so.o )
Linking so ...
so: oh nos!
CallStack (from HasCallStack):
error, called at so.hs:9:5 in main:Main
h, called at so.hs:8:5 in main:Main
g, called at so.hs:7:5 in main:Main
f, called at so.hs:4:8 in main:Main
main, called at so.hs:4:1 in main:Main
```
Which is what you've probably seen elsewhere on the web wrt GHC call stacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment