Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially revert #596, give PAlternative (and friends) the correct kinds #606

Merged
merged 3 commits into from
Jun 18, 2024

Conversation

RyanGlScott
Copy link
Collaborator

This PR consists of patches that:

Refer to the individual commit messages for further details.

The changes in #596 cause `singletons-th` to use `TypeAbstractions` to
explicitly quantify the kind variables of promoted class methods whenever the
parent class has a standalone kind signature, thereby ensuring that the order
of kind variables matches the order in which the user wrote them. At least,
that was the intention. Unfortunately, as #605 reveals, this approach sometimes
causes `singletons-th` to generate ill-kinded code for promoted class methods,
and there isn't an obvious way to work around this limitation.

As such, this patch reverts the `TypeAbstractions`-related changes from #596.
Once again, `singletons-th` now does not make any guarantees about the order of
kind variables for promoted class methods or their defunctionalization symbols.

On the other hand, this patch _does_ keep the changes from #596 that cause
`singletons-th` to propagate kind information from the parent class's
standalone kind signature through to the promoted class methods'
defunctionalization symbols, as this feature is useful independent of the
`TypeAbstractions`-related changes. I have taken the opportunity to document
why we do this in the new `Note [Propagating kind information from class
standalone kind signatures]` in `D.S.TH.Promote`.

I've removed the `T589` test case, as the functionality it was testing no
longer exists after reverting the `TypeAbstractions`-related changes. I have
also added a new `T605` test case that ensures that the regression from #605
stays fixed. In a subsequent commit, I will add another test case that
demonstrates that the kind propagation works as intended.

Fixes #605.
In particular, make note of the circumstances under which issues like #604.
There is no way for `singletons-th` to generate code that avoids the problems
in #604 in all cases, so we instead advise users to be wary when promoting code
involving classes that are parameterized over higher-kinded type variables
(e.g., `Alternative`).
Previously, `singletons-th` would generalize the kinds of `PAlternative` and
related classes (e.g., `PMonadPlus`), as well of the kinds of the
defunctionalization symbols for various classes that are parameterized over a
higher-kinded type variable. As described in the "Class constraints" section of
the `README.md`, the recommended workaround for this issue is to give the
classes in question explicit kinds, so this patch does just that by giving
`Alternative`, `MonadPlus`, etc. standalone kind signatures.

This causes the code in `singletons-base` to deviate a bit from the original
code in the `base` library. I have written a new `Note [Using standalone kind
signatures not present in the base library]` and cited it in all of the places
where such a deviation occurs.

Fixes #604.
@RyanGlScott RyanGlScott merged commit 5f0d420 into master Jun 18, 2024
24 checks passed
@RyanGlScott RyanGlScott deleted the T605-partial-TypeAbstractions-revert branch June 18, 2024 10:38
RyanGlScott added a commit that referenced this pull request Jun 30, 2024
This adds more explicit `Type -> Type` kind signatures to definitions that
would otherwise be kind-generalized to have overly polymorphic kinds:

* The kinds of `Asum` and `Msum` (the promoted counterparts to the term-level
  `asum` and `msum` functions, respectively).
* The helper type families generated when promoting the `Alternative` and
  `MonadPlus` instances for `Data.Functor.Product`. This sort of kind
  polymorphism isn't observable by users in today's GHC, but it will cause
  problems later in a future version of GHC that implements
  [GHC#23515](https://gitlab.haskell.org/ghc/ghc/-/issues/23515). (See #601.)

(I should have added these as part of #606 or #607, but I forgot them due to an
oversight.)
RyanGlScott added a commit that referenced this pull request Jul 1, 2024
This adds more explicit `Type -> Type` kind signatures to definitions that
would otherwise be kind-generalized to have overly polymorphic kinds:

* The kinds of `Asum` and `Msum` (the promoted counterparts to the term-level
  `asum` and `msum` functions, respectively).
* The helper type families generated when promoting the `Alternative` and
  `MonadPlus` instances for `Data.Functor.Product`. This sort of kind
  polymorphism isn't observable by users in today's GHC, but it will cause
  problems later in a future version of GHC that implements
  [GHC#23515](https://gitlab.haskell.org/ghc/ghc/-/issues/23515). (See #601.)

(I should have added these as part of #606 or #607, but I forgot them due to an
oversight.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant