diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2019-10-24 13:52:36 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-11-07 08:39:36 -0500 |
commit | 708c60aa144ed68a5b67a61f16539258dbcdb24e (patch) | |
tree | 1c73dfe7395871f7986eb12701d19b46825f3f39 /compiler/GHC/ThToHs.hs | |
parent | b4fb232892ec420059e767bbf464bd09361aaefa (diff) | |
download | haskell-708c60aa144ed68a5b67a61f16539258dbcdb24e.tar.gz |
Clean up TH's treatment of unary tuples (or, #16881 part two)
!1906 left some loose ends in regards to Template Haskell's treatment
of unary tuples. This patch ends to tie up those loose ends:
* In addition to having `TupleT 1` produce unary tuples, `TupE [exp]`
and `TupP [pat]` also now produce unary tuples.
* I have added various special cases in GHC's pretty-printers to
ensure that explicit 1-tuples are printed using the `Unit` type.
See `testsuite/tests/th/T17380`.
* The GHC 8.10.1 release notes entry has been tidied up a little.
Fixes #16881. Fixes #17371. Fixes #17380.
Diffstat (limited to 'compiler/GHC/ThToHs.hs')
-rw-r--r-- | compiler/GHC/ThToHs.hs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs index 7df5aee397..7d913ff4bf 100644 --- a/compiler/GHC/ThToHs.hs +++ b/compiler/GHC/ThToHs.hs @@ -908,9 +908,6 @@ cvtl e = wrapL (cvt e) ; return $ HsLamCase noExtField (mkMatchGroup FromSource ms') } - cvt (TupE [Just e]) = do { e' <- cvtl e; return $ HsPar noExtField e' } - -- Note [Dropping constructors] - -- Singleton tuples treated like nothing (just parens) cvt (TupE es) = cvt_tup es Boxed cvt (UnboxedTupE es) = cvt_tup es Unboxed cvt (UnboxedSumE e alt arity) = do { e' <- cvtl e @@ -1018,14 +1015,13 @@ ensureValidOpExp _e _m = {- Note [Dropping constructors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When we drop constructors from the input (for instance, when we encounter @TupE [e]@) -we must insert parentheses around the argument. Otherwise, @UInfix@ constructors in @e@ -could meet @UInfix@ constructors containing the @TupE [e]@. For example: +When we drop constructors from the input, we must insert parentheses around the +argument. For example: - UInfixE x * (TupE [UInfixE y + z]) + UInfixE x * (AppE (InfixE (Just y) + Nothing) z) -If we drop the singleton tuple but don't insert parentheses, the @UInfixE@s would meet -and the above expression would be reassociated to +If we convert the InfixE expression to an operator section but don't insert +parentheses, the above expression would be reassociated to OpApp (OpApp x * y) + z @@ -1254,8 +1250,6 @@ cvtp (TH.LitP l) | otherwise = do { l' <- cvtLit l; return $ Hs.LitPat noExtField l' } cvtp (TH.VarP s) = do { s' <- vName s ; return $ Hs.VarPat noExtField (noLoc s') } -cvtp (TupP [p]) = do { p' <- cvtPat p; return $ ParPat noExtField p' } - -- Note [Dropping constructors] cvtp (TupP ps) = do { ps' <- cvtPats ps ; return $ TuplePat noExtField ps' Boxed } cvtp (UnboxedTupP ps) = do { ps' <- cvtPats ps |