[GHC] #13154: Standalone-derived anyclass instances aren't as permissive as empty instances

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Note that these are accepted: {{{#!hs class Foo (a :: TYPE ('TupleRep '[])) instance Foo (a :: TYPE ('TupleRep '[])) instance Foo (##) }}} But if you try to write these same instances using `DeriveAnyClass` and `StandaloneDeriving`, they'll be rejected for no good reason: {{{#!hs deriving instance Foo (a :: TYPE ('TupleRep '[])) {- • Can't make a derived instance of ‘Foo a’: The last argument of the instance must be a data or newtype application -} deriving instance Foo (##) {- • Can't make a derived instance of ‘Foo (# #)’: The last argument of the instance cannot be an unboxed tuple -} }}} The latter error is a vestige of #12512, and should be easy enough to rectify. The former error is a bit tricker to fix, since much of the code in `TcDeriv`/`TcDerivInfer` assumes that the type to which the class is applied to in the instead head is a datatype or newtype `TyCon`. It's apparent that this doesn't hold true in the presence of `DeriveAnyClass`, however, so that code should be refactored to reflect this. For practical reasons, however, it might be best to wait until after #12144 is fixed to tackle this one, since that splits out some logic in `TcDerivInfer` for `DeriveAnyClass` so as to make it no longer rely on the aforementioned `TyCon` invariant. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => Generics -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * milestone: => 8.4.1 Comment: Another thing that standalone `DeriveAnyClass` currently doesn't allow (but bare instances do) is the use of nullary classes. That is, this is allowed: {{{#!hs {-# LANGUAGE MultiParamTypeClasses #-} module Allowed where class C instance C }}} but this is not: {{{#!hs {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE StandaloneDeriving #-} module Bug where class C deriving instance C }}} {{{ Bug.hs:7:1: error: • Cannot derive instances for nullary classes • In the stand-alone deriving instance for ‘C’ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3337 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): I'm missing something: why is this a real problem? Adding a bunch of logic to fix it seems like overkill to me, personally. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * cc: dfeuer (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: Generics => deriving -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Another component of this issue which Iceland_jack noticed is that one cannot standalone-derive any instances for primitive types, among which include `(->)`: {{{#!hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE StandaloneDeriving #-} module Bug where import GHC.Exts class C1 a deriving instance C1 (a -> b) class C2 (a :: TYPE 'IntRep) deriving instance C2 Int# }}} {{{ $ ghc/inplace/bin/ghc-stage2 Bug.hs [1 of 1] Compiling Bug ( Bug.hs, Bug.o ) Bug.hs:11:1: error: • Can't make a derived instance of ‘C1 (a -> b)’: The last argument of the instance must be a data or newtype application • In the stand-alone deriving instance for ‘C1 (a -> b)’ | 11 | deriving instance C1 (a -> b) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Bug.hs:14:1: error: • Can't make a derived instance of ‘C2 Int#’: The last argument of the instance must be a data or newtype application • In the stand-alone deriving instance for ‘C2 Int#’ | 14 | deriving instance C2 Int# | ^^^^^^^^^^^^^^^^^^^^^^^^^ }}} I'll lump this bug under this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => new * owner: RyanGlScott => (none) * differential: Phab:D3337 => Comment: Removing Phab:D3337 as the Diff for this, since it's been abandoned. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * owner: (none) => RyanGlScott Comment: See also commits: * a4f347c23ed926c24d178fec54c27d94f1fae0e4 (`Split out inferConstraintsDataConArgs from inferConstraints`) * ed7a830de6a2ea74dd6bb81f8ec55b9fe0b52f28 (`Use a ReaderT in TcDeriv to avoid some tedious plumbing`) * 9cb289abc582c9eb8337a2621baf58e35feeff46 (`Remove hack put in place for #12512`) Which have made progress towards fixing this ticket (but on whose commit messages I forgot to mention it). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3337 Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * cc: Iceland_jack (added) * differential: => Phab:D3337 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * differential: Phab:D3337 => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4337 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4337 Comment: Phab:D4337 fixes the issue in comment:8. It does //not// fix the entire issue, as there is still the degenerate case of: {{{#!hs {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE StandaloneDeriving #-} class C a deriving instance C a }}} Which needs further patching to fix. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty
instances
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: RyanGlScott
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler (Type | Version: 8.1
checker) |
Resolution: | Keywords: deriving
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC rejects | Unknown/Multiple
valid program | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4337
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4337, Wiki Page: | Phab:D4370 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D4337 => Phab:D4337, Phab:D4370 Comment: Phab:D4370 is another slight refactor that's working towards fixing this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty
instances
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: RyanGlScott
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler (Type | Version: 8.1
checker) |
Resolution: | Keywords: deriving
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC rejects | Unknown/Multiple
valid program | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4337,
Wiki Page: | Phab:D4370
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4337, Wiki Page: | Phab:D4370 -------------------------------------+------------------------------------- Changes (by bgamari): * owner: RyanGlScott => (none) * status: patch => new Comment: Is this now fixed, RyanGlScott? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13154: Standalone-derived anyclass instances aren't as permissive as empty instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4337, Wiki Page: | Phab:D4370 -------------------------------------+------------------------------------- Comment (by RyanGlScott): No. There is a smattering of things that still aren't supported, which include (but may not be limited to): * Instances for bare type variables: {{{#!hs instance Foo a -- Works deriving anyclass instance Foo a -- Doesn't work }}} * Instances for type-level literals: {{{#!hs instance Bar 1 -- Works deriving anyclass instance Bar 2 -- Doesn't work }}} * Empty instances: {{{#!hs instance Baz -- Works deriving instance Baz -- Doesn't work }}} I have an idea of how to fix these, but haven't had the time to try it out yet. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13154#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC