[GHC] #15790: String literals are not escaped in -ddump-splices

#15790: String literals are not escaped in -ddump-splices -------------------------------------+------------------------------------- Reporter: michalrus | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 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: -------------------------------------+------------------------------------- For example, with this code: `Main.hs`: {{{#!hs {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -ddump-splices -ddump-to-file #-} module Main where main :: IO () main = do putStrLn $( [| "\n\n\n" |] ) putStrLn $( [| "\"" |] ) }}} This is output: `Main.dump-splices`: {{{ Main.hs:8:15-28: Splicing expression [| "\n\n\n" |] ======> " " Main.hs:9:15-24: Splicing expression [| "\"" |] ======> """ }}} … which is not valid Haskell. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15790 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15790: String literals are not escaped in -ddump-splices -------------------------------------+------------------------------------- Reporter: michalrus | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 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: | -------------------------------------+------------------------------------- Comment (by michalrus): So, intuitively, this seems like a low hanging fruit. It’s Sunday, so I’d maybe want to try to submit a patch. I’ll report a possible failure. !^.!^ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15790#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15790: String literals are not escaped in -ddump-splices -------------------------------------+------------------------------------- Reporter: michalrus | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #4436 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #4436 Comment: Hah. It actually used to be the case that `\n` characters //were// escaped in `-ddump-splices`. However, someone specifically requested to change that to the current behavior (printing `\n` as newlines) in #4436. I'm not sure which behavior is better, given that separate groups of people want different things here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15790#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15790: String literals are not escaped in -ddump-splices -------------------------------------+------------------------------------- Reporter: michalrus | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #4436 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by michalrus): I see. =) But isn’t output of `-ddump-splices` supposed to be valid Haskell? If it was, then that would settle it. The manual says:
`-ddump-splices`
Dump Template Haskell expressions that we splice in, and **what Haskell code** the expression evaluates to.
— https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/debugging.ht... #ghc-flag--ddump-splices
At the same time, I can see the reasoning behind breaking such strings in #4436. After all, it’s a debugging flag, with output meant for human consumption. I’d like to propose, then, in line with #13190’s ideas, a patch, which causes `-ddump-splices` output to be JSON if the `-ddump-json` flag is present, and in which JSON the string literals would be escaped properly, as they would be in valid Haskell code? This way we get a clear distinction between human– and machine-targeted output. Would that be accepted? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15790#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC