Skip to content

GHC 7.10.3 throws away callstack frames in some cases

It was noticed that GHC 7.10.3 sometimes drops outer callers from IP callstacks. For instance,

{-# LANGUAGE ImplicitParams #-}

import GHC.Stack
import Control.Monad.Catch

newtype MyError = MyError CallStack
instance Exception MyError

instance Show MyError where
    show (MyError e) = show e

fromEvents :: (MonadThrow m, ?loc :: CallStack) => m (Maybe Int)
fromEvents = do
    Just <$> require 42
  where
    -- require :: (MonadThrow m, ?loc :: CallStack) => Int -> m Int
    require n                               -- line 17
      | even n = throwM $ MyError ?loc
      | otherwise = return n


main = do
    putStrLn "Hello world"
    fromEvents                              -- line 24

GHC 8.0.1 produces the correct output,

$ ./Hi
Hello world
Hi: [("fromEvents",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "Hi.hs", srcLocStartLine = 24, srcLocStartCol = 5, srcLocEndLine = 24, srcLocEndCol = 15})]

GHC 7.10.3 produces only one

$ ./Hi
Hello world
Hi: CallStack {getCallStack = [("?loc",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "Hi.hs", srcLocStartLine = 17, srcLocStartCol = 35, srcLocEndLine = 17, srcLocEndCol = 39})]}

Uncommenting the type signature for require however results in more-or-less the expected callstack with 7.10.3,

$ ./Hi
Hello world
Hi: CallStack {getCallStack = [("?loc",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "Hi.hs", srcLocStartLine = 18, srcLocStartCol = 35, srcLocEndLine = 18, srcLocEndCol = 39}),("require",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "Hi.hs", srcLocStartLine = 14, srcLocStartCol = 14, srcLocEndLine = 14, srcLocEndCol = 21}),("fromEvents",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "Hi.hs", srcLocStartLine = 24, srcLocStartCol = 5, srcLocEndLine = 24, srcLocEndCol = 15})]}
Trac metadata
Trac field Value
Version 7.10.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information