[GHC] #14869: Documentation for isLiftedTypeKind is incorrect
GHC
ghc-devs at haskell.org
Wed Feb 28 17:50:22 UTC 2018
#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:/compiler/types/Kind.hs#l68
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:/compiler/types/Kind.hs#l43
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
More information about the ghc-tickets
mailing list