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

unboxedTupleNameDegree_maybe doesn't work with GHC 9.10 #213

Closed
Tracked by #191
RyanGlScott opened this issue May 2, 2024 · 3 comments · Fixed by #215
Closed
Tracked by #191

unboxedTupleNameDegree_maybe doesn't work with GHC 9.10 #213

RyanGlScott opened this issue May 2, 2024 · 3 comments · Fixed by #215
Labels

Comments

@RyanGlScott
Copy link
Collaborator

If you run this program with GHC 9.8 or earlier:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UnboxedTuples #-}
module Main where

import Language.Haskell.TH.Desugar

main :: IO ()
main = print $ unboxedTupleNameDegree_maybe ''(#,#)

You will get this output, as expected:

$ runghc-9.8 Bug.hs
Just 2

With GHC 9.10, however, you will instead get:

$ runghc-9.10 Bug.hs
Nothing

Ultimately, this happens due to the fact that the names of unboxed tuple type constructors have changed in GHC 9.10. In GHC 9.8, we have:

λ> :set -XUnboxedTuples -XTemplateHaskell
λ> ''(#,#)
GHC.Prim.(#,#)

But in GHC 9.10, we have:

λ> :set -XUnboxedTuples -XTemplateHaskell
λ> ''(#,#)
GHC.Types.Tuple2#

The code for parsing unboxed tuple type constructors, however, assumes that only the former name will be used. We need to update this code to account for the possibility of names like Tuple2#.

@RyanGlScott RyanGlScott added the bug label May 2, 2024
@RyanGlScott
Copy link
Collaborator Author

We should also check for things like Sum2# in unboxedSumNameDegree_maybe.

@RyanGlScott RyanGlScott mentioned this issue May 2, 2024
6 tasks
RyanGlScott added a commit that referenced this issue May 2, 2024
This patch changes `unboxedTupleNameDegree_maybe` to handle non-punning tuple
names introduced in GHC 9.10, such as `Unit#`, `Solo#`, `Tuple2#`, `Tuple3#`,
etc. This is because `''(##)` is now syntactic sugar for `''Unit#`, `''(#,#)`
is now syntactic sugar for `Tuple2#`, and so on, so it is important to be able
to recognize both forms.

Similarly, this patch changes `unboxedSumNameDegree_maybe` to handle `Sum2#`,
`Sum3#`, etc.

Fixes #213.
RyanGlScott added a commit that referenced this issue May 2, 2024
This patch changes `unboxedTupleNameDegree_maybe` to handle non-punning tuple
names introduced in GHC 9.10, such as `Unit#`, `Solo#`, `Tuple2#`, `Tuple3#`,
etc. This is because `''(##)` is now syntactic sugar for `''Unit#`, `''(#,#)`
is now syntactic sugar for `Tuple2#`, and so on, so it is important to be able
to recognize both forms.

Similarly, this patch changes `unboxedSumNameDegree_maybe` to handle `Sum2#`,
`Sum3#`, etc.

Fixes #213.
@RyanGlScott
Copy link
Collaborator Author

Sigh... my testing in #215 wasn't thorough enough. While the example in #213 (comment) is now fixed, making a small tweak to it causes it to fail again:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UnboxedTuples #-}
module Main where

import Language.Haskell.TH
import Language.Haskell.TH.Desugar

main :: IO ()
main = print $ unboxedTupleNameDegree_maybe $ unboxedTupleTypeName 2
$ runghc-9.8 Bug.hs
Just 2
$ runghc-9.10 Bug.hs
Nothing

This one is really weird, as it turns out that unboxedTupleTypeName 2 returns a completely different Name than ''(#,#) does:

λ> unboxedTupleTypeName 2
GHC.Prim.Tuple2#
λ> ''(#,#)
GHC.Types.Tuple2#

See GHC#24750. This is unfortunate from a th-desugar perspective because we desugar uses of UnboxedTupleT <N> to ConT (unboxedTupleTypeName <N>), so it is particularly important to get the unboxedTupleTypeName case correct.

My hope is that we can fix GHC#24750 upstream so that this example Just Works™. If not, we'll need to add a special case for the (non-existent) GHC.Prim.Tuple<N># family of Names.

@RyanGlScott RyanGlScott reopened this May 2, 2024
RyanGlScott added a commit that referenced this issue May 12, 2024
Among other things, this checks for the program that failed in
#213 (comment).
@RyanGlScott
Copy link
Collaborator Author

The fix for GHC#24750 is present in GHC 9.10.1, which means that the program in #213 (comment) now works as expected. I've added that program (among others) as regression tests in 8179363.

RyanGlScott added a commit that referenced this issue May 12, 2024
This reverts commit 8179363.

`haskell-ci` only includes pre-release versions of GHC 9.10, which do not have
the necessary fixes needed to make these test cases pass on GHC 9.10.
RyanGlScott added a commit that referenced this issue May 12, 2024
Among other things, this checks for the program that failed in
#213 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant