[GHC] #14838: missing "incomplete-patterns" warning for TH-generated functions

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 8.2.2 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: -------------------------------------+------------------------------------- "incomplete-patterns" warnings are generated for TH-generated case expressions, but not for TH-generated functions, so the behaviour is inconsistent. For example: {{{#!hs {-# LANGUAGE TemplateHaskell #-} module Lib where import Language.Haskell.TH qIncompleteCase :: Q [Dec] qIncompleteCase = [d| incompleteCase :: Bool -> () incompleteCase b = case b of True -> () |] qIncompleteFunction :: Q [Dec] qIncompleteFunction =[d| incompleteFunction :: Bool -> () incompleteFunction True = () |] }}} {{{#!hs {-# LANGUAGE TemplateHaskell #-} module Bug where import Lib $qIncompleteCase $qIncompleteFunction incompleteCase' :: Bool -> () incompleteCase' b = case b of True -> () incompleteFunction' :: Bool -> () incompleteFunction' True = () }}} When compiling the above two files with `-Wall`, GHC 8.2.2 produces an "incomplete-patterns" warning for `qIncompleteCase`, `incompleteCase'`, and `incompleteFunction'`, but not for `qIncompleteFunction`. I would prefer to get a warning for `qIncompleteFunction` as well. My use case is the [https://hackage.haskell.org/package/surjective surjective] package, in which I intentionally generate code which produces warnings in order to warn the user about corresponding issues in their code. I could generate [https://github.com/gelisam/surjective/blob/master/src/Surjective.hs#L158-L16... better error messages] if GHC generated warnings for TH-generated functions as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 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 RyanGlScott): Amazing find. It turns out that this can all be tied back to this line of code (introduced in GHC 8.0, in commit 8a506104d5b5b71d5640afc69c992e0af40f2213): {{{#!hs ; unless (isGenerated origin) $ when (isAnyPmCheckEnabled dflags (DsMatchContext ctxt locn)) $ addTmCsDs (genCaseTmCs1 mb_scr new_vars) $ -- See Note [Type and Term Equality Propagation] checkMatches dflags (DsMatchContext ctxt locn) new_vars matches }}} Specifically, the `unless (isGenerated origin)` part. It turns out that `-Wincomplete-patterns` is completely suppressed for any code that has an `Origin` of `Generated`, and Template Haskell–spliced code happens to fall under that bucket. I see two ways out of this: 1. Go through the code in `Convert` and change every use of `Generated` to `FromSource`. 2. Come up with a separate origin for Template Haskell code (perhaps `FromTH`?). I'm not sure if it's worth the trouble, though. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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 RyanGlScott): * keywords: => PatternMatchWarnings -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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 simonpj): Nothing in the commit message explains why we suppress pattern match checks for generated code. Perhaps we shouldn't? I favour (1) until we see why it's a bad idea. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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 mpickering): I think the current behaviour of suppressing warnings might be better? If you see a warning arising from spliced code, what should you do about it? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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 simonpj): But there shouldn't ''be'' any warnings! And indeed this ticket is all about a warning that the user wanted but wasn't there. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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 RyanGlScott): I agree with Simon's reasoning. Moreover, it indeed appears that this was intended to be the case already, judging from [http://git.haskell.org/ghc.git/blob/34834234fff4a9dd0408d3b29e001cd132665327... this comment]: {{{#!hs --We use FromSource as the origin of the bind -- because the TH declaration is user-written }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings 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): Phab:D4440 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4440 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions
-------------------------------------+-------------------------------------
Reporter: gelisam | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Template Haskell | Version: 8.2.2
Resolution: | Keywords:
| PatternMatchWarnings
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): Phab:D4440
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.2.2 Resolution: fixed | Keywords: | PatternMatchWarnings Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: T14838 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4440 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: => T14838 * status: patch => closed * resolution: => fixed * milestone: => 8.6.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions
-------------------------------------+-------------------------------------
Reporter: gelisam | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.6.1
Component: Template Haskell | Version: 8.2.2
Resolution: fixed | Keywords:
| PatternMatchWarnings
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
error/warning at compile-time | Test Case: T14838
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4440
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: T14838 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4440 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: closed => new * resolution: fixed => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.10.1 Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: T14838 Blocked By: | Blocking: Related Tickets: #16169 | Differential Rev(s): Phab:D4440 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * related: => #16169 Comment: No idea why the original patch was reverted here but I still think close as working as intended. You wouldn't want a warning if an imported library function had an incomplete pattern so why is code generated by splices any different? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14838: missing "incomplete-patterns" warning for TH-generated functions -------------------------------------+------------------------------------- Reporter: gelisam | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.10.1 Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: | PatternMatchWarnings Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: T14838 Blocked By: | Blocking: Related Tickets: #16169 | Differential Rev(s): Phab:D4440 Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): For the sake of historical context, the original patch was in reverted in light of #14899, where it was discovered that the only reason that `singletons` compiles in a reasonable amount of time is because pattern- match coverage checking is disabled for generated code. Technically, the problem still exists if you were to write this code by hand, but we deemed `singletons` to be an important-enough reason not to keep the patch :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14838#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC