Pass separation for TyClDecl LHS and RHS
While implementing top-level kind signatures, I faced an issue related to scoped kind variables. Here's an example:
type T :: forall k. k -> Type
data T a = MkT (Proxy (a :: k))
When -XScopedTypeVariables are on, we want k in Proxy (a :: k) to refer to forall k. in the TLKS.
Now, do we rename the signature or the data declaration first?
- if we rename the declaration first, then
kon its RHS won't be able to refer tokin the signature (kis not in scope) - if we rename the signature first, then it will not be able to refer to the declaration LHS (
Tis not in scope)
We have the exact same issue in terms, where it is solved by doing renaming in three steps:
- rename the LHSs (
rnValBindsLHS) - rename the signatures (
renameSigs) - rename the RHSs (
rnValBindsRHS)
In order to accommodate this design, HsValBinds and HsBind are parametrized by two separate passes:
data HsValBindsLR idL idR = ...
data HsBindLR idL idR = ...
On the other hand, renaming type/class declarations is done in one pass (rnTyClDecls), so TyClDecl is parametrized only by one pass:
data TyClDecl pass = ...
We should change this to:
data TyClDecl idL idR = ...
This is likely to be a fairly invasive change, so I'd rather do it independently from the TLKS implementation.