-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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]>
- Loading branch information
1 parent
bd61dfa
commit 9b2afdf
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-56147/ignored-rule/after/IgnoredRule.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{-# LANGUAGE Safe #-} | ||
module IgnoredRule where | ||
|
||
|
||
myId :: a -> a | ||
myId x = x |
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-56147/ignored-rule/before/IgnoredRule.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{-# LANGUAGE Safe #-} | ||
module IgnoredRule where | ||
|
||
{-# RULES "myId" forall x. myId x = x #-} | ||
myId :: a -> a | ||
myId x = x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: Cannot add a rewrite rule for the identity function | ||
--- | ||
|
||
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. | ||
|
||
``` | ||
messages/GHC-56147/ignored-rule/before/IgnoredRule.hs:4:11: warning: [GHC-56147] | ||
Rule "myId" ignored | ||
Defining user rules is disabled under Safe Haskell | ||
| | ||
4 | {-# RULES "myId" forall x. myId x = x #-} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: Rewrite rules are ignored in Safe Haskell | ||
summary: Rewrite rules are not allowed in Safe Haskell and are therefore ignored | ||
severity: warning | ||
introduced: 9.6.1 | ||
--- | ||
|
||
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`. | ||
More details are available in [the GHC User's Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/safe_haskell.html). | ||
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. |