Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,322
    • Issues 4,322
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 362
    • Merge Requests 362
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13645

Closed
Open
Opened May 04, 2017 by refold@trac-refold

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
evaluated by: Main.caf_exc,\r\n called from Main.CAF\r\n --> evaluated by: Main.foo,\r\n called from Main.bar.bar',\r\n called from Main.bar,\r\n called from Main.main,\r\n called from Main.CAF\r\n --> evaluated by: Main.main\r\n[\"GHC.List.CAF ()\"]\r\n}}}\r\n\r\nIt'd be nice if `whoCreated` produced something closer to the `+RTS -xc` output in this case.\r\n\r\nCabalised test project: https://github.com/23Skidoo/caf-nostack","type_of_failure":"OtherFailure","blocking":[]} -->
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#13645