From 9b2afdf88da89ee1468c1a1c366791d615454258 Mon Sep 17 00:00:00 2001 From: David Binder Date: Tue, 12 Sep 2023 08:51:46 +0200 Subject: [PATCH] Document GHC-56147 (#462) * Document GHC-56147 * Apply suggestions from code review Co-authored-by: David Thrane Christiansen * Apply suggestion from code review --------- Co-authored-by: David Thrane Christiansen --- .../GHC-56147/ignored-rule/after/IgnoredRule.hs | 6 ++++++ .../GHC-56147/ignored-rule/before/IgnoredRule.hs | 6 ++++++ .../messages/GHC-56147/ignored-rule/index.md | 14 ++++++++++++++ message-index/messages/GHC-56147/index.md | 10 ++++++++++ 4 files changed, 36 insertions(+) create mode 100644 message-index/messages/GHC-56147/ignored-rule/after/IgnoredRule.hs create mode 100644 message-index/messages/GHC-56147/ignored-rule/before/IgnoredRule.hs create mode 100644 message-index/messages/GHC-56147/ignored-rule/index.md create mode 100644 message-index/messages/GHC-56147/index.md diff --git a/message-index/messages/GHC-56147/ignored-rule/after/IgnoredRule.hs b/message-index/messages/GHC-56147/ignored-rule/after/IgnoredRule.hs new file mode 100644 index 00000000..37d72485 --- /dev/null +++ b/message-index/messages/GHC-56147/ignored-rule/after/IgnoredRule.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE Safe #-} +module IgnoredRule where + + +myId :: a -> a +myId x = x diff --git a/message-index/messages/GHC-56147/ignored-rule/before/IgnoredRule.hs b/message-index/messages/GHC-56147/ignored-rule/before/IgnoredRule.hs new file mode 100644 index 00000000..89b58b53 --- /dev/null +++ b/message-index/messages/GHC-56147/ignored-rule/before/IgnoredRule.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE Safe #-} +module IgnoredRule where + +{-# RULES "myId" forall x. myId x = x #-} +myId :: a -> a +myId x = x diff --git a/message-index/messages/GHC-56147/ignored-rule/index.md b/message-index/messages/GHC-56147/ignored-rule/index.md new file mode 100644 index 00000000..63da9aaa --- /dev/null +++ b/message-index/messages/GHC-56147/ignored-rule/index.md @@ -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 #-} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +``` diff --git a/message-index/messages/GHC-56147/index.md b/message-index/messages/GHC-56147/index.md new file mode 100644 index 00000000..f45bb0b5 --- /dev/null +++ b/message-index/messages/GHC-56147/index.md @@ -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.