-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make TH generate standalone kind signatures
This patch addresses chunk (2) in #378 (comment) by making the TH machinery generate standalone kind signatures wherever possible, inching closer to the goal of preserving the order of `forall`'s type variables in all promoted and singled code. I say "inching" since this post does not quite get there (see the "Caveats" section at the bottom of this commit message), but it comes very close. In brief, the TH machinery now generates SAKS for the following: * Promoted top-level functions See `D.S.Promote.promoteLetDecRHS` for how this is implemented. * Defunctionalization symbols SAKS provide a wonderful opportunity to clean up the implementation in `D.S.Promote.Defun`, which is currently somewhat crufty. The code used to jump through hoops in order to give defunctionalization symbols CUSKs, but now that we live in a post-CUSKs world, we can get rid of all the ad hoc-ness in `Note [Defunctionalization and dependent quantification]`. Instead, we now use a much simpler algorithm that only depends on whether the thing being defunctionalized has a SAK or not. See `Note [Defunctionalization game plan]` in `D.S.Promote.Defun`. * Singled data type declarations If a data type's order of kind variables is known (e.g., if it was declared with a SAK), then the singled version of the data type will use a SAK to preserve the same kind variable order. See the code in `D.S.Single.Data.singDataD`. * Promoted and singled class declarations Similarly, if the order of kind variables is known for a class `C`, then the TH machinery will generate SAKS for `PC` and `SC` to preserve the same kind variable order. See the code in `D.S.Promote.promoteClassDec` and `D.S.Single.singClassD`. Naturally, lots of test cases' expected outputs change as a result of this patch. See `Singletons.T378{a,b}` for some new (or altered) cases that test new code paths. ------------- -- Caveats -- ------------- Alas, not everything preserves the order of type variables after this patch. Some notable exceptions are: * `let`- or `where`-bound functions When promoting this function: ```hs f :: Bool f = let x = True g :: () -> Bool g _ = x in g () ``` The TH machinery will give the promoted `F` type family a SAK, but not the `G` type family. See `Note [No SAKs for let-decs with local variables]` in `D.S.Promote` for an explanation. * Promoted class methods This class: ```hs class C (b :: Type) where m :: forall a. a -> b -> a ``` Is promoted like so: ```hs class PC (b :: Type) where type M (x :: a) (y :: b) :: a ``` The order of the variables `a` and `b` are different between the type of `m` and the kind of `M`. See `Note [Promoted class methods and kind variable ordering]` in `D.S.Promote`. * Fully saturated defunctionalization symbols If you defunctionalize the `Id` type family, you'll generate two defunctionalization symbols: ```hs type IdSym0 :: forall a. a ~> a data IdSym0 f where ... type IdSym1 (x :: a) = Id x :: a ``` Notice that unlike `IdSym0`, `IdSym1` (the "fully saturated" defunctionalization symbol) does _not_ have a SAK. This is because in general, giving fully saturated defunctionalization symbols SAKS can lead to kind errors. See `Note [No SAKs for fully saturated defunctionalization symbols]` in `D.S.Promote.Defun` for the sordid story.
- Loading branch information
1 parent
aa00fea
commit 64c15cb
Showing
147 changed files
with
6,433 additions
and
6,573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.