[GHC] #12080: RebindableSyntax breaks deriving Ord

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer 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: #11396 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The code generated with `deriving (Ord)` includes if-expressions which are subject to rebindable syntax: {{{ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RebindableSyntax #-} import Prelude class IfThenElse a b where ifThenElse :: a -> b -> b -> b instance IfThenElse Bool b where ifThenElse c x y = if c then x else y data Foo = Foo | Bar | Baz deriving (Eq, Ord) main :: IO () main = print $ Foo < Bar }}} when loaded into ghci (7.10, but not specific to that version): {{{ [1 of 1] Compiling Main ( Foo.hs, interpreted ) Foo.hs:13:42: Bad call to tagToEnum# at type a_aQy Specify the type by giving a type signature e.g. (tagToEnum# x) :: Bool In the expression: (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) In the expression: if (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) then LT else if (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#)) then EQ else GT In a case alternative: b# -> if (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) then LT else if (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#)) then EQ else GT When typechecking the code for ‘compare’ in a derived instance for ‘Ord Foo’: To see the code I am typechecking, use -ddump-deriv Foo.hs:13:42: No instance for (IfThenElse a0 Ordering) arising from an if statement The type variable ‘a0’ is ambiguous Note: there is a potential instance available: instance IfThenElse Bool b -- Defined at Foo.hs:10:10 In the expression: if (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) then LT else if (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#)) then EQ else GT In a case alternative: b# -> if (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) then LT else if (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#)) then EQ else GT In the expression: case (Main.$con2tag_rjG b) of { b# -> if (GHC.Prim.tagToEnum# (a# GHC.Prim.<# b#)) then LT else if (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#)) then EQ else GT } When typechecking the code for ‘compare’ in a derived instance for ‘Ord Foo’: To see the code I am typechecking, use -ddump-deriv Failed, modules loaded: none. }}} The if-expressions are generated by `nlHsIf`, which calls `mkHsIf`, which uses `Just noSyntaxExpr` as its first argument. I'm going to add a new function `nlBuiltInHsIf` which uses `Nothing` as the first argument, forcing the built-in if (according to Note [Rebindable if]), then use this new function when deriving stuff. I'll post a patch soonish. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer 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: #11396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Good catch. Shouldn't `nlHsIf` always use builtin syntax? Do we really need a new function? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer 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: #11396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by afarmer): Ah good point. I thought `nlHsIf` was used in more places. I'll just change it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer 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: #11396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): OK. Please comment `nHsIf` to point out the significance of the `Nothing` and explain why that choice is important. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer 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: #11396 | Differential Rev(s): Phab:D2247 Wiki Page: | -------------------------------------+------------------------------------- Changes (by afarmer): * differential: => Phab:D2247 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord
-------------------------------------+-------------------------------------
Reporter: afarmer | Owner: afarmer
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: #11396 | Differential Rev(s): Phab:D2247
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 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: #11396 | Differential Rev(s): Phab:D2247 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => merge * milestone: => 8.0.2 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11396 | Differential Rev(s): Phab:D2247 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-8.0` as cd5c5c3f3b0c63240058efe96cb12079fb03133e. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12080: RebindableSyntax breaks deriving Ord -------------------------------------+------------------------------------- Reporter: afarmer | Owner: afarmer Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11396 | Differential Rev(s): Phab:D2247 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => deriving -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12080#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC