Fix #14608 by restoring an unboxed tuple check
authorRyan Scott <ryan.gl.scott@gmail.com>
Tue, 2 Jan 2018 21:03:08 +0000 (16:03 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 4 Jan 2018 19:04:08 +0000 (14:04 -0500)
Commit 714bebff44076061d0a719c4eda2cfd213b7ac3d removed
a check in the bytecode compiler that caught illegal uses of unboxed
tuples (and now sums) in case alternatives, which causes the program
in #14608 to panic. This restores the check (using modern,
levity-polymorphic vocabulary).

Test Plan: make test TEST=T14608

Reviewers: hvr, bgamari, dfeuer, simonpj

Reviewed By: dfeuer, simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14608

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

(cherry picked from commit ecff651fc2f6d9833131e3e7fbc9a37b5b2f84ee)

compiler/ghci/ByteCodeGen.hs
testsuite/tests/ghci/should_fail/T14608.hs [new file with mode: 0644]
testsuite/tests/ghci/should_fail/T14608.script [new file with mode: 0644]
testsuite/tests/ghci/should_fail/T14608.stderr [new file with mode: 0644]
testsuite/tests/ghci/should_fail/all.T

index 697dc63..d537080 100644 (file)
@@ -962,6 +962,11 @@ doCase d s p (_,scrut) bndr alts is_unboxed_tuple
            | null real_bndrs = do
                 rhs_code <- schemeE d_alts s p_alts rhs
                 return (my_discr alt, rhs_code)
+           -- If an alt attempts to match on an unboxed tuple or sum, we must
+           -- bail out, as the bytecode compiler can't handle them.
+           -- (See Trac #14608.)
+           | any (\bndr -> typePrimRep (idType bndr) `lengthExceeds` 1) bndrs
+           = multiValException
            -- algebraic alt with some binders
            | otherwise =
              let (tot_wds, _ptrs_wds, args_offsets) =
diff --git a/testsuite/tests/ghci/should_fail/T14608.hs b/testsuite/tests/ghci/should_fail/T14608.hs
new file mode 100644 (file)
index 0000000..87d5617
--- /dev/null
@@ -0,0 +1,7 @@
+{-# LANGUAGE UnboxedTuples #-}
+module T14608 where
+
+data UnboxedTupleData = MkUTD (# (),() #)
+
+doThings :: UnboxedTupleData -> ()
+doThings (MkUTD t) = ()
diff --git a/testsuite/tests/ghci/should_fail/T14608.script b/testsuite/tests/ghci/should_fail/T14608.script
new file mode 100644 (file)
index 0000000..c37a742
--- /dev/null
@@ -0,0 +1 @@
+:load T14608.hs
diff --git a/testsuite/tests/ghci/should_fail/T14608.stderr b/testsuite/tests/ghci/should_fail/T14608.stderr
new file mode 100644 (file)
index 0000000..fe84063
--- /dev/null
@@ -0,0 +1,3 @@
+Error: bytecode compiler can't handle unboxed tuples and sums.
+  Possibly due to foreign import/export decls in source.
+  Workaround: use -fobject-code, or compile this module to .o separately.
index 58a396e..2851373 100644 (file)
@@ -1,2 +1,3 @@
 test('T10549', [], ghci_script, ['T10549.script'])
 test('T10549a', [], ghci_script, ['T10549a.script'])
+test('T14608', [], ghci_script, ['T14608.script'])