Opened 3 years ago

Last modified 3 years ago

#12696 new bug

Exception gives not enough information to be useful

Reported by: flip101 Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: exception Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by flip101)

I was told in #haskell @freenode to report this as a bug. I have a program that throws exceptions and tried debugging the problem within ghci and also outside of ghci with these commands:

stack build --ghc-options '-rtsopts -fprof-auto -fprof-auto-calls' --executable-profiling
stack exec -- vhdl +RTS -xc

Paraphrased my own words and others from irc:

The bug is that it's a bug that ghc is not reporting something useful on the exception. So i don't get sufficient information from the debug facilities. When i have sufficient information i can go ahead and debug my program. This ticket is not about solving a possible bug in my code.

The specific issue is that it's producing what ghci calls an undefined exception, and -xc is producing * Exception (reporting due to +RTS -xc): (THUNK_2_0). "(THUNK_2_0)" doesn't tell anyone anything. I'd expect to see that it reentered something it wasn't supposed to, or something like that. THUNK_2_0 sounds like an internal GHC thing, which i why i'm filing a bug.

The +RTS -xc includes names of info tables, which would help identify *what* it's throwing on. but unless the Core is generated at the same time during compilation, it's not possible to find out what. If i generate core now i will get different names. The exception could even be in the standard library. +RTS -xc definitely has a lot of room for improvement

When the program runs normally it doesn't terminate. The GHCI run terminate because -fbreak-on-exception was set.

tfComment :: Data from => from -> from
tfComment = transformBi tf
  where tf (Comment ((pos_c, c), (pos_s, s))) = Comment $ ((pos_c, T.concat ["--", c]), (pos_s, s))
        tf a = a
 
zeroPos :: Data from => from -> from
zeroPos = transformBi zp
  where zp sp@(M.SourcePos _ _ _) = sp { M.sourceName="", M.sourceLine=unsafePos 1, M.sourceColumn=unsafePos 1}
        zp x = x
 
-- (a)dd (e)xtended(i)dentifier (s)laches
aeis :: Data from => from -> from
aeis = transformBi x
  where x (IExtended a) = let updated_text :: Text
                              updated_text = T.concat ["\\", snd $ t_text a, "\\"]
                          in IExtended $ a {t_text = (fst $ t_text a, updated_text)}
        x a = a
 
bla = something..
  where parser_prop :: ContextClause -> Bool
        parser_prop = \x -> (transformIn <$> Right x) == (transformOut <$> parseSource parser $ T.toStrict . printSource $ transformIn x)
        transformIn ast = zeroPos ast
        transformOut ast = tfComment $ aeis $ zeroPos ast

ghci trace

λ> :trace main
Stopped in <exception thrown>, <unknown>
_exception :: e = _
λ> _exception

<interactive>:2:1: error:
    • No instance for (Show e) arising from a use of ‘print’
      Cannot resolve unknown runtime type ‘e’
      Use :print or :force to determine these types
      Relevant bindings include it :: e (bound at <interactive>:2:1)
      These potential instances exist:
        instance [safe] Show Args -- Defined in ‘Test.QuickCheck.Test’
        instance [safe] Show Result -- Defined in ‘Test.QuickCheck.Test’
        instance Show a => Show (ZipList a)
          -- Defined in ‘Control.Applicative’
        ...plus 297 others
        ...plus 133 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of an interactive GHCi command: print it
λ> :print e

<interactive>:1:1: error: Not in scope: ‘e’
λ> :force e

<interactive>:1:1: error: Not in scope: ‘e’
λ> :back
Logged breakpoint at Main.hs:95:13-26
_result :: from -> from
tf :: Comment -> Comment
λ> :list
94  tfComment :: Data from => from -> from
95  tfComment = transformBi tf -- transformBi tf highlighted here
96    where tf (Comment ((pos_c, c), (pos_s, s))) = Comment $ ((pos_c, T.concat ["--", c]), (pos_s, s))
λ> :back
Logged breakpoint at Main.hs:242:28-57
_result :: from
ast :: from
λ> :list
241          transformIn ast = zeroPos ast
242          transformOut ast = tfComment $ aeis $ zeroPos ast -- tfComment $ aeis $ zeroPos ast highlighted here
243  
λ> :force ast
ast = Right []
λ> transformIn (Right [])
Right []
λ> transformOut (Right [])
Right []
λ> zeroPos (Right [])
Right []
λ> aeis (Right [])
Right []
λ> tfComment (Right [])
Right []

run with profiling options (this was aborted at some point)

» stack exec -- vhdl +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
  Data.Data.CAF
  --> evaluated by: Data.Generics.Uniplate.Internal.Data.sybChildren.f,
  called from Data.Generics.Uniplate.Internal.Data.sybChildren,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.biplate.answer,
  called from Data.Generics.Uniplate.Data.biplate,
  called from Main.CAF:lvl2028_r3oe6
  --> evaluated by: Data.HashMap.Base.toList',
 called from Data.HashMap.Base.equal,
 called from Data.HashMap.Base.==,
 called from Data.Generics.Uniplate.Internal.Data.fixEq,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.biplate.answer,
 called from Data.Generics.Uniplate.Data.biplate,
 called from Main.CAF:lvl2028_r3oe6
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
 Data.Generics.Uniplate.Internal.Data.uniplateVerbose,
 called from Data.Generics.Uniplate.Internal.Data.CAF:uniplateVerbose
 --> evaluated by: Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.biplate.answer,
 called from Data.Generics.Uniplate.Data.biplate,
 called from Main.CAF:lvl2028_r3oe6
 --> evaluated by: Data.Generics.Uniplate.Internal.Data.fromOracle,
 called from Data.Generics.Uniplate.Internal.Data.biplateData,
 called from Data.Generics.Uniplate.Data.biplate,
 called from Main.tfComment,
 called from Main.qcrp.transformOut,
 called from Main.qcrp.parser_prop,
 called from Main.qcrp.parser_prop,
 called from Main.qc2.logInput,
 called from Main.qc2.logInput,
 called from Main.qc2.logInput,
 called from Main.qc2,
 called from Test.QuickCheck.Property.forAllShrink.\.\,
 called from Test.QuickCheck.Property.property,
 called from Test.QuickCheck.Test.quickCheckWithResult.property',
  called from Test.QuickCheck.Test.quickCheckWithResult.\,
  called from Test.QuickCheck.Text.withNullTerminal,
  called from Test.QuickCheck.Test.quickCheckWithResult,
  called from Main.qc2,
  called from Main.qcrp,
  called from Main.ntc
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
  Data.Generics.Uniplate.Internal.Data.sybChildren.f,
  called from Data.Generics.Uniplate.Internal.Data.sybChildren,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.biplate.answer,
  called from Data.Generics.Uniplate.Data.biplate,
  called from Main.CAF:lvl2025_r3oe3
  --> evaluated by: Data.HashMap.Base.toList',
 called from Data.HashMap.Base.equal,
 called from Data.HashMap.Base.==,
 called from Data.Generics.Uniplate.Internal.Data.fixEq,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.biplate.answer,
 called from Data.Generics.Uniplate.Data.biplate,
 called from Main.CAF:lvl2025_r3oe3
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
 Data.Generics.Uniplate.Internal.Data.sybChildren.f,
 called from Data.Generics.Uniplate.Internal.Data.sybChildren,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.biplate.answer,
 called from Data.Generics.Uniplate.Data.biplate,
 called from Main.CAF:lvl2022_r3oe0
 --> evaluated by: Data.HashMap.Base.toList',
  called from Data.HashMap.Base.equal,
  called from Data.HashMap.Base.==,
  called from Data.Generics.Uniplate.Internal.Data.fixEq,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.biplate.answer,
  called from Data.Generics.Uniplate.Data.biplate,
  called from Main.CAF:lvl2022_r3oe0
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
  Data.Generics.Uniplate.Internal.Data.sybChildren.f,
  called from Data.Generics.Uniplate.Internal.Data.sybChildren,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.biplate.answer,
  called from Data.Generics.Uniplate.Data.biplate,
  called from Main.CAF:lvl1945_r3oc9
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
  Data.Generics.Uniplate.Internal.Data.sybChildren.f,
  called from Data.Generics.Uniplate.Internal.Data.sybChildren,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.descend.answer,
  called from Data.Generics.Uniplate.Data.descend,
  called from Data.Generics.Uniplate.Operations.transform.g,
  called from Data.Generics.Uniplate.Operations.transform,
  called from Main.CAF:answer6_r3ocg
  --> evaluated by: Data.HashMap.Base.toList',
 called from Data.HashMap.Base.equal,
 called from Data.HashMap.Base.==,
 called from Data.Generics.Uniplate.Internal.Data.fixEq,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.descend.answer,
 called from Data.Generics.Uniplate.Data.descend,
 called from Data.Generics.Uniplate.Operations.transform.g,
 called from Data.Generics.Uniplate.Operations.transform,
 called from Main.CAF:answer6_r3ocg
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
 Data.Generics.Uniplate.Internal.Data.sybChildren.f,
 called from Data.Generics.Uniplate.Internal.Data.sybChildren,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.descend.answer,
 called from Data.Generics.Uniplate.Data.descend,
 called from Data.Generics.Uniplate.Operations.transform.g,
 called from Data.Generics.Uniplate.Operations.transform,
 called from Main.CAF:answer7_r3ocp
 --> evaluated by: Data.HashMap.Base.toList',
  called from Data.HashMap.Base.equal,
  called from Data.HashMap.Base.==,
  called from Data.Generics.Uniplate.Internal.Data.fixEq,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.descend.answer,
  called from Data.Generics.Uniplate.Data.descend,
  called from Data.Generics.Uniplate.Operations.transform.g,
  called from Data.Generics.Uniplate.Operations.transform,
  called from Main.CAF:answer7_r3ocp
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace:
  Data.Generics.Uniplate.Internal.Data.sybChildren.f,
  called from Data.Generics.Uniplate.Internal.Data.sybChildren,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f.cs,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate.f,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap.populate,
  called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
  called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
  called from Data.Generics.Uniplate.Data.descend.answer,
  called from Data.Generics.Uniplate.Data.descend,
  called from Data.Generics.Uniplate.Operations.transform.g,
  called from Data.Generics.Uniplate.Operations.transform,
  called from Main.CAF:answer8_r3ocy
  --> evaluated by: Data.HashMap.Base.toList',
 called from Data.HashMap.Base.equal,
 called from Data.HashMap.Base.==,
 called from Data.Generics.Uniplate.Internal.Data.fixEq,
 called from Data.Generics.Uniplate.Internal.Data.insertHitMap,
 called from Data.Generics.Uniplate.Internal.Data.readCacheFollower,
 called from Data.Generics.Uniplate.Data.descend.answer,
 called from Data.Generics.Uniplate.Data.descend,
 called from Data.Generics.Uniplate.Operations.transform.g,
 called from Data.Generics.Uniplate.Operations.transform,
 called from Main.CAF:answer8_r3ocy
^C^C^C^C

Change History (9)

comment:1 Changed 3 years ago by rwbarton

What is the bug?

comment:2 Changed 3 years ago by flip101

it's a bug that ghc is not reporting something useful

comment:3 Changed 3 years ago by rwbarton

Reporting something useful about what? Please be specific. We are not mind readers.

comment:4 Changed 3 years ago by flip101

Description: modified (diff)

comment:5 Changed 3 years ago by mpickering

It still isn't clear to me what the code is which causes the exception. Could you please provide a test case which you can invoke with one invocation of the 'ghc' executable which shows the error you think is bad?

comment:6 Changed 3 years ago by flip101

Description: modified (diff)

comment:7 Changed 3 years ago by flip101

mpickering i can attempt to. However this is my first haskell project and the original file is over 2000 lines with a lot of tangled code which i assume you would like have reduced to just a few lines without any dependencies. To be honest i'm not sure if i will be able to pull that off.

comment:8 Changed 3 years ago by flip101

Maybe a test case is not needed to help the issue along .. i discovered some more things

λ> :trace main
Stopped in <exception thrown>, <unknown>
_exception :: e = _
λ> :print _exception
_exception = (_t1::e)
λ> seq _exception ()
()
λ> :p _exception
_exception = GHC.Exception.SomeException
               (GHC.Exception.ErrorCallWithLocation (_t9::String) (_t10::String))
λ> _t9
"Data.Data.fromConstr"
λ> _t10
""

https://hackage.haskell.org/package/base-4.9.0.0/docs/src/Data.Data.html#fromConstr

I would say this pretty much points to the origin of the exception. I found out about the seq-trick after another read of the debugging wiki.

comment:9 Changed 3 years ago by flip101

The scope of this ticket is just the issue of poorly reported exceptions.

Note: See TracTickets for help on using tickets.