[commit: ghc] master: Fix #15550 by quoting RULE names during TH conversion (5e6cf2a)

git at git.haskell.org git at git.haskell.org
Mon Aug 27 13:39:36 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5e6cf2a9301a5473ff9c5319b96de941b1ad72dd/ghc

>---------------------------------------------------------------

commit 5e6cf2a9301a5473ff9c5319b96de941b1ad72dd
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Mon Aug 27 14:02:42 2018 +0200

    Fix #15550 by quoting RULE names during TH conversion
    
    Summary:
    When converting a `RuleP` to a GHC source `RuleD` during TH
    conversion, we were stupidly not double-quoting the name of the rule.
    Easily fixed.
    
    Test Plan: make test TEST=T15550
    
    Reviewers: goldfire, bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonpj, rwbarton, carter
    
    GHC Trac Issues: #15550
    
    Differential Revision: https://phabricator.haskell.org/D5090


>---------------------------------------------------------------

5e6cf2a9301a5473ff9c5319b96de941b1ad72dd
 compiler/hsSyn/Convert.hs        |  4 ++--
 testsuite/tests/th/T15550.hs     |  8 ++++++++
 testsuite/tests/th/T15550.stderr | 11 +++++++++++
 testsuite/tests/th/all.T         |  1 +
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
index 24b0b20..687c828 100644
--- a/compiler/hsSyn/Convert.hs
+++ b/compiler/hsSyn/Convert.hs
@@ -705,8 +705,8 @@ cvtPragmaD (RuleP nm bndrs lhs rhs phases)
        ; rhs'   <- cvtl rhs
        ; returnJustL $ Hs.RuleD noExt
             $ HsRules noExt (SourceText "{-# RULES")
-                      [noLoc $ HsRule noExt (noLoc (SourceText nm,nm')) act
-                                                  bndrs' lhs' rhs']
+                      [noLoc $ HsRule noExt (noLoc (quotedSourceText nm,nm'))
+                                                  act bndrs' lhs' rhs']
        }
 
 cvtPragmaD (AnnP target exp)
diff --git a/testsuite/tests/th/T15550.hs b/testsuite/tests/th/T15550.hs
new file mode 100644
index 0000000..538064c
--- /dev/null
+++ b/testsuite/tests/th/T15550.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T15550 where
+
+$([d| myId :: a -> a
+      myId x = x
+      {-# NOINLINE [1] myId #-}
+      {-# RULES "myId" forall x. myId x = x #-}
+    |])
diff --git a/testsuite/tests/th/T15550.stderr b/testsuite/tests/th/T15550.stderr
new file mode 100644
index 0000000..8169d75
--- /dev/null
+++ b/testsuite/tests/th/T15550.stderr
@@ -0,0 +1,11 @@
+T15550.hs:(4,3)-(8,6): Splicing declarations
+    [d| {-# RULES "myId" forall x. myId x = x #-}
+        
+        myId :: a -> a
+        myId x = x
+        {-# NOINLINE [1] myId #-} |]
+  ======>
+    myId :: a -> a
+    myId x = x
+    {-# NOINLINE [1] myId #-}
+    {-# RULES "myId" forall x. myId x = x #-}
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 5c7037d..55724dc 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -425,4 +425,5 @@ test('T14471', normal, compile, [''])
 test('TH_rebindableAdo', normal, compile, [''])
 test('T14627', normal, compile_fail, [''])
 test('TH_invalid_add_top_decl', normal, compile_fail, [''])
+test('T15550', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T15518', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])



More information about the ghc-commits mailing list