cmpTc :: TyCon -> TyCon -> Ordering
-- Here we treat * and Constraint as equal
-- See Note [Kind Constraint and kind *] in Kinds.lhs
--
-- Also we treat OpenTypeKind as equal to either * or #
-- See Note [Comparison with OpenTypeKind]
cmpTc tc1 tc2
  | u1 == openTypeKindTyConKey, isSubOpenTypeKindKey u2 = EQ
  | u2 == openTypeKindTyConKey, isSubOpenTypeKindKey u1 = EQ
  | otherwise = nu1 `compare` nu2
  where
    u1  = tyConUnique tc1
    nu1 = if u1==constraintKindTyConKey then liftedTypeKindTyConKey else u1
    u2  = tyConUnique tc2
    nu2 = if u2==constraintKindTyConKey then liftedTypeKindTyConKey else u2

{-
Note [Comparison with OpenTypeKind]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In PrimOpWrappers we have things like
   PrimOpWrappers.mkWeak# = /\ a b c. Prim.mkWeak# a b c
where
   Prim.mkWeak# :: forall (a:Open) b c. a -> b -> c
                                     -> State# RealWorld -> (# State# RealWorld, Weak# b #)
Now, eta reduction will turn the definition into
     PrimOpWrappers.mkWeak# = Prim.mkWeak#
which is kind-of OK, but now the types aren't really equal.  So HACK HACK
we pretend (in Core) that Open is equal to * or #.  I hate this.

Note [cmpTypeX]
~~~~~~~~~~~~~~~

When we compare foralls, we should look at the kinds. But if we do so,
we get a corelint error like the following (in
libraries/ghc-prim/GHC/PrimopWrappers.hs):

    Binder's type: forall (o_abY :: *).
                   o_abY
                   -> GHC.Prim.State# GHC.Prim.RealWorld
                   -> GHC.Prim.State# GHC.Prim.RealWorld
    Rhs type: forall (a_12 :: ?).
              a_12
              -> GHC.Prim.State# GHC.Prim.RealWorld
              -> GHC.Prim.State# GHC.Prim.RealWorld

This is why we don't look at the kind. Maybe we should look if the
kinds are compatible.

-- cmpTypeX env (ForAllTy tv1 t1)   (ForAllTy tv2 t2)
--   = cmpTypeX env (tyVarKind tv1) (tyVarKind tv2) `thenCmp`
--     cmpTypeX (rnBndr2 env tv1 tv2) t1 t2

************************************************************************
*                                                                      *
                Type substitutions
*                                                                      *
************************************************************************
-}
cmpTc :: TyCon -> TyCon -> Ordering
cmpTc tc1 tc2
  | u1 == openTypeKindTyConKey, isSubOpenTypeKindKey u2 = EQ
  | u2 == openTypeKindTyConKey, isSubOpenTypeKindKey u1 = EQ
  | otherwise = nu1 `compare` nu2
  where
    u1  = tyConUnique tc1
    nu1 = if u1==constraintKindTyConKey then liftedTypeKindTyConKey else u1
    u2  = tyConUnique tc2
    nu2 = if u2==constraintKindTyConKey then liftedTypeKindTyConKey else u2

{-
Note [Comparison with OpenTypeKind]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In PrimOpWrappers we have things like
   PrimOpWrappers.mkWeak# = /\ a b c. Prim.mkWeak# a b c
where
   Prim.mkWeak# :: forall (a:Open) b c. a -> b -> c
                                     -> State# RealWorld -> (# State# RealWorld, Weak# b #)
Now, eta reduction will turn the definition into
     PrimOpWrappers.mkWeak# = Prim.mkWeak#
which is kind-of OK, but now the types aren't really equal.  So HACK HACK
we pretend (in Core) that Open is equal to * or #.  I hate this.

Note [cmpTypeX]
~~~~~~~~~~~~~~~

When we compare foralls, we should look at the kinds. But if we do so,
we get a corelint error like the following (in
libraries/ghc-prim/GHC/PrimopWrappers.hs):

    Binder's type: forall (o_abY :: *).
                   o_abY
                   -> GHC.Prim.State# GHC.Prim.RealWorld
                   -> GHC.Prim.State# GHC.Prim.RealWorld
    Rhs type: forall (a_12 :: ?).
              a_12
              -> GHC.Prim.State# GHC.Prim.RealWorld
              -> GHC.Prim.State# GHC.Prim.RealWorld

This is why we don't look at the kind. Maybe we should look if the
kinds are compatible.

-- cmpTypeX env (ForAllTy tv1 t1)   (ForAllTy tv2 t2)
--   = cmpTypeX env (tyVarKind tv1) (tyVarKind tv2) `thenCmp`
--     cmpTypeX (rnBndr2 env tv1 tv2) t1 t2

************************************************************************
*                                                                      *
                Type substitutions
*                                                                      *
************************************************************************
-}
cmpTc tc1 tc2
  | u1 == openTypeKindTyConKey, isSubOpenTypeKindKey u2 = EQ
  | u2 == openTypeKindTyConKey, isSubOpenTypeKindKey u1 = EQ
  | otherwise = nu1 `compare` nu2
  where
    u1  = tyConUnique tc1
    nu1 = if u1==constraintKindTyConKey then liftedTypeKindTyConKey else u1
    u2  = tyConUnique tc2
    nu2 = if u2==constraintKindTyConKey then liftedTypeKindTyConKey else u2

{-
Note [Comparison with OpenTypeKind]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In PrimOpWrappers we have things like
   PrimOpWrappers.mkWeak# = /\ a b c. Prim.mkWeak# a b c
where
   Prim.mkWeak# :: forall (a:Open) b c. a -> b -> c
                                     -> State# RealWorld -> (# State# RealWorld, Weak# b #)
Now, eta reduction will turn the definition into
     PrimOpWrappers.mkWeak# = Prim.mkWeak#
which is kind-of OK, but now the types aren't really equal.  So HACK HACK
we pretend (in Core) that Open is equal to * or #.  I hate this.

Note [cmpTypeX]
~~~~~~~~~~~~~~~

When we compare foralls, we should look at the kinds. But if we do so,
we get a corelint error like the following (in
libraries/ghc-prim/GHC/PrimopWrappers.hs):

    Binder's type: forall (o_abY :: *).
                   o_abY
                   -> GHC.Prim.State# GHC.Prim.RealWorld
                   -> GHC.Prim.State# GHC.Prim.RealWorld
    Rhs type: forall (a_12 :: ?).
              a_12
              -> GHC.Prim.State# GHC.Prim.RealWorld
              -> GHC.Prim.State# GHC.Prim.RealWorld

This is why we don't look at the kind. Maybe we should look if the
kinds are compatible.

-- cmpTypeX env (ForAllTy tv1 t1)   (ForAllTy tv2 t2)
--   = cmpTypeX env (tyVarKind tv1) (tyVarKind tv2) `thenCmp`
--     cmpTypeX (rnBndr2 env tv1 tv2) t1 t2

************************************************************************
*                                                                      *
                Type substitutions
*                                                                      *
************************************************************************
-}