This fix is described in Note [Removing variables with bound kinds]
in TcType. This commit also changes split_dvs to close over kinds
at the end, which seems more performant than walking over the kind
of every tyvar occurrence.
Along the way, I also updated the free-variable functions in
TyCoRep to close over kinds after gathering free variables,
as the old story was wrong, as detailed in Note [Free variables
of types]. This caused performance trouble, and so I noticed
that most uses of free-variable finding actually do not care
at all about determinacy... yet were carefully tracking order.
So I wrote tyCoVarsOfType to build a VarSet directly, without
Sadly, there is *still* performance trouble, yet to be sorted
Also while working on this, I noticed that GHC wasn't doing its
best job at keeping left-to-right ordering of type variables in
cases where it doesn't really matter, but still would be nice.
I've made some improvements in this area.
An unrelated change is also in MkId, where the type-variable
reordering logic for data constructors was wrong for newtype
instances in GADT syntax. Fixed now.