[GHC] #15073: Unable to newtype derive `Prim` via DerivingStrategies
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple Architecture: x86_64 | Type of failure: None/Unknown (amd64) | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The following compiles with both GHC 8.2.2 and 8.4.1: {{{#!hs newtype Drain = Drain { _drain :: Word8 } deriving stock (Eq, Ord, Show, Generic) deriving newtype (Storable) deriving anyclass (NFData) }}} However, adding `Prim` beside `Storable` in the `newtype` area yields the following with GHC 8.2.2: {{{ /home/colin/code/haskell/mapalgebra/lib/Geography/MapAlgebra.hs:1148:21-24: error: • Illegal unboxed tuple type as function argument: (# ghc-prim-0.5.1.1:GHC.Prim.State# s1, Word8 #) • In the expression: ghc-prim-0.5.1.1:GHC.Prim.coerce @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep). ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s -> ghc-prim-0.5.1.1:GHC.Prim.Int# -> ghc-prim-0.5.1.1:GHC.Prim.State# s -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Word8) @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep). ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s -> ghc-prim-0.5.1.1:GHC.Prim.Int# -> ghc-prim-0.5.1.1:GHC.Prim.State# s -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Drain) primitive-0.6.3.0:Data.Primitive.Types.readByteArray# In an equation for ‘primitive-0.6.3.0:Data.Primitive.Types.readByteArray#’: primitive-0.6.3.0:Data.Primitive.Types.readByteArray# = ghc-prim-0.5.1.1:GHC.Prim.coerce @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep). ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s -> ghc-prim-0.5.1.1:GHC.Prim.Int# -> ghc-prim-0.5.1.1:GHC.Prim.State# s -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Word8) @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep). ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s -> ghc-prim-0.5.1.1:GHC.Prim.Int# -> ghc-prim-0.5.1.1:GHC.Prim.State# s -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Drain) }}} and this with GHC 8.4.1: {{{ Illegal kind: ((:) (ghc-prim-0.5.2.0:GHC.Types.TupleRep ([] :: [] ghc- prim-0.5.2.0:GHC.Types.RuntimeR ep)) ((:) ghc-prim-0.5.2.0:GHC.Types.LiftedRep ([] :: [] ghc- prim-0.5.2.0:GHC.Types.RuntimeRep) :: [] ghc-prim-0.5.2.0:GHC.Types.RuntimeRep) :: [] ghc- prim-0.5.2.0:GHC.Types.RuntimeRep) Did you mean to enable TypeInType? | 1132 | deriving newtype (Storable, Prim) | }}} Turning on `TypeInType` as it suggests gives the same `Illegal unboxed tuple...` error. I've hand-written `Storable` instances before so I'm confident in its derivation, but I otherwise know nothing about `Prim`. Is there something magical about it that prevents it from being newtype derived in the same way? Thank you kindly, Colin -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => deriving Comment: Indeed. The fix for #14579 requires generating code for `GeneralizeNewtypeDeriving` that has more explicit type/kinds signatures. The flipside is that `Prim`, whose types mention unboxed tuples and levity polymorphic kinds, now requires enabling `TypeInType` and `UnboxedTuples` to derive, as you've observed. There are a handful of language extensions that GHC always enables under the hood when deriving things (such as `KindSignatures`), but I'm very much doubtful that we'd want to always enable either `TypeInType` or `UnboxedTuples`, since those can cause some other programs to break. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by fosskers): Oh look at that - enabling `UnboxedTuples` on my end makes the error disappear, and I seem to be able to use the instance. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Ah, now I see why you were confused—the `Illegal unboxed tuple type as function argument` error message doesn't recommend enabling `UnboxedTuples`. Would you consider this issue resolved if the error message were revised to do so? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by fosskers): I would, yeah. I've never used `UnboxedTuples` before (but had heard of them once reminded), so it didn't even occur to me that all I was missing was a `LANGUAGE` extension. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4620 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620 Wiki Page: | -------------------------------------+------------------------------------- Comment (by fosskers): Thanks! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I propose some language to clarify this in the users guide in Phab:D4701. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"0c7db226012b5cfafc9a38bfe372661672ec8900/ghc" 0c7db226/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="0c7db226012b5cfafc9a38bfe372661672ec8900" Fix #15073 by suggesting UnboxedTuples in an error message Under certain circumstances, `GeneralizedNewtypeDeriving` can emit code which uses unboxed tuple types, but if `UnboxedTuples` wasn't enabled, the error message that GHC gave didn't make it very clear that it could be worked around by explicitly enabling the extension. Easily fixed. Test Plan: make test TEST=T15073 Reviewers: bgamari Reviewed By: bgamari Subscribers: simonpj, thomie, carter GHC Trac Issues: #15073 Differential Revision: https://phabricator.haskell.org/D4620 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620, Wiki Page: | Phab:D4701 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: deriving/should_fail/T15073 (added) * differential: Phab:D4620 => Phab:D4620, Phab:D4701 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620, Wiki Page: | Phab:D4701 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"b876c1bb5c8ccd73a203c0f94bac3cbb9c7e2d65/ghc" b876c1bb/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="b876c1bb5c8ccd73a203c0f94bac3cbb9c7e2d65" users-guide: Point out GNTD may require additional extensions As noted in #15073, GeneralizedNewtypeDeriving may produce code that uses extensions that do not directly appear in the code written by the user. Make this clear in the users guide. [skip ci] Test Plan: Read it Reviewers: RyanGlScott Reviewed By: RyanGlScott Subscribers: fosskers, rwbarton, thomie, carter GHC Trac Issues: #15073 Differential Revision: https://phabricator.haskell.org/D4701 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15073: Unable to newtype derive `Prim` via DerivingStrategies -------------------------------------+------------------------------------- Reporter: fosskers | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: fixed | Keywords: deriving Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4620, Wiki Page: | Phab:D4701 -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15073#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC