[GHC] #12126: Bad error messages for SPECIALIZE pragmas

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: Specialize, | Operating System: Unknown/Multiple ErrorMessages | Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When playing with SPECIALIZE pragmas, I've encountered one large problem with the error messages, and two minor ones. 1. Given a function with a `Num` constraint, applying `SPECIALIZE` at a non-function type triggers defaulting incorrectly; the code {{{#!hs f1 :: Num a => a -> a f1 x = x + x {-# SPECIALIZE f1 :: Bool #-} }}} produces the error {{{ …/Test1.hs:5:1: error: • Couldn't match expected type ‘Integer -> Integer’ with actual type ‘Bool’ • In the SPECIALISE pragma {-# SPECIALIZE f1 :: Bool #-} }}} (This is in the attached file `Test1.hs`.) 2. Given a function, applying `SPECIALIZE` at a well-formed type without the looked-for instance produces an error with some extra text (the first line ends with "a SPECIALISE pragma for ‘f2’", even though this is repeated on the next line); the code {{{#!hs f2 :: Num a => a -> a f2 x = x + x {-# SPECIALIZE f2 :: Bool -> Bool #-} }}} produces the error {{{ …/Test2.hs:5:1: error: • No instance for (Num Bool) a SPECIALISE pragma for ‘f2’ • In the SPECIALISE pragma {-# SPECIALIZE f2 :: Bool -> Bool #-} }}} (This is in the attached file `Test2.hs`.) 3. This is minor, but: both of these error messages talk about a `SPECIALISE` pragma when I wrote a `SPECIALIZE` pragma. Even more so, case is not preserved in the quoted pragma; if I provide a {{{#!hs {-# specialize … #-} }}} pragma, the error message ends with {{{ • In the SPECIALISE pragma {-# SPECIALIZE … #-}`. }}} even though that isn't what I wrote. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by antalsz): * Attachment "Test1.hs" added. Incorrect defaulting in a `SPECIALIZE` error message -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by antalsz): * Attachment "Test2.hs" added. Extra text in a `SPECIALIZE` error message -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * keywords: Specialize, ErrorMessages => Specialize, ErrorMessages, newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Thanks, this is a good bug report and something good for a newcomer to get started with. I think that fixing at least (2) and (3) should be easy. Here are my investigations so far: 1. Specialisation signatures are handled in `TcBinds.tcSpecPrags`. 2. `unifyType` fails to solve `Bool ~ (Num a => a -> a)` so it gets deferred to later on in the constraint solving process. At which point it is defaulted for some reason. 1. The outer error context is added in `tcSpecPrag`. 2. The inner error context is added as a result of `hsSigDoc`. Suggestion: Modify the outer context added in `tcSpecPrag`. 1. The actual text that a user used can be found in the `inl_src` field of the `InlinePragma` field of `SpecSig`. Suggestion: There should be a few places to change where you can use this value rather than hard-coding `SPECIALISE`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by tmcgilchrist): Might I put my hand up to attempt fixing this mpickering? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Yes, of course! I made the notes so that it would be easier for someone else to tackle this. If you need any help make sure to ask. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: tmcgilchrist Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by tmcgilchrist): * owner: => tmcgilchrist -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12126: Bad error messages for SPECIALIZE pragmas -------------------------------------+------------------------------------- Reporter: antalsz | Owner: tmcgilchrist Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Specialize, | ErrorMessages, newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ThrashAbaddon): * cc: ThrashAbaddon (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12126#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC