[GHC] #14318: TH shadowing bind statement triggers -Wunused-matches

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 8.2.1 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | error/warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{ $(newName "x" >>= \x -> newName "f" >>= \f -> lamE [varP f, varP x] (doE [ bindS (varP x) (listE [varE f `appE` varE x]) , noBindS (varE x)]) ) }}} generates the following expression: {{{ \f x -> do x <- f x x }}} and `-Wunused-matches` complains that `x` is not used, while both bound occurrences are in fact used. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by lyxia): * cc: lyxia (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by lyxia: Old description:
{{{ $(newName "x" >>= \x -> newName "f" >>= \f -> lamE [varP f, varP x] (doE [ bindS (varP x) (listE [varE f `appE` varE x]) , noBindS (varE x)]) ) }}}
generates the following expression:
{{{ \f x -> do x <- f x x }}}
and `-Wunused-matches` complains that `x` is not used, while both bound occurrences are in fact used.
New description: {{{ {-# LANGUAGE TemplateHaskell #-} module Test where import Language.Haskell.TH m :: (a -> [b]) -> a -> [b] m = $(newName "x" >>= \x -> newName "f" >>= \f -> lamE [varP f, varP x] (doE [ bindS (varP x) (listE [varE f `appE` varE x]) , noBindS (varE x)]) ) }}} The splice generates the following expression: {{{ \f x -> do x <- [f x] x }}} and `-Wunused-matches` complains that `x` is not used, while both bound occurrences are in fact used (the two uses have different types so that's quite certain). -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: mgsloan Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mgsloan): * owner: (none) => mgsloan -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mgsloan): * owner: mgsloan => (none) Comment: I've looked into this a bit. It looks like names created by `newName` are turned into GHC names via `mkSystemNameAt`, and integer making the name unique is used directly. See `Convert.thRdrName`. I'm guessing that code involving warnings is expecting that these unique names are unique per binding site, whereas in this case the same unique name is bound multiple times. I'm not sure what the correct approach is to fixing this. It could either be to fix the warning code, or, alternatively, have TH ensure that generated code has per-binding uniqueness. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14318: TH shadowing bind statement triggers -Wunused-matches -------------------------------------+------------------------------------- Reporter: lyxia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mgsloan): Ah, here is a ticket about TH allowing you to produce non-unique uniques: https://ghc.haskell.org/trac/ghc/ticket/11812 So, I suspect that the proper solution here would involve making it so that TH cannot produce non-unique binding of unique names. There is some tricky stuff here, though. I can imagine a scenario where a TH user might rely on storing unique names in memory and re-using them between splices. This makes the task of further unique-ification quite non-trivial. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14318#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC