[GHC] #12389: Limit duplicate export warnings for datatypes

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: #11959 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- `containers` sometimes exports data constructors/patterns conditionally (depending on GHC version and whether `TESTING` is defined). Presently, to avoid a duplicate export warning, it's necessary to write a separate export line for each combination of exported constructors, which is horrible: {{{#!hs module Foo ( #ifdef TESTING #ifdef USE_PATTERN_SYNONYMS Foo (Foo, Pat1, Pat2) #else Foo (Foo) #endif #elif USE_PATTERN_SYNONYMS Foo (Pat1, Pat2) #else Foo #endif }}} or to break up the lines with CPP, which is so horrible I can't even bring myself to write it. I'd much rather be able to write {{{#!hs module Foo ( Foo #ifdef TESTING ,Foo(Foo) #endif #ifdef USE_PATTERN_SYNONYMS ,Foo(Pat1, Pat2) #endif ) }}} The trouble here is that GHC warns about duplicate export of the type `Foo`. I think there's a pretty simple partial solution: only warn about a type export that is *completely* redundant, adding neither type constructor nor pattern. And offer a way to turn off the redundant export warning entirely for types and classes without turning it off for bindings. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Well the first `Foo` export certainly looks redundant (as long as at least one of the CPP flags is enabled). I don't really see how your second version is any better than what you say is "so horrible [...]": {{{#!hs module Foo ( Foo ( #ifdef TESTING Foo, #endif #ifdef USE_PATTERN_SYNONYMS Pat1, Pat2, #endif ) ) }}} (A trailing comma is legal here right? Otherwise it really is a mess.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:1 rwbarton]:
Well the first `Foo` export certainly looks redundant (as long as at least one of the CPP flags is enabled).
I don't really see how your second version is any better than what you say is "so horrible [...]": {{{#!hs module Foo ( Foo ( #ifdef TESTING Foo, #endif #ifdef USE_PATTERN_SYNONYMS Pat1, Pat2, #endif ) ) }}}
(A trailing comma is legal here right? Otherwise it really is a mess.)
I don't know about GHC 8, but in 7.10, a trailing comma is *not* legal, and neither is a leading one. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Hmm, it's not (in 8 either). A trailing comma is legal at the end of the export list though. Seems like we should just allow it at the end of a constructor/etc. list also. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Sure. That would solve (much of) the problem. I'd want leading commas too, because I tend to prefer a leading-comma style. And I'd want to silence the warning from duplicate constructors/patterns within the list. Because I could, hypothetically, have {{{#!hs Foo ( #if Condition1 Foo, Bar #endif #if Condition2 , Bar, Baz #endif ) }}} and wouldn't want to have to get fancy with the CPP if `Condition1` and `Condition2` both happen to hold. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Well you don't really want to "silence the warning from duplicate constructors/patterns within the list". You want to silence ''this'' duplicate of `Bar`. If you happen to repeat a different constructor elsewhere in the export list by accident, you'd still want a warning about that. So it would more appropriate to use a mechanism for locally disabling warnings. Since you can already write what you need with `#if Condition1 || Condition2`, it's not a problem anyways. At some point you may be better off just disabling the warning entirely. Warnings about redundancies are too hard when the compiler can't see your entire program at once. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Well you don't really want to "silence the warning from duplicate constructors/patterns within the list". You want to silence ''this'' duplicate of `Bar`. If you happen to repeat a different constructor elsewhere in the export list by accident, you'd still want a warning about
#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:5 rwbarton]: that. So it would more appropriate to use a mechanism for locally disabling warnings. Local suppression is very heavy for a warning about something as relatively unimportant as this. I'd be happy with a heuristic: accidental duplicates are typically less likely in a constructor/pattern export list than in a (typically much longer) module export list. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Well I wouldn't be too happy with that; the flag should do what it says on the tin and cater to the needs of normal users over those of CPP-wielding maniacs :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Fine; if I can get leading and trailing commas, I'll be happy. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): If I remember right, the export list itself does allow extra commas. So it seems a bit inconsistent not to allow the same story for the `Foo( P1, P2 )` form. So this would be ok with me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * milestone: 8.2.1 => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * keywords: => newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by parsonsmatt): I'm going to attempt a patch for this. By my first look, it should require a change to the `compiler/parser/Parser.y` Happy file, specifically the `qcnames` parse rule. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: parsonsmatt Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Phab:D4134 Wiki Page: | -------------------------------------+------------------------------------- Changes (by parsonsmatt): * owner: (none) => parsonsmatt * differential: => Phab:D4134 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: parsonsmatt Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Phab:D4134 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
I'm going to attempt a patch for this.
Thanks! But what exactly is "this"? I think you mean something like "allow leading and trailing commas in the sub-export lists". As I said above, that's ok with me. but * It should be consistent with exports lists themselves. Do they allow leading commas? If not, it'd make sense to add them. Thus {{{ module M( , f, g, ) where ... }}} * Do we allow multiple leading or trailing commas? What about repeated commas in the middle of a list? * What about import lists? Should they not be consistent? * Should we require a language extension flag? So although this is a small and superficial change, it ''is'' a user- facing one, and so should really go through the [https://github.com/ghc- proposals/ghc-proposals GHC proposals process]. Because it's small, it'll be quick! But the debate is always helpful. I'm conscious that this may seem obstructive, but I've learned that it really is worth writing down the specification and debating it before implementing it. Doing so materially increases quality by giving a way for more people to contribute. Thanks for helping! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: parsonsmatt Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Phab:D4134 Wiki Page: | -------------------------------------+------------------------------------- Comment (by parsonsmatt): You're correct -- that is what I meant :) I've collected the notes into a [https://github.com/ghc-proposals/ghc- proposals/pull/87 GHC Proposal #87]. I'll submit the proposal to the wider community and see what comes of that. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12389: Limit duplicate export warnings for datatypes -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: parsonsmatt Type: feature request | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #11959 | Differential Rev(s): Phab:D4134 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.6.1 => 8.8.1 Comment: Thanks for taking this on, parsonsmatt! However, given that the Proposal is going to be revised I doubt this will happen for 8.6. Bumping. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12389#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC