[GHC] #8987: TH: panic in reportWarning when the message throws an exception

#8987: TH: panic in reportWarning when the message throws an exception -----------------------------------+--------------------------------------- Reporter: Yuras | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Compile-time crash Unknown/Multiple | Test Case: Difficulty: Unknown | Blocking: Blocked By: | Related Tickets: | -----------------------------------+--------------------------------------- `reportWarning` and `reportError` doesn't force it's argument, so `ghc` panics when printing the message. To reproduce: {{{#!haskell test :: Q [Dec] test = do reportWarning undefined return [] }}} Output: {{{ main.hs:5:3: Warning:ghc: panic! (the 'impossible' happened) (GHC version 7.8.1 for x86_64-unknown-linux): Prelude.undefined Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} The fix could be: {{{ --- a/compiler/typecheck/TcSplice.lhs +++ b/compiler/typecheck/TcSplice.lhs @@ -875,8 +875,8 @@ instance TH.Quasi (IOEnv (Env TcGblEnv TcLclEnv)) where ; let i = getKey u ; return (TH.mkNameU s i) } - qReport True msg = addErr (text msg) - qReport False msg = addWarn (text msg) + qReport True !msg = addErr (text msg) + qReport False !msg = addWarn (text msg) qLocation = do { m <- getModule ; l <- getSrcSpanM }}} But possibly it should `deepseq` the argument? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Changes (by Yuras): * cc: shumovichy@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Comment (by simonpj): I have not thought about this deeply, but wouldn't something very similar happen with your change? The program will still crash, won't it? Would you like to give a test case? In any case, you are right that if you are going to do this at all, then something deepseq-like would be more thorough. By all means send a patch (with comments to explain). Thanks. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Comment (by Yuras): Replying to [comment:2 simonpj]:
I have not thought about this deeply, but wouldn't something very similar happen with your change? The program will still crash, won't it?
No, ghc is prepared for exceptions in splice, including nested exceptions. See Note [Exceptions in TH] and Note [Concealed TH exceptions] So with my change compilation gracefully fails with the next message: {{{ main.hs:1:1: Exception when trying to run compile-time code: Prelude.undefined Code: test }}}
Would you like to give a test case?
In any case, you are right that if you are going to do this at all, then
something deepseq-like would be more thorough.
By all means send a patch (with comments to explain). Thanks.
Well, looks like it is not possible to use `deepseq` in `ghc`. Should I implement ad-hoc solution? Something like `deepseqString`? I don't believe it is the first time we need `deepseq`, so most likely it is already implemented somewhere. Thanks, Yuras -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Comment (by simonpj): Yes, I see a `seqString` in `AsmCodeGen`, so perhaps pull it out into `Utils` and use it. Thanks Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Changes (by Yuras): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Comment (by simonpj): Looks great. But where is `Note [Exceptions in TH]`? If you could just add that, it'd be great. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Comment (by Yuras): Replying to [comment:6 simonpj]:
Looks great. But where is `Note [Exceptions in TH]`? If you could just add that, it'd be great.
It is already here, 50 lines above. It perfectly explains how TH handles exceptions, I have little to nothing to add. I don't think we need special Note about `qReport`, but I added few lines to an existent Note. But I'm not sure it worth adding, the notes are pretty clear already. Let me know if prefer one patch, combining all the 3 attached. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception
---------------------------------------+-----------------------------------
Reporter: Yuras | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time crash | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets:
---------------------------------------+-----------------------------------
Comment (by Simon Peyton Jones

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: th/T8987 | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Changes (by Yuras): * testcase: => th/T8987 Comment: Should it be marked as closed or merge? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8987: TH: panic in reportWarning when the message throws an exception ---------------------------------------+----------------------------------- Reporter: Yuras | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time crash | Unknown/Multiple Test Case: th/T8987 | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ---------------------------------------+----------------------------------- Changes (by simonpj): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8987#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC