Optimise nullary type synonym comparisons and avoid allocating TYPE TyConApps
TysPrim.liftedTypeKind is GHC's representation of the GHC.Type.Type type and consequently works its way into many ASTs. As of GHC 8.10 it has the form TyConApp TYPE ['LiftedPtrRep]. This is unfortunate since we must traverse this type very often during typechecking (e.g. for comparison and unification). This particularly bad in the common case where when we are testing for equality between two liftedTypeKind types.
It would be better if we rather wrote liftedTypeKind in terms of the GHC.Type.Type type synonym: liftedTypeKind = TyConApp typeTyCon []. In this case, comparing two liftedTypeKind types would merely require comparing the keys of the TyCons.
To take advantage of this some changes in our type comparison functions will be needed. Currently our type comparison functions (e.g. GHC.Core.Type.eqType; see list below) expand type synonyms as their first step. However, this leaves some obvious money on the table in the case of nullary type synonyms like Type. It would be much better if we handled the case of nullary TyConApps explicitly to catch the case that they are the same TyCon.
Affected comparison functions:
GHC.Core.Type.cmpTypeTcType.tcEqTypeTcCanonical.can_eq_nc’GHC.Core.Unify.unify_ty