Commit 8de6e13f authored by seraphime's avatar seraphime Committed by Ben Gamari
Browse files

Fix bytecode generator panic

This fixes #12128.

The bug was introduced in 1c9fd3f1.

Test Plan: ./validate

Reviewers: simonmar, austin, hvr, simonpj, bgamari

Reviewed By: bgamari

Subscribers: simonpj, thomie

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

GHC Trac Issues: #12128
parent 908f8e23
......@@ -1327,6 +1327,12 @@ pushAtom d p e
pushAtom _ _ (AnnCoercion {}) -- Coercions are zero-width things,
= return (nilOL, 0) -- treated just like a variable V
-- See Note [Empty case alternatives] in coreSyn/CoreSyn.hs
-- and Note [Bottoming expressions] in coreSyn/CoreUtils.hs:
-- The scrutinee of an empty case evaluates to bottom
pushAtom d p (AnnCase (_, a) _ _ []) -- trac #12128
= pushAtom d p a
pushAtom d p (AnnVar v)
| UnaryRep rep_ty <- repType (idType v)
, V <- typeArgRep rep_ty
......@@ -1627,6 +1633,11 @@ atomPrimRep :: AnnExpr' Id ann -> PrimRep
atomPrimRep e | Just e' <- bcView e = atomPrimRep e'
atomPrimRep (AnnVar v) = bcIdPrimRep v
atomPrimRep (AnnLit l) = typePrimRep (literalType l)
-- Trac #12128:
-- A case expresssion can be an atom because empty cases evaluate to bottom.
-- See Note [Empty case alternatives] in coreSyn/CoreSyn.hs
atomPrimRep (AnnCase _ _ ty _) = ASSERT(typePrimRep ty == PtrRep) PtrRep
atomPrimRep (AnnCoercion {}) = VoidRep
atomPrimRep other = pprPanic "atomPrimRep" (ppr (deAnnotate' other))
......
{-
This code produces an empty case statement, which
panics the bytecode generator after trac #11155.
-}
module ShouldCompile where
import GHC.TypeLits (Symbol)
import Unsafe.Coerce
instance Read Symbol where
readsPrec = unsafeCoerce (readsPrec :: Int -> ReadS String)
data Bar = TyCon !Symbol deriving (Read)
......@@ -24,3 +24,4 @@ test('T10145', just_ghci, ghci_script, ['T10145.script'])
test('T7253', just_ghci, ghci_script, ['T7253.script'])
test('T11328', just_ghci, ghci_script, ['T11328.script'])
test('T11825', just_ghci, ghci_script, ['T11825.script'])
test('T12128', just_ghci, ghci_script, ['T12128.script'])
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