[GHC] #11369: Suppress redundant-constraint warnings in case of empty classes

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 8.1 (Type checker) | 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: -------------------------------------+------------------------------------- The technique described in http://www.well-typed.com/blog/2015/07/checked-exceptions/ makes use of a class without any methods, i.e. {{{#!hs class Throws e }}} However, this by definition results in redundant constraints, e.g. {{{#!hs readFoo :: Throws IOError => FilePath -> IO Foo readFoo fn = {- ... -} }}} which GHC 8.0 warns about. I propose to suppress warnings in case a class which has no methods is used as seemingly redundant constraint. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | 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 edsko): We could probably work around this by adding a dummy class method in `Throws` and call that in `throwChecked`. (But I think there are other use cases of method-less classes out there in the wild :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | 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): I'd be ok with that. But I suggest suppressing only if it has no methods ''and'' no superclasses. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | 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 ekmett): Note: Suppressing only in the absence of superclasses means that any class constraint that just gives you a law will **always** spring this warning. {{{#!hs class Bifunctor p => Braided p where braid :: p a b -> p b a -- | @braid . braid = id@ class Braided p => Symmetric p swap :: Symmetric p => p a b -> p b a swap = braid }}} (This code is slightly simplified from http://hackage.haskell.org/package/categories-1.0.7/docs/Control-Category- Braided.html) One "solution" here is to move `swap` into the `Symmetric` class, but then you need to worry about it being overridden to be different than `braid`, which operationally can't happen in the current approach. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ekmett): * related: => #11370 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ekmett): * cc: ekmett (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by edsko): I wonder if some kind of pragma would make more sense than trying to come up with a clever heuristic. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Indeed, a pragma would be good. If someone is going to add class-specific pragmas, making `UndecidableSuperClasses` work on a per-class (rather than per-module) basis would be good. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * priority: highest => normal -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Demoting priority since there is an obvious workaround here: disable the warning in the module that defines `unthrow`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari):
If someone is going to add class-specific pragmas, making `UndecidableSuperClasses` work on a per-class (rather than per-module) basis would be good.
What would this look like? Any class in the cycle being marked with the pragma would allow undecidable superclasses? If we are going to do this we may want to consider doing it before the 8.0 release. Moving from per-module to per-class modules after the per-class pragmas are in the wild may be rather painful (judging by the move from `OverlappingInstances` to `{-# OVERLAPPING #-}`, although perhaps `UndecidableSuperClasses` won't see as wide use). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

What would this look like? Any class in the cycle being marked with the
#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: simonpj Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): pragma would allow undecidable superclasses? This issue is when we report a class cycle. If any class in the cycle has a "UndecidableSuperClasses" pragma, then yes, I suggest we do not warn. It'd be great to put this per-class stuff in 8.0, but someone would have to step up and implement it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * owner: simonpj => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.2 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.1 => 8.0.2 Comment: Bumping to 8.0.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.2 => 8.2.1 Comment: Sadly this won't be happening for 8.0.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Another use case for this emerged in #12810. Now that we can use GND for deriving instances of classes with associated type families, it's quite easy to trigger `-Wredundant-constraints` with code like this: {{{#!hs {-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies #-} class C a where type T a newtype Identity a = Identity a deriving C }}} as it will generate the following instance: {{{#!hs instance C a => C (Identity a) where type T (Identity a) = T a }}} and GHC will emit this warning: {{{ • Redundant constraint: C a • In the instance declaration for ‘C (Identity a)’ }}} Now we have examples where GHC-generated code is producing warnings, which is disconcerting. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I think this is just a bug in the code that infers the context for the instance declaration that arises from GND. We should tet {{{ instance {- Empty context!! -} C (Identity a) where type T (Identity a) = T a }}} Where is that code? I can help with this after the PLDI deadline. Anyway, I think this is unrelated to the original topic of the ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11369: Suppress redundant-constraint warnings in case of empty classes -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11370 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): simonpj, I've opened #12814 to discuss the design you propose in comment:18. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11369#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC