#15067 closed bug (fixed)

When Typeable and unboxed sums collide, GHC panics

Reported by: RyanGlScott Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler (Type checker) Version: 8.4.1
Keywords: Typeable, UnboxedSums Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash or panic Test Case: typecheck/should_fail/T15067
Blocked By: Blocking:
Related Tickets: #13276 Differential Rev(s): Phab:D4622, Phab:D4623
Wiki Page:

Description

This program is enough to send GHC into a tizzy:

{-# LANGUAGE UnboxedSums #-}
module Bug1 where

import Type.Reflection

floopadoop :: TypeRep (# Bool | Int #)
floopadoop = typeRep
$ ghc Bug.hs
[1 of 1] Compiling Bug1             ( Bug.hs, Bug.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.4.1 for x86_64-unknown-linux):
        tyConRep
  (#|#)
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
        pprPanic, called at compiler/deSugar/DsBinds.hs:1314:5 in ghc:DsBinds

If you use an unboxed sum data constructor, you can get a different panic:

{-# LANGUAGE PartialTypeSignatures #-}                                                             
{-# LANGUAGE TemplateHaskell #-}                                                                   
{-# LANGUAGE TypeInType #-}                                                                        
{-# LANGUAGE UnboxedSums #-}                                                                       
module Bug2 where

import Language.Haskell.TH
import Type.Reflection

type Fweemp = $(conT (unboxedSumDataName 1 2))

doopafloop :: _ => TypeRep Fweemp
doopafloop = typeRep
$ ghc Bug2.hs
[1 of 1] Compiling Bug2             ( Bug2.hs, Bug2.o )
GHC error in desugarer lookup in Bug2:
  Can't find interface-file declaration for variable $tc'(#_|#)
    Probable cause: bug in .hi-boot file, or inconsistent .hi file
    Use -ddump-if-trace to get an idea of which file caused the error
ghc: panic! (the 'impossible' happened)
  (GHC version 8.4.1 for x86_64-unknown-linux):
        initDs

Change History (6)

comment:1 Changed 17 months ago by RyanGlScott

Component: CompilerCompiler (Type checker)
Type of failure: None/UnknownCompile-time crash or panic
Version: 8.2.28.4.1

comment:2 Changed 17 months ago by RyanGlScott

Ah, #13276 claims that unboxed sums shouldn't be Typeable at all. I'm fine with this, but it would be nice to have a proper error message in the event one tries to do this instead of panicking. (The commit which established this limitation, 42ff5d97b486d50b0d10e474f47e86822bb71ace, didn't add any regression tests, which might explain why these infelicities went unnoticed.)

comment:3 Changed 17 months ago by bgamari

Differential Rev(s): Phab:D4622, Phab:D4623
Status: newpatch

Whoops!

See Phab:D4622 and Phab:D4623.

comment:4 Changed 17 months ago by Ben Gamari <ben@…>

In 0f046aa/ghc:

testsuite: Add test for #15067

Subscribers: thomie, carter, RyanGlScott

GHC Trac Issues: #15067

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

comment:5 Changed 16 months ago by Ben Gamari <ben@…>

In f0212a93/ghc:

TcInteract: Ensure that tycons have representations before solving for Typeable

Summary: This fixes #15067.

Test Plan: Validate

Subscribers: thomie, carter, RyanGlScott

GHC Trac Issues: #15067

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

comment:6 Changed 16 months ago by RyanGlScott

Resolution: fixed
Status: patchclosed
Test Case: typecheck/should_fail/T15067

Thanks, Ben!

#13276 tracks the remaining issue of making unboxed sum type/data constructors Typeable.

Note: See TracTickets for help on using tickets.