Closed RyanGlScott closed 1 year ago
After looking at the code which generates standalone kind signatures for things like SD
, it's clearer why this bug arises:
Here, sing_data_sak
is the final standalone kind signature (e.g., for SD
), data_sak
is the standalone kind signature for the original data type (e.g., for D
), and tvbs
are the type variable binders for the data type (e.g., the x p
in data D x p
). There are two things that are suspicious about this code:
data_sak
(invis_args
) from the visible arguments (vis_args
), and then prepends all of the invisible arguments before all of the visible arguments. This is very questionable, considering that a visible argument can precede an invisible argument due to nested forall
s. (In this example, I don't think this ends up mattering, but it is fishy nonetheless.)This code uses replaceTvbKind
, which is defined like so:
The DVisFADep
case is very suspect. In effect, this will discard a type variable binder in tvbs
in favor of a visible dependent forall
from data_sak
. In the example above, that means discarding a
in favor of x
, which is the root of the issue above.
To do this properly, I think we will need to get rid of replaceTvbKind
(which is quite broken w.r.t. visible dependent forall
s) and instead implement something akin to the zipSAKS
algorithm from this GHC proposal, which solves a similar problem.
GHC's implementation of zipSAKS
is called matchUpSigWithDecl
, which is very relevant here. An interesting thing about matchUpSigWithDecl
: if you look up the D
example above with :info
in GHCi, you'll get:
λ> :info D
type D :: forall k. forall (x :: k) -> Proxy x -> Type
data D x p = MkD
Note that the binders in data D x p
have remained unchanged, but the a
variable in the standalone kind signature has been renamed to x
. I think we will want to do a similar renaming in singletons-th
.
The following program:
Will cause
singletons-th
to emit an out-of-scopeName
error, which shouldn't happen under normal circumstances:Specifically, the culprit is in the standalone kind signature for
SD
, which mentionsx
inD x p
without binding it: