[GHC] #15550: Names of RULES aren't quoted in -ddump-splices

GHC ghc-devs at haskell.org
Wed Aug 22 00:35:03 UTC 2018


#15550: Names of RULES aren't quoted in -ddump-splices
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Template Haskell  |              Version:  8.4.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * cc: alanz (added)


Comment:

 So I've identified the problem, which lies in `Convert`: when converting a
 Template Haskell `RuleP` into a GHC source `RuleD`, we take the `RuleP`'s
 name (which is not surrounded in double quotes) and repurpose that as the
 `SourceText` for the `RuleD`'s name. However, the `RuleD` name's
 `SourceText` must be intended to be the precise name of the rewrite rule,
 double quotes and all, since using the unquoted name from the `RuleP`
 causes it to be pretty-printed without double quotes.

 In light of this, one way to fix this issue is with this patch:

 {{{#!diff
 diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
 index 24b0b20..87b3400 100644
 --- a/compiler/hsSyn/Convert.hs
 +++ b/compiler/hsSyn/Convert.hs
 @@ -705,7 +705,7 @@ 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
 +                      [noLoc $ HsRule noExt (noLoc
 (quotedSourceText,nm')) act
                                                    bndrs' lhs' rhs']
         }
 }}}

 However, this leads me to wonder: is this `SourceText` name supposed to
 reflect a //user-written// rule name? That is, the exact syntax that the
 user types in a source Haskell file? If so, then it feels somewhat strange
 to put a `SourceText` here, since this `RuleD` is generated through
 Template Haskell behind the scenes, not through source syntax.

 In fact, another way to fix this issue is by not using `SourceText` at
 all, and instead using `NoSourceText`:

 {{{#!diff
 diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
 index 24b0b20..87b3400 100644
 --- a/compiler/hsSyn/Convert.hs
 +++ b/compiler/hsSyn/Convert.hs
 @@ -705,7 +705,7 @@ 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
 +                      [noLoc $ HsRule noExt (noLoc (NoSourceText,nm'))
 act
                                                    bndrs' lhs' rhs']
         }
 }}}

 (See
 [http://git.haskell.org/ghc.git/blob/21f0f56164f50844c2150c62f950983b2376f8b6:/compiler/hsSyn/HsDecls.hs#l2193
 pprFullRuleName] to see why that gets pretty-printed correctly.)

 I honestly have no idea which is the correct choice to make. Other places
 in `Convert` seem to vary in their uses of `SourceText` and
 `NoSourceText`, so it's hard to tell if there's already an established
 convention in `Convert`.

 alanz, what are your thoughts on this?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15550#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list