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

#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 | Version: 8.4.3 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Compile the following program: {{{#!hs {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -ddump-splices #-} module Bug where $([d| myId :: a -> a myId x = x {-# NOINLINE [1] myId #-} {-# RULES "myId" forall x. myId x = x #-} |]) }}} {{{ $ /opt/ghc/8.4.3/bin/ghci Bug.hs GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/ryanglscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:(5,3)-(9,6): Splicing declarations [d| {-# RULES "myId" forall x_a1xu. myId_a1xr x_a1xu = x_a1xu #-} myId_a1xr :: a_a1xs -> a_a1xs myId_a1xr x_a1xt = x_a1xt {-# NOINLINE [1] myId_a1xr #-} |] ======> myId_a49f :: a_a49e -> a_a49e myId_a49f x_a49g = x_a49g {-# NOINLINE [1] myId_a49f #-} {-# RULES myId forall x_a49h. myId_a49f x_a49h = x_a49h #-} Ok, one module loaded. }}} Notice how in the bottom of the `-ddump-splices` output, the name of the rewrite rule for `myId` isn't surrounded by double quotes, thus making it syntactically invalid. That is, it's printed as: {{{#!hs {-# RULES myId forall x_a49h. myId_a49f x_a49h = x_a49h #-} }}} Whereas it should be: {{{#!hs {-# RULES "myId" forall x_a49h. myId_a49f x_a49h = x_a49h #-} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15550 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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... 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

#15550: Names of RULES aren't quoted in -ddump-splices -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch 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): Phab:D5090 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D5090 Comment: I decided to just go with the `quotedSourceText` option for now in Phab:D5090. We can always revisit the `SourceText`-in-`Convert` question later. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15550#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15550: Names of RULES aren't quoted in -ddump-splices -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch 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): Phab:D5090 Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): @RyanGlScott, I have been snowed,sorry. I think `NoSourceText` is probably the better option here, to be honest. But in the bigger scheme of things probably does not matter all that much. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15550#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15550: Names of RULES aren't quoted in -ddump-splices
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
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): Phab:D5090
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Krzysztof Gogolewski

#15550: Names of RULES aren't quoted in -ddump-splices -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: merge 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): Phab:D5090 Wiki Page: | -------------------------------------+------------------------------------- Changes (by monoidal): * status: patch => merge Comment: If it's not too late, this can be merged to 8.6. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15550#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15550: Names of RULES aren't quoted in -ddump-splices -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5090 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged with 2cdb2de12ce4a96269cfa5fcd69dabfc4eb99786. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15550#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC