diff options
author | nineonine <mail4chemik@gmail.com> | 2020-05-22 00:41:55 -0700 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-08-19 18:47:39 -0400 |
commit | 731c8d3bc5a84515793e5dadb26adf52f9280e13 (patch) | |
tree | 2a5fbdc0e4eccc3b8e31fe07832755cb6ab18a70 /compiler/GHC/Platform | |
parent | 0c5ed5c7eb30bc5462b67ff097c3388597265a4b (diff) | |
download | haskell-731c8d3bc5a84515793e5dadb26adf52f9280e13.tar.gz |
Implement -Wredundant-bang-patterns (#17340)
Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs.
Dead bangs are the ones that under no circumstances can force a thunk that
wasn't already forced. Dead bangs are a form of redundant bangs. The new check
is performed in Pattern-Match Coverage Checker along with other checks (namely,
redundant and inaccessible RHSs). Given
f :: Bool -> Int
f True = 1
f !x = 2
we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable
where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is
dead. Such a dead bang is then indicated in the annotated pattern-match tree by
a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect
all dead bangs to warn about.
Note that we don't want to warn for a dead bang that appears on a redundant
clause. That is because in that case, we recommend to delete the clause wholly,
including its leading pattern match.
Dead bang patterns are redundant. But there are bang patterns which are
redundant that aren't dead, for example
f !() = 0
the bang still forces the match variable, before we attempt to match on (). But
it is redundant with the forcing done by the () match. We currently don't
detect redundant bangs that aren't dead.
Diffstat (limited to 'compiler/GHC/Platform')
0 files changed, 0 insertions, 0 deletions