[GHC] #14869: Documentation for isLiftedTypeKind is incorrect

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Documentation Unknown/Multiple | bug Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I [https://github.com/ghc-proposals/ghc- proposals/pull/32#issuecomment-369252383 noticed recently] that Template Haskell reifies `Constraint` as `Type`: {{{#!hs $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :set -XTypeFamilies -XTemplateHaskell λ> :m + Data.Kind Language.Haskell.TH λ> type family Foo :: Constraint λ> putStrLn $(reify ''Foo >>= stringE . pprint) type family Ghci1.Foo :: * }}} The root of the issue can be traced back to the `isLiftedTypeKind` function, which `TcSplice` uses to distinguish `Type` from `Constraint`. At least, that's what its [http://git.haskell.org/ghc.git/blob/df2c3b3364834d2fd038192c89348fc50a2e0475... documentation] claims: {{{ -- | This version considers Constraint to be distinct from *. Returns True -- if the argument is equivalent to Type and False otherwise. isLiftedTypeKind :: Kind -> Bool isLiftedTypeKind = is_TYPE is_lifted where is_lifted (TyConApp lifted_rep []) = lifted_rep `hasKey` liftedRepDataConKey is_lifted _ = False }}} However, in practice this claim about treating `Constraint` and `Type` as distinct is false: {{{ $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive -package ghc GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :m + TyCoRep TysWiredIn λ> isLiftedTypeKind liftedTypeKind True λ> isLiftedTypeKind constraintKind True }}} Either we should change the implementation of `isLiftedTypeKind` to match the documentation's claim, or change the documentation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by RyanGlScott: Old description:
I [https://github.com/ghc-proposals/ghc- proposals/pull/32#issuecomment-369252383 noticed recently] that Template Haskell reifies `Constraint` as `Type`:
{{{#!hs $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :set -XTypeFamilies -XTemplateHaskell λ> :m + Data.Kind Language.Haskell.TH λ> type family Foo :: Constraint λ> putStrLn $(reify ''Foo >>= stringE . pprint) type family Ghci1.Foo :: * }}}
The root of the issue can be traced back to the `isLiftedTypeKind` function, which `TcSplice` uses to distinguish `Type` from `Constraint`. At least, that's what its [http://git.haskell.org/ghc.git/blob/df2c3b3364834d2fd038192c89348fc50a2e0475... documentation] claims:
{{{ -- | This version considers Constraint to be distinct from *. Returns True -- if the argument is equivalent to Type and False otherwise. isLiftedTypeKind :: Kind -> Bool isLiftedTypeKind = is_TYPE is_lifted where is_lifted (TyConApp lifted_rep []) = lifted_rep `hasKey` liftedRepDataConKey is_lifted _ = False }}}
However, in practice this claim about treating `Constraint` and `Type` as distinct is false:
{{{ $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive -package ghc GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :m + TyCoRep TysWiredIn λ> isLiftedTypeKind liftedTypeKind True λ> isLiftedTypeKind constraintKind True }}}
Either we should change the implementation of `isLiftedTypeKind` to match the documentation's claim, or change the documentation.
New description: I [https://github.com/ghc-proposals/ghc- proposals/pull/32#issuecomment-369252383 noticed recently] that Template Haskell reifies `Constraint` as `Type`: {{{ $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :set -XTypeFamilies -XTemplateHaskell λ> :m + Data.Kind Language.Haskell.TH λ> type family Foo :: Constraint λ> putStrLn $(reify ''Foo >>= stringE . pprint) type family Ghci1.Foo :: * }}} The root of the issue can be traced back to the `isLiftedTypeKind` function, which `TcSplice` uses to distinguish `Type` from `Constraint`. At least, that's what its [http://git.haskell.org/ghc.git/blob/df2c3b3364834d2fd038192c89348fc50a2e0475... documentation] claims: {{{ -- | This version considers Constraint to be distinct from *. Returns True -- if the argument is equivalent to Type and False otherwise. isLiftedTypeKind :: Kind -> Bool isLiftedTypeKind = is_TYPE is_lifted where is_lifted (TyConApp lifted_rep []) = lifted_rep `hasKey` liftedRepDataConKey is_lifted _ = False }}} However, in practice this claim about treating `Constraint` and `Type` as distinct is false: {{{ $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive -package ghc GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :m + TyCoRep TysWiredIn λ> isLiftedTypeKind liftedTypeKind True λ> isLiftedTypeKind constraintKind True }}} Either we should change the implementation of `isLiftedTypeKind` to match the documentation's claim, or change the documentation. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Amusingly, the `Constraint` counterpart, `isLiftedTypeKind`, actually appears to do [http://git.haskell.org/ghc.git/blob/df2c3b3364834d2fd038192c89348fc50a2e0475... the right thing]: {{{#!hs isConstraintKind :: Kind -> Bool isConstraintKindCon :: TyCon -> Bool isConstraintKindCon tc = tyConUnique tc == constraintKindTyConKey isConstraintKind (TyConApp tc _) = isConstraintKindCon tc isConstraintKind _ = False }}} This actually checks the unique of the tycon, and per `Note [Kind Constraint and kind *]`, the uniques for `Type` and `Constraint` [http://git.haskell.org/ghc.git/blob/df2c3b3364834d2fd038192c89348fc50a2e0475... are different]. Thus: {{{ $ inplace/bin/ghc-stage2 --interactive -package ghc GHCi, version 8.5.20180221: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci λ> :m + Kind TysWiredIn λ> isConstraintKind liftedTypeKind False λ> isConstraintKind constraintKind True }}} Thus, to fix the aforementioned Template Haskell bug, all we'd have to do is make this change: {{{#!diff diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs index 45e18e6..b052e8e 100644 --- a/compiler/typecheck/TcSplice.hs +++ b/compiler/typecheck/TcSplice.hs @@ -1707,8 +1707,8 @@ reifyFamilyInstance is_poly_tvs inst@(FamInst { fi_flavor = flavor ------------------------------ reifyType :: TyCoRep.Type -> TcM TH.Type -- Monadic only because of failure -reifyType ty | isLiftedTypeKind ty = return TH.StarT - | isConstraintKind ty = return TH.ConstraintT +reifyType ty | isConstraintKind ty = return TH.ConstraintT + | isLiftedTypeKind ty = return TH.StarT reifyType ty@(ForAllTy {}) = reify_for_all ty reifyType (LitTy t) = do { r <- reifyTyLit t; return (TH.LitT r) } reifyType (TyVarTy tv) = return (TH.VarT (reifyName tv)) }}} ----- I propose that we: 1. Change the documentation for `isLiftedTypeKind` to reflect the fact that it does not distinguish between `Constraint` and `Type`. 2. Make the above change to `TcSplice` to fix the bug. Does that sound reasonable? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
I propose that we:
Yes that sounds reasonable. Thanks -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4474 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4474 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14869: Documentation for isLiftedTypeKind is incorrect
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.2.2
checker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Documentation | Unknown/Multiple
bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4474
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#14869: Documentation for isLiftedTypeKind is incorrect -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.2.2 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: th/T14869 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4474 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => th/T14869 * status: patch => closed * resolution: => fixed * milestone: => 8.6.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14869#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC