This repository was archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
More synify-ing improvements #931
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b6a12c0
Better rendering of unboxed sums/tuples
harpocrates 7d455c7
Handle promoted tuples in 'synifyType'
harpocrates 7ace2a6
Accept test cases
harpocrates b4526dc
Properly synify promoted list types
harpocrates 307f33a
Only look at visible types when synifying a 'HsListTy'
harpocrates ffcf6c2
Various improvements to synifying Types
harpocrates 421fc78
Deduce proper order for type variables
harpocrates 1c8d152
Infer kinds in pattern syns based on kind of TyCon
harpocrates 05974a3
Synify associated type defaults
harpocrates 0aaeba6
Extend variables in scope when synifying
harpocrates 25d3db5
Add example of 'tyCoVarsOfTypeList's behaviour
harpocrates 3dcf333
Move 'forall's left on pattern synonym sigs
harpocrates dece147
Fix return kind of polykinded H98 types
harpocrates File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
><head | ||
><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" | ||
/><title | ||
>UnboxedStuff</title | ||
><link href="#" rel="stylesheet" type="text/css" title="Ocean" | ||
/><link rel="stylesheet" type="text/css" href="#" | ||
/><script src="haddock-bundle.min.js" async="async" type="text/javascript" | ||
></script | ||
><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript" | ||
></script | ||
></head | ||
><body | ||
><div id="package-header" | ||
><ul class="links" id="page-menu" | ||
><li | ||
><a href="#" | ||
>Contents</a | ||
></li | ||
><li | ||
><a href="#" | ||
>Index</a | ||
></li | ||
></ul | ||
><p class="caption empty" | ||
></p | ||
></div | ||
><div id="content" | ||
><div id="module-header" | ||
><table class="info" | ||
><tr | ||
><th | ||
>Safe Haskell</th | ||
><td | ||
>Safe</td | ||
></tr | ||
></table | ||
><p class="caption" | ||
>UnboxedStuff</p | ||
></div | ||
><div id="table-of-contents" | ||
><p class="caption" | ||
>Contents</p | ||
><ul | ||
><li | ||
><a href="#" | ||
>Unboxed type constructors</a | ||
></li | ||
></ul | ||
></div | ||
><div id="synopsis" | ||
><details id="syn" | ||
><summary | ||
>Synopsis</summary | ||
><ul class="details-toggle" data-details-id="syn" | ||
><li class="src short" | ||
><span class="keyword" | ||
>data</span | ||
> <a href="#" | ||
>X</a | ||
></li | ||
><li class="src short" | ||
><span class="keyword" | ||
>data</span | ||
> <a href="#" | ||
>Y</a | ||
></li | ||
><li class="src short" | ||
><span class="keyword" | ||
>data</span | ||
> <a href="#" | ||
>Z</a | ||
></li | ||
><li class="src short" | ||
><a href="#" | ||
>unboxedUnit</a | ||
> :: (# #) -> (# #)</li | ||
><li class="src short" | ||
><a href="#" | ||
>unboxedTuple</a | ||
> :: (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> #) -> (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Z</a | ||
> #)</li | ||
><li class="src short" | ||
><a href="#" | ||
>unboxedSum</a | ||
> :: (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> #) -> (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Z</a | ||
> #)</li | ||
></ul | ||
></details | ||
></div | ||
><div id="interface" | ||
><h1 | ||
>Documentation</h1 | ||
><div class="top" | ||
><p class="src" | ||
><span class="keyword" | ||
>data</span | ||
> <a id="t:X" class="def" | ||
>X</a | ||
> <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
><div class="top" | ||
><p class="src" | ||
><span class="keyword" | ||
>data</span | ||
> <a id="t:Y" class="def" | ||
>Y</a | ||
> <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
><div class="top" | ||
><p class="src" | ||
><span class="keyword" | ||
>data</span | ||
> <a id="t:Z" class="def" | ||
>Z</a | ||
> <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
><a href="#" id="g:1" | ||
><h1 | ||
>Unboxed type constructors</h1 | ||
></a | ||
><div class="top" | ||
><p class="src" | ||
><a id="v:unboxedUnit" class="def" | ||
>unboxedUnit</a | ||
> :: (# #) -> (# #) <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
><div class="top" | ||
><p class="src" | ||
><a id="v:unboxedTuple" class="def" | ||
>unboxedTuple</a | ||
> :: (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> #) -> (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
>, <a href="#" title="UnboxedStuff" | ||
>Z</a | ||
> #) <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
><div class="top" | ||
><p class="src" | ||
><a id="v:unboxedSum" class="def" | ||
>unboxedSum</a | ||
> :: (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> #) -> (# <a href="#" title="UnboxedStuff" | ||
>X</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Y</a | ||
> | <a href="#" title="UnboxedStuff" | ||
>Z</a | ||
> #) <a href="#" class="selflink" | ||
>#</a | ||
></p | ||
></div | ||
></div | ||
></div | ||
><div id="footer" | ||
></div | ||
></body | ||
></html | ||
> |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{-# LANGUAGE UnboxedSums, UnboxedTuples #-} | ||
module UnboxedStuff where | ||
|
||
data X | ||
data Y | ||
data Z | ||
|
||
-- * Unboxed type constructors | ||
|
||
unboxedUnit :: (# #) -> (# #) | ||
unboxedUnit = undefined | ||
|
||
unboxedTuple :: (# X, Y #) -> (# X, Y, Z #) | ||
unboxedTuple = undefined | ||
|
||
unboxedSum :: (# X | Y #) -> (# X | Y | Z #) | ||
unboxedSum = undefined | ||
|
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
\haddockmoduleheading{UnboxedStuff} | ||
\label{module:UnboxedStuff} | ||
\haddockbeginheader | ||
{\haddockverb\begin{verbatim} | ||
module UnboxedStuff ( | ||
X, Y, Z, unboxedUnit, unboxedTuple, unboxedSum | ||
) where\end{verbatim}} | ||
\haddockendheader | ||
|
||
\begin{haddockdesc} | ||
\item[\begin{tabular}{@{}l} | ||
data\ X | ||
\end{tabular}] | ||
\end{haddockdesc} | ||
\begin{haddockdesc} | ||
\item[\begin{tabular}{@{}l} | ||
data\ Y | ||
\end{tabular}] | ||
\end{haddockdesc} | ||
\begin{haddockdesc} | ||
\item[\begin{tabular}{@{}l} | ||
data\ Z | ||
\end{tabular}] | ||
\end{haddockdesc} | ||
\section{Unboxed type constructors} | ||
\begin{haddockdesc} | ||
\item[ | ||
unboxedUnit\ ::\ ({\char '43}\ {\char '43})\ ->\ ({\char '43}\ {\char '43}) | ||
] | ||
\item[ | ||
unboxedTuple\ ::\ ({\char '43}\ X,\ Y\ {\char '43})\ ->\ ({\char '43}\ X,\ Y,\ Z\ {\char '43}) | ||
] | ||
\item[ | ||
unboxedSum\ ::\ ({\char '43}\ X\ |\ Y\ {\char '43})\ ->\ ({\char '43}\ X\ |\ Y\ |\ Z\ {\char '43}) | ||
] | ||
\end{haddockdesc} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must be missing some context here. Why would we ever want to retrieve free type variables in reverse order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want them in order. Unfortunately, that's not what GHC does.
unionFV
starts by running the secondFV
on the accumulator, then passing that to the firstFV
. That means it adds variables from the second argument to thein_scope
set before adding variables from the first argument. All this is bad news if the first and second arguments share some variables.Here is a snippet demonstrating the somewhat surprising behaviour:
My hack here is to traverse everything in reverse order, then reverse the list of type variables at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh dear, that's absolutely terrible. I really thought that
tyCoVarsOfTypesWellScoped
would be enough to accomplish this task, but your counterexample shows that I was mistaken.Still, I'm incredibly bothered by the fact that we have to duplicate so much machinery just to solve this problem. I've sent an email to the ghc-devs list asking about this, so I'm hoping I can get some clarification on this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on Simon's response here, it looks like the
FV
-returning functions really don't guarantee any particular order (only that it's deterministic), which is a huge bummer.Ideally, we'd rewrite
tyCoFVsOfType
and friends in such a way that they always return things in left-to-right order. Your hacked version accomplishes this, but at the cost of reversing the order at the very end, which feels wasteful. Is there a way to accomplish the same thing with only one pass?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In GHC: yes. We'd need to change
unitFV
to append to the var list. In order to keep that operation efficient, that means swapping occurrences of[Var]
inFV
for difference lists ofVar
. It looks like theFV
code has already been carefully performance tuned, so we'd have to be very careful there.In Haddock: not really, short of porting over most of
FV
(and then making the changes we'd otherwise make in GHC).What frustrates me the most is not the
reverse
: it's having to rely on what is accidental behaviour in GHC.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, this is all so nasty.
Ultimately, I think the
orderedFVs
hack is probably the way to go for now. I'd only request that you expand the documentation for it to include an example of whytyCoVarsOfTypeWellScoped
doesn't give the behavior you desire (e.g., your example in #931 (comment)).Ideally, we'd investigate making the
FV
functions in GHC return things in a reliable left-to-right order. But as you've noted, they're quite performance intensive, so I can understand your reservations about making things slower by changing the underlying data structures involved.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an example illustrating GHC's behaviour (I didn't know about
alphaTyVar
andbetaTyVar
- thanks!).I agree we should eventually look into making
FV
return things in a reliable left-to-right order. I'm a bit swamped at the moment, but I'll try to circle back when all of this Hi Haddock stuff settles down.