[GHC] #14761: Incorrect diagnostic for UNPACK/missing strictness

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | error/warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: #7210 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs data A = A { a :: {-# UNPACK #-} Maybe Int} }}} {{{ [1 of 1] Compiling Main ( Temp.hs, Temp.o ) Temp.hs:1:19: error: • Unexpected strictness annotation: {-# UNPACK #-}Maybe • In the type ‘{-# UNPACK #-}Maybe Int’ In the definition of data constructor ‘A’ In the data declaration for ‘A’ | 1 | data A = A { a :: {-# UNPACK #-} Maybe Int} | }}} The diagnostic is incorrect because it complains about an "unexpected strictness annotation" although the error is the opposite. A quick glance at the relevant GHC code suggests that it's running into the wrong diagnostic from #7210. Verified on nightly-2018-01-29. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dminuoso): The problem only seems to trigger when there's a type constructor. {{{#!hs data A = A { a :: {-# UNPACK #-} Maybe Int} -- Wrong diagnostic data A = A { a :: {-# UNPACK #-} (,) Int Int } -- Wrong diagnostic }}} But not with the special type syntax or unary types {{{#!hs data A = A { a :: {-# UNPACK #-} (Int, Int) } -- Works data A = A { a :: {-# UNPACK #-} Int } -- Works }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This happens because both strictness annotations (`!`) and `UNPACK` annotations can decorate //any// type, and moreover, they bind more tightly than application. Therefore, this: {{{#!hs {-# UNPACK #-} Maybe Int }}} is shorthand for this: {{{#!hs ({-# UNPACK #-} Maybe) Int }}} You'll notice that you'll get a similar error if you had written `a :: ! Maybe Int`. So the error isn't incorrect—you are in fact putting `{-# UNPACK #-}` in the wrong place, and should have written it as `{-# UNPACK #-} (Maybe Int)`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dminuoso): Thank you for the explanation. Is it correct to consider {-# UNPACK #-} itself a strictness annotation? As an end user I would expect it to be referred to as a pragma. Furthermore I still have to specify the strictness annotation ! for the field. If this is working as intended, then I think it's a somewhat poor message. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): OK. Would you be satisfied if the error message said `Unexpected UNPACK pragma` instead of `Unexpected strictness annotation`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dminuoso): That sounds much better and less confusing given the context. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): I also agree that referring to `{-# UNPACK #-}` as "pragma" and `!` as "annotation" would be much better here. I'm also a bit surprised that `{-# UNPACK #-}` has such high precedence. This is not the case with some other annotations, e.g. `{-# SCC ... #-}` has quite low precedence so when I have `f = {-# SCC my_application #-} g a b c` it covers `g a b c` not just `g`. Because we can't unpack just some part of a field in a data con I think it'd make sense for `UNPACK` to have very low precedence. I think lowering the precedence would be backwards compatible too. Any thought on this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Both `{-# UNPACK #-}` and `!` only make sense at the outer level of a type in a data constructor field. But in GADT-style declarations, they can appear to be "inside" a type {{{ data T where K :: !(Maybe Int) -> {-# UNPACK #-} !Int -> T }}} Somehow `!` looks as if it should bind tightly. e.g. `!Maybe Int -> T` looks wrong. But I agree that `{-# UNPACK #-}` would be better with a lower precedence. Since these annotations/pragmas can't occur nested (except as above), I don't think it would be a breaking change to reduce the precedence of `{-# UNPACK #-}` if someone wants to make a proposal. Meanwhile, yes, the error message should be better. Something about saying `{-# UNPACK #-}` cannot appear nested inside a type might help? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => newcomer Comment: Changing the error message at the very least should be straightforward. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Phab:D4379 Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * status: new => patch * differential: => Phab:D4379 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Phab:D4397 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D4379 => Phab:D4397 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Phab:D4397 Wiki Page: | -------------------------------------+------------------------------------- Comment (by sighingnow): Replying to [comment:10 RyanGlScott]: Thanks for correcting me! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness
-------------------------------------+-------------------------------------
Reporter: dminuoso | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.2
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
error/warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #7210 | Differential Rev(s): Phab:D4397
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: error/warning at compile-time | typecheck/should_fail/T14761a, | typecheck/should_fail/T14761b Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Phab:D4397 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * testcase: => typecheck/should_fail/T14761a, typecheck/should_fail/T14761b * resolution: => fixed * milestone: => 8.6.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14761: Incorrect diagnostic for UNPACK/missing strictness -------------------------------------+------------------------------------- Reporter: dminuoso | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: error/warning at compile-time | typecheck/should_fail/T14761a, | typecheck/should_fail/T14761b Blocked By: | Blocking: Related Tickets: #7210 | Differential Rev(s): Phab:D4397 Wiki Page: | -------------------------------------+------------------------------------- Comment (by int-index): The original example now compiles in HEAD after the merge of Phab:D5221 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14761#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC