[GHC] #10982: Warn about unused pattern variables in type families

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 7.11 Keywords: newcomer | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Now that we have wildcards in type families (#3699) I want to be warned about unused pattern variables in the same way I am warned about them at the term level. For example this should cause a warning that `b` is not used: {{{#!hs type family F a b type instance F a b = a }}} Prefixing unused variable with an underscore should suppress the warning: {{{#!hs type family F a b type instance F a _b = a }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by msosn): * owner: => msosn -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer 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 msosn): I'm looking into how the NamedWildCards extension causes programs to be rejected. I noticed that with the extension enabled, using named wildcards as types outside the type signatures (where they behave as documented in Partial Type Signatures section of the user's guide) causes errors. The code below is accepted when the extension is disabled, because the identifiers starting with _ are parsed as ordinary type variables. From what I read on the ghc mailing list, the type families should also be accepted with the NamedWildCards on. If so, shouldn't the wildcards be treated as type variables in the other cases as well? {{{ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NamedWildCards #-} module FailsWithNWCsEnabled where type Synonym _a = _a -> _a -- "Unexpected type '_a' In the type declaration for 'Synonym'" data A a _b = ACon a a -- "Unexpected type '_b' In the data declaration for 'A'" data B _a b = BCon _a _a -- "Unexpected type '_a' In the data declaration for 'B'" type family C a b where C a _b = a -> a -- "Wildcard '_b' not allowed in a type pattern of family instance for 'C'" type family D a b where D _a b = _a -> _a -- "Wildcard '_a' not allowed in a type pattern of family instance for 'D'" -- "Wildcard '_a' not allowed in the declaration for type synonym 'D'" (twice) data family E a b data instance E a _b = ECon a a -- "Wildcard '_b' not allowed in a type pattern of family instance for 'E'" data family F a b data instance F _a b = FCon _a _a -- "Wildcard '_a' not allowed in a type pattern of family instance for 'F'" -- "Wildcard '_a' not allowed in the definition of data constructor 'FCon'" (twice) }}} I also wonder if the warnings in type families should be enabled with the -fwarn-unused-matches option or should I make a new flag? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

The code below is accepted when the extension is disabled, because the identifiers starting with _ are parsed as ordinary type variables. From what I read on the ghc mailing list, the type families should also be accepted with the NamedWildCards on. If so, shouldn't the wildcards be
I also wonder if the warnings in type families should be enabled with
#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer 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 jstolarek): Replying to [comment:2 msosn]: treated as type variables in the other cases as well? I think you're right. I mean if this code is valid when `NamedWildCards` are turned off, then it certainly should be valid when we enable `NamedWildCards`. After all named wild cards can't possibly appear in any of these declarations, so whenever a name that looks like a wildcard appears we can safely assume that it must be a type variable. Note however, that we only want to generate warnings for unused pattern variables in type families. the -fwarn-unused-matches option or should I make a new flag? I say we use the existing flag. If anyone complains that they want a separate flag for unused type-level patterns then we can add it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1576 Wiki Page: | -------------------------------------+------------------------------------- Changes (by msosn): * differential: => Phab:D1576 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families
-------------------------------------+-------------------------------------
Reporter: jstolarek | Owner: msosn
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1576
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Jan Stolarek

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1576 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): This is a bit fiddly. Here are some facts about the current implementation: * Named wildcards are part of the abstract syntax of types; see the `HsWildCardTy` constructor of `HsType` and the data type `HsTypes.WildCardInfo`. * If `-XNamedWildCards` is on, we make a `NamedWildCard` for any `_v` in a type; see `Parser.y` and the call to `mkNamedWildCardTy`. That puts a `NamedWildCard` in many places that it does not "belong", which is what gives rise to the fallout in comment:2 The Right Thing is probably not to put `HsWildCardTy` into types where they aren't allowed. Really they should only show up in `LHsSigWcType`. So I suppose that one simple thing would be to parse wildcards as `HsTyVar`, and then either * Make `mkLHsSigWcType` traverse the type and replace appropriate `HsTyVars` with `HsWildCardTy`, or * Make the renamer do this job. Probably the latter is best. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11098 | Differential Rev(s): Phab:D1576 Wiki Page: | -------------------------------------+------------------------------------- Changes (by jstolarek): * related: => #11098 Comment: This looks like a manifestation of #11098. I tried fixing it by "making renamer do its job" but got stuck because I didn't know how to tell whether a type variable was introduced using a forall or not - see [ticket:11098#comment:3]. But this was before wildcard refactor patch (Phab:D1428). Now, looking at Note [HsType binders] in HsTypes, I think it is easy to tell whether a type variable was quantified explicitly or not. Michał, does this allow you to make progress? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | UnusedTyVarWarnings, | UnusedTyVarWarningsNamedWCs Blocked By: | Blocking: Related Tickets: #11098 | Differential Rev(s): Phab:D1576 Wiki Page: | -------------------------------------+------------------------------------- Changes (by msosn): * testcase: => UnusedTyVarWarnings, UnusedTyVarWarningsNamedWCs -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families
-------------------------------------+-------------------------------------
Reporter: jstolarek | Owner: msosn
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| UnusedTyVarWarnings,
| UnusedTyVarWarningsNamedWCs
Blocked By: | Blocking:
Related Tickets: #11098 | Differential Rev(s): Phab:D1576
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10982: Warn about unused pattern variables in type families -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: msosn Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | UnusedTyVarWarnings, | UnusedTyVarWarningsNamedWCs Blocked By: | Blocking: Related Tickets: #11098 | Differential Rev(s): Phab:D1576 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10982#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10982: Warn about unused pattern variables in type families
-------------------------------------+-------------------------------------
Reporter: jstolarek | Owner: msosn
Type: feature request | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
Resolution: fixed | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| UnusedTyVarWarnings,
| UnusedTyVarWarningsNamedWCs
Blocked By: | Blocking:
Related Tickets: #11098 | Differential Rev(s): Phab:D1576
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC