Opened 6 years ago

Closed 6 years ago

#7445 closed bug (fixed)

template-haskell : need a good error message instead of just an unexplained panic

Reported by: erikd Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case: th/T7445
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Will attach two files to this bug, quasi-arithmetic.hs and QuasiArith.hs.


ghc --make quasi-arithmetic.hs -o quasi-arithmetic

on these files results in:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.4.2 for x86_64-unknown-linux):
    main:QuasiArith BinopExpr{d}[(0B, base:System.IO.print{v 0B}),
                                  (32I, ghc-prim:GHC.Types.IO{tc 32I}),
                                  (40, ghc-prim:GHC.Tuple.(){(w) tc 40}),
                                  (rwP, main:QuasiArith.MulOp{d rwP}),
                                  (rwR, main:QuasiArith.AddOp{d rwR}),
                                  (rwU, main:QuasiArith.BinopExpr{d rwU}),
                                  (rwW, main:QuasiArith.IntExpr{d rwW}),
                                  (r2Ha, main:Main.main{v r2Ha})]

Attachments (2)

QuasiArith.hs (4.1 KB) - added by erikd 6 years ago.
quasi-arithmetic.hs (142 bytes) - added by erikd 6 years ago.

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by erikd

Attachment: QuasiArith.hs added

Changed 6 years ago by erikd

Attachment: quasi-arithmetic.hs added

comment:1 Changed 6 years ago by erikd


Same problem with GHC version 7.6.1.

comment:2 Changed 6 years ago by erikd

Should mention that the original source of those files was :

comment:3 Changed 6 years ago by erikd

Summary: template-haskell : the impossible happenedtemplate-haskell : need a good error message instead of just an unexplained panic

Found the problem, for QuasiArith.hs I had:

module QuasiArith
    ( eval
    , expr
    ) where

If I change the module declaration to:

module QuasiArith where

it no longer panics and in fact even works and generates the correct result.

I'm not sure what was causing it to fail. I tried exporting all top level functions and values in QuasiArith.hs and it still failed.

Would in be sensible to disallow restricted exports for all files that import Language.Haskell.TH.Quote?

comment:4 Changed 6 years ago by erikd


Confirmed in GHC HEAD as well.

comment:5 Changed 6 years ago by erikd

Hmm, this works:

module QuasiArith
    ( Expr (..)
    , BinOp (..)
    , eval
    , expr
    ) where

Problem seems to have been that type Expr and BinOp were not exported.

comment:6 Changed 6 years ago by simonpj@…

commit 9a20e540754fc2af74c2e7392f2786a81d8d5f11

Author: Simon Peyton Jones <>
Date:   Thu Dec 6 16:03:16 2012 +0000

    Stop attempting to "trim" data types in interface files
    Without -O, we previously tried to make interface files smaller
    by not including the data constructors of data types.  But
    there are a lot of exceptions, notably when Template Haskell is
    involved or, more recently, DataKinds.
    However Trac #7445 shows that even without TemplateHaskell, using
    the Data class and invoking Language.Haskell.TH.Quote.dataToExpQ
    is enough to require us to expose the data constructors.
    So I've given up on this "optimisation" -- it's probably not
    important anyway.  Now I'm simply not attempting to trim off
    the data constructors.  The gain in simplicity is worth the
    modest cost in interface file growth, which is limited to the
    bits reqd to describe those data constructors.

 compiler/main/TidyPgm.lhs |  207 ++++++++++++++++++++++++---------------------
 1 files changed, 109 insertions(+), 98 deletions(-)

comment:7 Changed 6 years ago by simonpj

difficulty: Unknown
Status: newmerge
Test Case: th/T7445

comment:8 Changed 6 years ago by igloo

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.