summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-02-23 16:19:34 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-01 17:32:48 -0500
commite571eda75f979e315ff87997e58ed99eb9d874c9 (patch)
treed6fdcc849402b9ddb657960ded482a979121b42f /docs
parent51828c6daedc5ba0843706bba65dfe396648944c (diff)
downloadhaskell-e571eda75f979e315ff87997e58ed99eb9d874c9.tar.gz
Pmc: Implement `considerAccessible` (#18610)
Consider (`T18610`): ```hs f :: Bool -> Int f x = case (x, x) of (True, True) -> 1 (False, False) -> 2 (True, False) -> 3 -- Warning: Redundant ``` The third clause will be flagged as redundant. Nevertheless, the programmer might intend to keep the clause in order to avoid bitrot. After this patch, the programmer can write ```hs g :: Bool -> Int g x = case (x, x) of (True, True) -> 1 (False, False) -> 2 (True, False) | GHC.Exts.considerAccessible -> 3 -- No warning ``` And won't be bothered any longer. See also `Note [considerAccessible]` and the updated entries in the user's guide. Fixes #18610 and #19228.
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/9.2.1-notes.rst17
-rw-r--r--docs/users_guide/using-warnings.rst28
2 files changed, 40 insertions, 5 deletions
diff --git a/docs/users_guide/9.2.1-notes.rst b/docs/users_guide/9.2.1-notes.rst
index 9812279849..918f8ebae8 100644
--- a/docs/users_guide/9.2.1-notes.rst
+++ b/docs/users_guide/9.2.1-notes.rst
@@ -114,15 +114,12 @@ Runtime system
Moreover, we now correctly account for the size of the array, meaning that
space lost to fragmentation is no longer counted as live data.
-- The :rts-flag:`-h` flag has been deprecated, use either :rts-flag:`-hc` or
- :rts-flag:`-hT` explicitly, as appropriate.
+
- The ``-xt`` RTS flag has been removed. Now STACK and TSO closures are always
included in heap profiles. Tooling can choose to filter out these closure types
- if necessary.
+` if necessary.
-``ghc-prim`` library
-~~~~~~~~~~~~~~~~~~~~
- ``Void#`` is now a type synonym for the unboxed tuple ``(# #)``.
Code using ``Void#`` now has to enable :extension:`UnboxedTuples`.
@@ -203,3 +200,13 @@ Runtime system
- On POSIX, ``System.IO.openFile`` can no longer leak a file descriptor if it
is interrupted by an asynchronous exception (#19114, #19115).
+
+- There's a new binding ``GHC.Exts.considerAccessible``. It's equivalent to
+ ``True`` and allows the programmer to turn off pattern-match redundancy
+ warnings for particular clauses, like the third one here ::
+
+ g :: Bool -> Int
+ g x = case (x, x) of
+ (True, True) -> 1
+ (False, False) -> 2
+ (True, False) | considerAccessible -> 3 -- No warning!
diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst
index a9995268ea..3c09d4c141 100644
--- a/docs/users_guide/using-warnings.rst
+++ b/docs/users_guide/using-warnings.rst
@@ -1235,6 +1235,34 @@ of ``-W(no-)*``.
second pattern overlaps it. More often than not, redundant patterns
is a programmer mistake/error, so this option is enabled by default.
+ If the programmer is dead set of keeping a redundant clause,
+ for example to prevent bitrot, they can make use of a guard
+ scrutinising ``GHC.Exts.considerAccessible`` to prevent the
+ checker from flagging the parent clause as redundant: ::
+
+ g :: String -> Int
+ g [] = 0
+ g (_:xs) = 1
+ g "2" | considerAccessible = 2 -- No warning!
+
+ Note that ``considerAccessible`` should come as the last statement of
+ the guard in order not to impact the results of the checker. E.g., if
+ you write ::
+
+ h :: Bool -> Int
+ h x = case (x, x) of
+ (True, True) -> 1
+ (False, False) -> 2
+ (True, False) | considerAccessible, False <- x -> 3
+
+ The pattern-match checker takes you by your word, will conclude
+ that ``False <- x`` might fail and warn that the pattern-match
+ is inexhaustive. Put ``considerAccessible`` last to avoid such
+ confusions.
+
+ Note that due to technical limitations, ``considerAccessible`` will not
+ suppress :ghc-flag:`-Winaccessible-code` warnings.
+
.. ghc-flag:: -Winaccessible-code
:shortdesc: warn about inaccessible code
:type: dynamic