Skip to content

Commit 9b2afdf

Browse files
Document GHC-56147 (#462)
* Document GHC-56147 * Apply suggestions from code review Co-authored-by: David Thrane Christiansen <[email protected]> * Apply suggestion from code review --------- Co-authored-by: David Thrane Christiansen <[email protected]>
1 parent bd61dfa commit 9b2afdf

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE Safe #-}
2+
module IgnoredRule where
3+
4+
5+
myId :: a -> a
6+
myId x = x
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE Safe #-}
2+
module IgnoredRule where
3+
4+
{-# RULES "myId" forall x. myId x = x #-}
5+
myId :: a -> a
6+
myId x = x
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Cannot add a rewrite rule for the identity function
3+
---
4+
5+
Wanting to rewrite occurrences of `myId x` to `x` in programs is sensible. But since GHC cannot check in general whether rewrite rules violate the guarantees of SafeHaskell, GHC chooses to ignore all such rules in modules which are annotated as `Safe`.These rewrite rules should therefore be removed.
6+
7+
```
8+
messages/GHC-56147/ignored-rule/before/IgnoredRule.hs:4:11: warning: [GHC-56147]
9+
Rule "myId" ignored
10+
Defining user rules is disabled under Safe Haskell
11+
|
12+
4 | {-# RULES "myId" forall x. myId x = x #-}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Rewrite rules are ignored in Safe Haskell
3+
summary: Rewrite rules are not allowed in Safe Haskell and are therefore ignored
4+
severity: warning
5+
introduced: 9.6.1
6+
---
7+
8+
GHC implements the `SafeHaskell` extension which allows programmers to restrict modules to a specific subset which is considered safe and does not contain loopholes such as `unsafePerformIO`.
9+
More details are available in [the GHC User's Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/safe_haskell.html).
10+
One of the features which isn't considered safe are user-specified rewrite rules. GHC therefore warns that all rewrite rules in a module which is declared safe will be ignored.

0 commit comments

Comments
 (0)