[GHC] #11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #1544, #11529 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When I run the following program `test-show.hs` on ghc 7.10.3: {{{#!hs data Y = Д星 String String deriving (Eq, Ord, Show, Read) data X = String :☆ String deriving (Eq, Ord, Show, Read) main :: IO () main = do let y = Д星 "" "" d = 0 print $ map fromEnum $ show y print $ (y, "") `elem` (readsPrec d (showsPrec d y "")) print $ (read $ show y :: Y) let x = "" :☆ "" d = 0 print $ map fromEnum $ show x print $ (x, "") `elem` (readsPrec d (showsPrec d x "")) print $ (read $ show x :: X) }}} I got the following results: {{{ $ stack ghc -- --version The Glorious Glasgow Haskell Compilation System, version 7.10.3 $ stack runhaskell test-show.hs [1044,26143,32,34,34,32,34,34] True Д星 "" "" [34,34,32,58,9734,32,34,34] False test-show.hs: Prelude.read: no parse }}} This behavior does not conform to Section 11.4 of Haskell 2010 Language Specification: https://www.haskell.org/onlinereport/haskell2010/haskellch11.html#x18-186000... :
It should be the case that (x,"") is an element of (readsPrec d (showsPrec d x ""))
-- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nushio): The condition for this bug is that the infix value constructor has at least one Unicode character. The prefix value constructors with Unicode characters, as well as infix value constructors without Unicode characters, works fine. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: => unicode Comment: nushio: maybe you could look into the cause and send a patch? See [wiki:Newcomers] and [wiki:WorkingConventions/FixingBugs]. Other unicode related tickets: [[TicketQuery(status=!closed,keywords=~unicode)]] -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nushio): Dear thomie: I'm excited to do so. I have `ghc` source downloaded and was able to compile it. Do you know where the deriving algorithm for `Read` is implemented? It will be helpful. Or, maybe should I ask in haskell-cafe ? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Search for `Read instances` in `compiler/typecheck/TcGenDeriv.hs`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nushio): Thank you very much, thomie! With that help now I have located the origin of this bug: {{{
readPrec_to_S (expectP $ L.Symbol ":+") 0 ":+" [((),"")] readPrec_to_S (expectP $ L.Symbol ":☆") 0 ":☆" []
}}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nushio): I actually found out that this issue #11535 have already been fixed as result of some other work between 7.10.3 and the latest head. What shall I do? I still can submit a patch with test cases for #11535, and I believe it is of some help to the ghc. {{{ ~/hub/ghc (fix-11535)$ cat tmp-lex-test.hs import GHC.Read import Text.ParserCombinators.ReadPrec import qualified Text.Read.Lex as L data X = String :☆\& String deriving (Eq, Ord, Show, Read) main :: IO () main = do print $ readPrec_to_S (expectP $ L.Symbol ":+") 0 ":+" print $ readPrec_to_S (expectP $ L.Symbol ":☆") 0 ":☆" let x = "" :☆\& "" d = 0 print $ map fromEnum $ show x print $ (x, "") `elem` (readsPrec d (showsPrec d x "")) print $ (read $ show x :: X) ~/hub/ghc (fix-11535)$ ./inplace/bin/runghc tmp-lex-test.hs [((),"")] [((),"")] [34,34,32,58,9734,92,38,32,34,34] True "" :☆\& "" ~/hub/ghc (fix-11535)$ stack runhaskell tmp-lex-test.hs Run from outside a project, using implicit global project config Using resolver: lts-5.0 from implicit global project's config file: /home/nushio/.stack/global-project/stack.yaml [((),"")] [] [34,34,32,58,9734,92,38,32,34,34] False tmp-lex-test.hs: Prelude.read: no parse ~/hub/ghc (fix-11535)$ stack ghc -- --version Run from outside a project, using implicit global project config Using resolver: lts-5.0 from implicit global project's config file: /home/nushio/.stack/global-project/stack.yaml The Glorious Glasgow Haskell Compilation System, version 7.10.3 ~/hub/ghc (fix-11535)$ git log | head -n 1 commit db121b2ec4596b99fed9781ec2d055f29e0d5b20 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Oops, sorry for not checking with 8.0 earlier. I don't know which commit fixed it. So yes, a patch for the testsuite would be good. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Phab:D1884 Wiki Page: | -------------------------------------+------------------------------------- Changes (by nushio): * differential: => Phab:D1884 Comment: I am sorry too, for not checking with the HEAD compiler (I did checked with stackage-nightly, but that was still 7.10.3 .) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Phab:D1884 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"1ef7add01ead4cbe065297f68306d9bc4b456156/ghc" 1ef7add/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="1ef7add01ead4cbe065297f68306d9bc4b456156" Add test (only) to assure that #11535 is fixed Ticket #11535 dealt with derived Read instances of infix Unicode value constructors. GHC 7.10.3 used to derive (Read/Show) instances so that `read . show` for values of such types had no parse. The issue has been fixed by other compiler update. This patch adds only tests, so that derived instance of Read/Show for infix Unicode value constructors has correct parse, satisfying Haskell 2010 Specification. Resolves: #11535 Test Plan: `make test TEST=T11535` Reviewers: austin, rwbarton, thomie, bgamari Reviewed By: rwbarton, thomie, bgamari Subscribers: rwbarton, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1884 GHC Trac Issues: #11535 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11535: Derived instance of Read/Show causes runtime exception for infix Unicode value constructors -------------------------------------+------------------------------------- Reporter: nushio | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: unicode Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1544, #11529 | Differential Rev(s): Phab:D1884 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => fixed * milestone: => 8.0.1 Comment: Thanks again nushio. And sorry for the delay, your patch was not showing up in the "Needs review" queue for some reason, so we kind of forgot about it for a while. I hope you can work on some of the other unicode tickets as well. (bgamari: This commit just added a test. Merge to 8.0 at will) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11535#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC