Commit 9550b8d8 authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari

Make unboxedTuple{Type,Data}Name support 0- and 1-tuples

Previously, these functions were hardcoded so as to always `error`
whenever given an argument of 0 or 1. This restriction can be lifted
pretty easily, however.

This requires a slight tweak to `isBuiltInOcc_maybe` in `TysWiredIn` to
allow it to recognize `Unit#` (which is the hard-wired `OccName` for
unboxed 1-tuples).

Fixes #12977.

Test Plan: make test TEST=12977

Reviewers: austin, goldfire, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2847

GHC Trac Issues: #12977
parent fe5d68ad
......@@ -691,6 +691,7 @@ isBuiltInOcc_maybe occ =
-- unboxed tuple data/tycon
"(##)" -> Just $ tup_name Unboxed 0
"Unit#" -> Just $ tup_name Unboxed 1
_ | Just rest <- "(#" `stripPrefix` name
, (commas, rest') <- BS.span (==',') rest
, "#)" <- rest'
......
......@@ -1187,20 +1187,17 @@ unboxedTupleDataName :: Int -> Name
-- | Unboxed tuple type constructor
unboxedTupleTypeName :: Int -> Name
unboxedTupleDataName 0 = error "unboxedTupleDataName 0"
unboxedTupleDataName 1 = error "unboxedTupleDataName 1"
unboxedTupleDataName n = mk_unboxed_tup_name (n-1) DataName
unboxedTupleTypeName 0 = error "unboxedTupleTypeName 0"
unboxedTupleTypeName 1 = error "unboxedTupleTypeName 1"
unboxedTupleTypeName n = mk_unboxed_tup_name (n-1) TcClsName
unboxedTupleDataName n = mk_unboxed_tup_name n DataName
unboxedTupleTypeName n = mk_unboxed_tup_name n TcClsName
mk_unboxed_tup_name :: Int -> NameSpace -> Name
mk_unboxed_tup_name n_commas space
= Name occ (NameG space (mkPkgName "ghc-prim") tup_mod)
mk_unboxed_tup_name n space
= Name (mkOccName tup_occ) (NameG space (mkPkgName "ghc-prim") tup_mod)
where
occ = mkOccName ("(#" ++ replicate n_commas ',' ++ "#)")
tup_mod = mkModName "GHC.Tuple"
tup_occ | n == 1 = "Unit#" -- See Note [One-tuples] in TysWiredIn
| otherwise = "(#" ++ replicate n_commas ',' ++ "#)"
n_commas = n - 1
tup_mod = mkModName "GHC.Tuple"
-----------------------------------------------------
-- Locations
......
......@@ -16,6 +16,9 @@
* Add support for attaching deriving strategies to `deriving` statements
(#10598)
* `unboxedTupleTypeName` and `unboxedTupleDataName` now work for unboxed
0-tuples and 1-tuples (#12977)
## 2.11.0.0 *May 2016*
* Bundled with GHC 8.0.1
......
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UnboxedTuples #-}
module T12977 where
import Language.Haskell.TH.Lib
import Language.Haskell.TH.Syntax
zero :: () -> $(conT (unboxedTupleTypeName 0))
zero () = $(conE (unboxedTupleDataName 0))
one :: () -> $(conT (unboxedTupleTypeName 1) `appT` conT ''Int)
one () = $(conE (unboxedTupleDataName 1)) 42
......@@ -444,3 +444,4 @@ test('T12646', normal, compile, ['-v0'])
test('T12788', extra_clean(['T12788_Lib.hi', 'T12788_Lib.o']),
multimod_compile_fail,
['T12788.hs', '-v0 ' + config.ghc_th_way_flags])
test('T12977', normal, compile, ['-v0'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment