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

Improve local reification and desugaring with respect to standalone kind signatures #227

Merged
merged 5 commits into from
Jul 13, 2024

Conversation

RyanGlScott
Copy link
Collaborator

Previously, th-desugar would not take standalone kind signatures into account when locally reifying a class method (#220). Similarly, it would not take them into account when locally reifying or desugaring a data constructor (#199). This patch accomplishes this, mainly by using the matchUpSAKWithDecl function (during local reification) and the dMatchUpSAKWithDecl function (during desugaring) to match up kind information from the standalone kind signature to the parent declaration's type variable binders.

Fixes #199. Fixes #220.


This PR is split up into a number of commits, as several commits are required in order to migrate matchUpSAKWithDecl/dMatchUpSAKWithDecl (along with the functionality needed to define them) from singletons-th over to th-desugar. As such, this PR also fixes #223.

This migrates various substitution functions from `singletons-th` to
`th-desugar` as part of an effort to eventually implement a fix for #223.
Unlike the existing functions in `Language.Haskell.TH.Subst`, the functions in
`Language.Haskell.TH.Desugar.Subst.Capturing` do _not_ avoid capture when
substituting into `forall` types. This means that these functions can be pure
instead of monadic.
This patch migrates two functions from `singletons-th` over to `th-desugar`,
which will be useful in implementing `matchUpSAKWithDecl` as part of #223.
This patch migrates the following functions from `singletons-th` to
`th-desugar`:

* `matchUpSAKWithDecl`, which makes up the type variable binders from
  a standalone kind signature with the corresponding type variable binders
  from the type-level declaration header.
* The `ForAllTyFlag` data type, a generalization of `Specificity` and `BndrVis`.
  (`matchUpSAKWithDecl` returns `[TyVarBndr ForAllTyFlag]`.)
* `tvbForAllTyFlagsToSpecs` and `tvbForAllTyFlagsToBndrVis` functions, which
  allow converting the results of calling `matchUpSAKWithDecl` to
  `[TyVarBndrSpec]` or `[TyVarBndrVis]`, respectively.

Also add counterparts to the functions above that work over `DTyVarBndr`s
instead of `TyVarBndr`s.

Fixes #223.
…ind signatures

Previously, `th-desugar` would not take standalone kind signatures into account
when locally reifying a class method (#220). Similarly, it would not take them
into account when locally reifying or desugaring a data constructor (#199).
This patch accomplishes this, mainly by using the `matchUpSAKWithDecl` function
(during local reification) and the `dMatchUpSAKWithDecl` function (during
desugaring) to match up kind information from the standalone kind signature to
the parent declaration's type variable binders.

Fixes #199. Fixes #220.
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 12, 2024
As part of a fix for goldfirere/th-desugar#223,
goldfirere/th-desugar#227 adds its own version of
`singletons-th`'s `matchUpSAKWithDecl` function (now called
`dMatchUpSAKWithDecl` on the `th-desugar` side). This commit completes the
migration by removing `singletons-th`'s version of `matchUpSAKWithDecl` and
instead using the version offered by `th-desugar`.
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 12, 2024
As part of a fix for goldfirere/th-desugar#199 and goldfirere/th-desugar#220,
goldfirere/th-desugar#227 improves `th-desugar`'s
ability to locally reify and desugar precise types for Haskell98-style data
constructors and class methods. This has a couple of knock-on effects for
`singletons`:

* The type of `dsCon` has changes to accept `DTyVarBndrSpec`s instead of
  `DTyVarBndrUnit`s, so we must adapt the call sites in `singletons-th`
  accordingly.
* Some of the test cases in `singletons-base` need to have their expected
  output updated to account for the improved kind information and specificity
  information flowing down from standalone kind signatures.
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 12, 2024
As part of a fix for goldfirere/th-desugar#223,
goldfirere/th-desugar#227 adds its own version of
`singletons-th`'s `matchUpSAKWithDecl` function (now called
`dMatchUpSAKWithDecl` on the `th-desugar` side). This commit completes the
migration by removing `singletons-th`'s version of `matchUpSAKWithDecl` and
instead using the version offered by `th-desugar`.
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 12, 2024
As part of a fix for goldfirere/th-desugar#199 and goldfirere/th-desugar#220,
goldfirere/th-desugar#227 improves `th-desugar`'s
ability to locally reify and desugar precise types for Haskell98-style data
constructors and class methods. This has a couple of knock-on effects for
`singletons`:

* The type of `dsCon` has changes to accept `DTyVarBndrSpec`s instead of
  `DTyVarBndrUnit`s, so we must adapt the call sites in `singletons-th`
  accordingly.
* Some of the test cases in `singletons-base` need to have their expected
  output updated to account for the improved kind information and specificity
  information flowing down from standalone kind signatures.
@RyanGlScott RyanGlScott merged commit aeb8931 into master Jul 13, 2024
24 checks passed
@RyanGlScott RyanGlScott deleted the T199-T220-improve-reification-wrt-saks branch July 13, 2024 11:48
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 13, 2024
As part of a fix for goldfirere/th-desugar#223,
goldfirere/th-desugar#227 adds its own version of
`singletons-th`'s `matchUpSAKWithDecl` function (now called
`dMatchUpSAKWithDecl` on the `th-desugar` side). This commit completes the
migration by removing `singletons-th`'s version of `matchUpSAKWithDecl` and
instead using the version offered by `th-desugar`.
RyanGlScott added a commit to goldfirere/singletons that referenced this pull request Jul 13, 2024
As part of a fix for goldfirere/th-desugar#199 and goldfirere/th-desugar#220,
goldfirere/th-desugar#227 improves `th-desugar`'s
ability to locally reify and desugar precise types for Haskell98-style data
constructors and class methods. This has a couple of knock-on effects for
`singletons`:

* The type of `dsCon` has changes to accept `DTyVarBndrSpec`s instead of
  `DTyVarBndrUnit`s, so we must adapt the call sites in `singletons-th`
  accordingly.
* Some of the test cases in `singletons-base` need to have their expected
  output updated to account for the improved kind information and specificity
  information flowing down from standalone kind signatures.
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