[GHC] #15534: Allow associated types in Minimal pragmas

#15534: Allow associated types in Minimal pragmas -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Missing associated type definitions can cause compile-time problems similar to the run-time problems that occur when necessary methods are missing. {{{#!hs {-# language TypeFamilies, UndecidableInstances #-} class Foo a where type X a type X a = Y a type Y a type Y a = X a instance Foo Int bob :: X Int bob = undefined }}} Compiling this gives {{{ Minim.hs:14:7: error: • Reduction stack overflow; size = 201 When simplifying the following type: Y Int Use -freduction-depth=0 to disable this check (any upper bound you could choose might fail unpredictably with minor updates to GHC, so disabling the check is recommended if you're sure that type checking should terminate) • In the expression: undefined In an equation for ‘bob’: bob = undefined | 14 | bob = undefined }}} That's not exactly the best error message in the world. I would like to be able to write {{{#!hs {-# MINIMAL X | Y #-} }}} which would mean that instances should give type instances for `X` or `Y`. I don't see any reason to prohibit mixing associated types and methods in a single `MINIMAL` pragma. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15534 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15534: Allow associated types in Minimal pragmas -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Before we can entertain the thought of extending `MINIMAL` pragmas to encompass associated type families, we might want to rethink how we report warnings for missing things in classes. Consider this example: {{{#!hs {-# LANGUAGE TypeFamilies #-} module Bug where class C a where type T1 a type T2 a m1 :: a m2 :: a instance C Int }}} Then the warnings we get are rather fragmented: {{{ $ /opt/ghc/8.4.3/bin/ghci Bug.hs GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:10:1: warning: [-Wmissing-methods] • No explicit associated type or default declaration for ‘T1’ • In the instance declaration for ‘C Int’ | 10 | instance C Int | ^^^^^^^^^^^^^^ Bug.hs:10:1: warning: [-Wmissing-methods] • No explicit associated type or default declaration for ‘T2’ • In the instance declaration for ‘C Int’ | 10 | instance C Int | ^^^^^^^^^^^^^^ Bug.hs:10:10: warning: [-Wmissing-methods] • No explicit implementation for ‘m1’ and ‘m2’ • In the instance declaration for ‘C Int’ | 10 | instance C Int | ^^^^^ }}} Unfortunately, the warnings for missing implementations for associated types are completely separate from those for missing implementations for methods. This is not an ideal state of affairs, because if we attached the following `MINIMAL` pragma to `C`: {{{#!hs {-# MINIMAL (T1 | m1) | (T2 | m2) #-} }}} Then presumably, we'd want a single warning to the effect of: {{{ • No explicit implementation for either ‘T1’ or ‘m1’, or ‘T2’ or ‘m2’ • In the instance declaration for ‘C Int’ }}} Achieving this in today's GHC is challenging, since the code for reporting warnings for missing associated types lives in `tcATDefault`, whereas the code for reporting warnings for missing methods lives in `tcMethods`. Perhaps step one is to consolidate these into the same function. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15534#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15534: Allow associated types in Minimal pragmas -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
Achieving this in today's GHC is challenging, since the code for reporting warnings for missing associated types lives in tcATDefault, whereas the code for reporting warnings for missing methods lives in tcMethods.
I rather think that both should be done in `checkValidClass`. Which would make it much easier to do what you want here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15534#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC