Fix Template Haskell reification of unboxed tuple types
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 18 Jul 2016 13:29:05 +0000 (09:29 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Mon, 18 Jul 2016 13:31:20 +0000 (09:31 -0400)
Summary:
Previously, Template Haskell reified unboxed tuple types as boxed
tuples with twice the appropriate arity.

Fixes #12403.

Test Plan: make test TEST=T12403

Reviewers: hvr, goldfire, austin, bgamari

Reviewed By: goldfire

Subscribers: thomie

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

GHC Trac Issues: #12403

compiler/typecheck/TcSplice.hs
docs/users_guide/8.0.2-notes.rst
testsuite/tests/th/T12403.hs [new file with mode: 0644]
testsuite/tests/th/T12403.stdout [new file with mode: 0644]
testsuite/tests/th/all.T

index fa68d2e..6ae1ba4 100644 (file)
@@ -1819,7 +1819,9 @@ reify_tc_app tc tys
     tc_binders  = tyConBinders tc
     tc_res_kind = tyConResKind tc
 
-    r_tc | isTupleTyCon tc                = if isPromotedDataCon tc
+    r_tc | isUnboxedTupleTyCon tc         = TH.UnboxedTupleT (arity `div` 2)
+             -- See Note [Unboxed tuple RuntimeRep vars] in TyCon
+         | isTupleTyCon tc                = if isPromotedDataCon tc
                                             then TH.PromotedTupleT arity
                                             else TH.TupleT arity
          | tc `hasKey` listTyConKey       = TH.ListT
index d5d442f..39ad028 100644 (file)
@@ -32,6 +32,12 @@ Compiler
    initial cmm from STG-to-C-- code generation and :ghc-flag:`-ddump-cmm-verbose`
    to obtain the intermediates from all C-- pipeline stages.
 
+Template Haskell
+~~~~~~~~~~~~~~~~
+
+-  Reifying types that contain unboxed tuples now works correctly. (Previously,
+   Template Haskell reified unboxed tuples as boxed tuples with twice their
+   appropriate arity.)
 
 TODO FIXME Heading title
 ~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/testsuite/tests/th/T12403.hs b/testsuite/tests/th/T12403.hs
new file mode 100644 (file)
index 0000000..d4aad62
--- /dev/null
@@ -0,0 +1,12 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE UnboxedTuples #-}
+module Main where
+
+import Language.Haskell.TH
+
+data T = T (# Int, Int #)
+
+$(return [])
+
+main :: IO ()
+main = putStrLn $(reify ''T >>= stringE . pprint)
diff --git a/testsuite/tests/th/T12403.stdout b/testsuite/tests/th/T12403.stdout
new file mode 100644 (file)
index 0000000..9b75e8b
--- /dev/null
@@ -0,0 +1 @@
+data Main.T = Main.T ((# , #) GHC.Types.Int GHC.Types.Int)
index ff2d6d4..3f448d7 100644 (file)
@@ -418,3 +418,5 @@ test('T11484', normal, compile, ['-v0'])
 test('T8761', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T12130', extra_clean(['T12130a.hi','T12130a.o']),
               multimod_compile, ['T12130', '-v0 ' + config.ghc_th_way_flags])
+test('T12403', omit_ways(['ghci']),
+              compile_and_run, ['-v0 -ddump-splices -dsuppress-uniques'])