[GHC] #11316: Too many guards warning causes issues
GHC
ghc-devs at haskell.org
Wed Dec 30 08:56:21 UTC 2015
#11316: Too many guards warning causes issues
-------------------------------------+-------------------------------------
Reporter: NeilMitchell | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
GHC HEAD warns if you have too many guards, for example:
{{{
src/HSE/Bracket.hs:44:5: warning:
Too many guards in an equation for ‘needBracket’
Guard checking has been over-simplified
(Use: -Wno-too-many-guards to suppress this warning
-ffull-guard-reasoning
to run the full checker (may increase
compilation time and memory consumption))
}}}
The code in question is from
https://github.com/ndmitchell/hlint/blob/master/src/HSE/Bracket.hs#L44 and
reads:
{{{#!hs
needBracket i parent child
| isAtom child = False
| InfixApp{} <- parent, App{} <- child = False
| isSection parent, App{} <- child = False
| Let{} <- parent, App{} <- child = False
| ListComp{} <- parent = False
| List{} <- parent = False
| Tuple{} <- parent = False
| If{} <- parent, isAnyApp child = False
| App{} <- parent, i == 0, App{} <- child = False
| ExpTypeSig{} <- parent, i == 0, isApp child = False
| Paren{} <- parent = False
| isDotApp parent, isDotApp child, i == 1 = False
| RecConstr{} <- parent = False
| RecUpdate{} <- parent, i /= 0 = False
| Case{} <- parent, i /= 0 || isAnyApp child = False
| Lambda{} <- parent, i == length (universeBi parent :: [Pat_]) -
1 = False -- watch out for PViewPat
| Do{} <- parent = False
| otherwise = True
}}}
For code that runs with the default flags, and likes to have zero warnings
(or warnings as errors), and compile with multiple GHC versions, that is
problematic. How can I suppress this warning?
* Adding {{{-Wno-too-many-guards}}} will only work with GHC 8, so I need
to either use CPP to version select my warning suppression, or
conditionality outside the compiler select the flags.
* Or I can give up on detecting warnings as errors, which is a bit sad, as
it's generally a useful criteria.
* Or I can modify my code to make it harder to read in order to satisfy a
checker whose semantics might change in future.
* Or GHC could not warn on too many guards, because it's really a warning
that the compiler can't cope, not that too many guards is necessarily bad.
I suggest the last option, because warnings should generally be about code
issues, not compiler issues.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11316>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list