diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-01-02 16:03:08 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-01-02 17:33:04 -0500 |
commit | ecff651fc2f6d9833131e3e7fbc9a37b5b2f84ee (patch) | |
tree | 64e0723c19b638e6389b598a802321acd87e738c | |
parent | 46287af0911f7cb446c62850630f85af567ac512 (diff) | |
download | haskell-ecff651fc2f6d9833131e3e7fbc9a37b5b2f84ee.tar.gz |
Fix #14608 by restoring an unboxed tuple check
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
-rw-r--r-- | compiler/ghci/ByteCodeGen.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_fail/T14608.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_fail/T14608.script | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_fail/T14608.stderr | 3 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_fail/all.T | 1 |
5 files changed, 17 insertions, 0 deletions
diff --git a/compiler/ghci/ByteCodeGen.hs b/compiler/ghci/ByteCodeGen.hs index 697dc63b43..d5370805ea 100644 --- a/compiler/ghci/ByteCodeGen.hs +++ b/compiler/ghci/ByteCodeGen.hs @@ -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 index 0000000000..87d5617e5c --- /dev/null +++ b/testsuite/tests/ghci/should_fail/T14608.hs @@ -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 index 0000000000..c37a742461 --- /dev/null +++ b/testsuite/tests/ghci/should_fail/T14608.script @@ -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 index 0000000000..fe84063af2 --- /dev/null +++ b/testsuite/tests/ghci/should_fail/T14608.stderr @@ -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. diff --git a/testsuite/tests/ghci/should_fail/all.T b/testsuite/tests/ghci/should_fail/all.T index 58a396ed86..285137387d 100644 --- a/testsuite/tests/ghci/should_fail/all.T +++ b/testsuite/tests/ghci/should_fail/all.T @@ -1,2 +1,3 @@ test('T10549', [], ghci_script, ['T10549.script']) test('T10549a', [], ghci_script, ['T10549a.script']) +test('T14608', [], ghci_script, ['T14608.script']) |