[GHC] #9127: Don't warn about pattern-bindings of the form `let !_ = rhs`
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` ------------------------------------+------------------------------------- Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- With GHC 7.8.2, code like {{{ let !_ = rqPostParams rq let !_ = rqParams rq }}} triggers the following warnings: {{{ src/Snap/Internal/Test/RequestBuilder.hs:150:13: Warning: This pattern-binding binds no variables: !_ = rqPostParams rq src/Snap/Internal/Test/RequestBuilder.hs:151:13: Warning: This pattern-binding binds no variables: !_ = rqParams rq }}} I think that `let !_ = rhs` shouldn't trigger a warning, just like `let _ = rhs` doesn't. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Harump. Maybe `let _ = rhs` ''should'' trigger a warning! It's dead code after all. But the `let !_ = e in b` means just {{{e `seq` b}}} so I suppose you could argue that it non-warnable. Does anyone else care? Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by igloo): This sounds a little odd to me. What's the actual use-case here? A test that the parameter parser doesn't thrown an exception? Unless there's a common reason for wanting to do this, I think it would be better for people who really want to do this to have to use `seq` or `!_rqPostParams = ...` instead. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by refold): Replying to [comment:2 igloo]:
This sounds a little odd to me. What's the actual use-case here? A test that the parameter parser doesn't thrown an exception?
The code looks like this: {{{ foo :: RequestBuilder foo = do rq <- rGet let !_ = rqPostParams rq ... rPut rq }}} where `RequestBuilder` is a state monad (`StateT ...`). So we're forcing some parts of the state before passing it along; `let !_ = rhs` is used as a nicer syntax for `seq`. IMO it's a valid idiom. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by igloo): Ah, well, it'll ''probably'' do what you want. But if, for example, at a usage site GHC can see the expression that has been put in `rqPostParams` and thinks that it is cheap, then it may evaluate a copy of it rather than sharing the value. #2273 is an example of something similar. To be sure, I think you'd need something like: {{{ foo :: RequestBuilder foo = do rq <- rGet let !rqPostParams' = rqPostParams rq ... rPut $! (rq { rqPostParams = rqPostParams' }) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by refold): Replying to [comment:4 igloo]: Thanks, that's good to know. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by gzayas): * owner: => gzayas -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by gzayas): * status: new => patch -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by Joachim Breitner <mail@…>): In [changeset:"fbdebd30b9ff3ca76243791723b85959c6860083/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="fbdebd30b9ff3ca76243791723b85959c6860083" supress warning of bang wildcard pattern-binding (i.e. let !_ = rhs). This fixes #9127 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Reviewed, validated and pushed, thanks Guido for your first contribution to GHC! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by nomeata): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: gzayas Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I'd love to see this documented in the user manual, please. Look at [http://www.haskell.org/ghc/docs/latest/html/users_guide/options- sanity.html sanity checking] and `-fwarn-unused-bindings`. There are really two things enabled by `-fwarn-unused_bindings`: * Warning about a named variable brought into scope but not used (unless exported or starting with underscore). e.g. {{{ let f x = rhs1 in True -- Warning for unused f let (p,q) = rhs2 in p+1 -- Warning about unused q }}} * Warning about a pattern binding that doesn't bind anything; e.g. {{{ Just _ = rhs1 -- Warning for unused binding (_, _) = rhs2 -- Warning for unused binding }}} But no warning is given for a lone wild-card pattern or banged wild-card pattern: {{{ _ = rhs3 -- No warning !_ = rhs4 -- No warning; behaves like seq }}} The former is not very different from `_v = rhs3` which elicits no warning; and can be useful to add a type constraint, e.g. `_ = x::Int`. The latter is useful as an alternative way to force evaluation. Could you add all that to the manual? Thanks -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * owner: gzayas => * status: closed => new * resolution: fixed => -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by gzayas): Simon, documentation changed as requested. Please have a look and let me know. Thanks, Guido -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by gzayas): * status: new => patch -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9127: Don't warn about pattern-bindings of the form `let !_ = rhs` -------------------------------------+------------------------------------ Reporter: refold | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * status: patch => closed * resolution: => fixed Comment: Thank you. I edited a bit more and committed {{{ commit aa18a46d85a4995f0daea63d44e627f11d03ce95 Author: Simon Peyton Jones <simonpj@microsoft.com> Date: Mon Jun 9 13:58:23 2014 +0100 Improve documentation for -fwarn-unused-binds }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9127#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC