Opened 3 years ago

Closed 3 years ago

#9160 closed bug (fixed)

Panic: Template variable unbound in rewrite rule

Reported by: mietek Owned by:
Priority: normal Milestone: 7.8.3
Component: Compiler Version: 7.8.2
Keywords: Cc: jstolarek, slyfox, george
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: Compile-time crash Test Case: indexed_types/should_fail/T9160
Blocked By: Blocking:
Related Tickets: #4524 Differential Rev(s):
Wiki Page:

Description (last modified by mietek)

Installing singletons-1.0 with GHC 7.8.2 on both OS X 10.9.2 and Ubuntu 2014.04 fails:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.2 for x86_64-apple-darwin):
        Template variable unbound in rewrite rule

This seems to be an issue with the optimizer, as the bug only appears with optimization level 2, using the following line in ~/.cabal/config:

optimization: 2

See also goldfirere/singletons#83

Attachments (4)

singletons-1.0.log (10.4 KB) - added by mietek 3 years ago.
Build log
ghc.info (1.7 KB) - added by mietek 3 years ago.
ghc --info
singletons-1.0-build.log (9.5 KB) - added by mjo 3 years ago.
ghc-info.txt (1.8 KB) - added by mjo 3 years ago.

Download all attachments as: .zip

Change History (22)

Changed 3 years ago by mietek

Attachment: singletons-1.0.log added

Build log

comment:1 Changed 3 years ago by mietek

comment:2 Changed 3 years ago by mietek

Changed 3 years ago by mietek

Attachment: ghc.info added

ghc --info

comment:3 Changed 3 years ago by mietek

Description: modified (diff)

comment:4 Changed 3 years ago by mietek

Operating System: MacOS XUnknown/Multiple

comment:5 Changed 3 years ago by mietek

Description: modified (diff)

comment:6 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In b637585dcbfc1ba53aa49bcb9b730cd08fea4b59/ghc:

Fix elemLocalRdrEnv (Trac #9160)

This was pretty obscure.  elemLocalRdrEnv was utterly wrong (replied
False when it should reply True) when given an Exact Name. That
doesn't happen often, but it does happen in the result of a TH splice.
The result was that an associated type didn't get a type variable that
lined up with its parent class (elemLocalRdrEnv is used in
RnTypes.bindHsTyVars), and that messed up the singletons package.

I've made a completely different test case to show up the bug:
indexed_types/should_fail/T9160

I also refactored RdrName.LocalRdrEnv to be a record with named
fields, which makes the code more robust and easy to understand.

comment:7 Changed 3 years ago by simonpj

Status: newmerge
Test Case: indexed_types/should_fail/T9160

comment:8 Changed 3 years ago by thoughtpolice

Milestone: 7.8.3

comment:9 Changed 3 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Merged into 7.8.3.

comment:10 Changed 3 years ago by mjo

Resolution: fixed
Status: closednew

I'm seeing the same symptoms with 7.8.3:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.3

Only with -O2 set, again.

$ cd singletons-1.0/
$ runghc Setup.hs configure --user -O2
Configuring singletons-1.0...
$ runghc Setup.hs build
...
[39 of 45] Compiling Data.Singletons.Prelude.List ( src/Data/Singletons/Prelude/List.hs, dist/build/Data/Singletons/Prelude/List.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.3 for x86_64-unknown-linux):
	Template variable unbound in rewrite rule

Changed 3 years ago by mjo

Attachment: singletons-1.0-build.log added

Changed 3 years ago by mjo

Attachment: ghc-info.txt added

comment:11 Changed 3 years ago by mjo

I should also mention that the test cases passes, i.e. fails:

$ ghc T9160.hs
[1 of 1] Compiling T9160            ( T9160.hs, T9160.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.

T9160.hs:18:8:
    Type indexes must match class instance head
    Found ‘* -> *’ but expected ‘*’
    In the type instance declaration for ‘F’
    In the instance declaration for ‘C (a :: *)’

Same thing happens with -O2.

comment:12 Changed 3 years ago by slyfox

Cc: slyfox added

comment:13 Changed 3 years ago by George

I am also seeing this on ghc 7.10.1, not sure if this is another instance of this bug:

cabal install bitmap [ 3 of 10] Compiling Data.Bitmap.IO ( Data/Bitmap/IO.hs, dist/build/Data/Bitmap/IO.o )

Data/Bitmap/IO.hs:1248:1: Warning:

SPECIALISE pragma for non-overloaded function ‘myPlusPtr’

Data/Bitmap/IO.hs:1249:1: Warning:

SPECIALISE pragma for non-overloaded function ‘myPlusPtr’

ghc: panic! (the 'impossible' happened)

(GHC version 7.10.1 for x86_64-apple-darwin):

Template variable unbound in rewrite rule

$fPixelComponentFloat3_X2Rc [$fPixelComponentFloat3_X2Rc] [$fPixelComponentFloat3_X2Rc] [] []

Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug

Last edited 3 years ago by George (previous) (diff)

comment:14 Changed 3 years ago by George

Cc: george added

comment:15 in reply to:  13 Changed 3 years ago by slyfox

Replying to George:

I am also seeing this on ghc 7.10.1, not sure if this is another instance of this bug:

cabal install bitmap [ 3 of 10] Compiling Data.Bitmap.IO ( Data/Bitmap/IO.hs, dist/build/Data/Bitmap/IO.o )

I've distilled it a bit to a selfcontained test:

-- sf 9160 # cat B.hs 
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -O2 #-}
module B (bug) where

data D = D
data E = E

class Storable a where
    poke2 :: a -> E
instance Storable D where
    poke2 = poke2 -- undefined

class Foo a where
instance Foo D where

class (Foo t, Storable t) => FooStorable t where

instance FooStorable D where
    {-# SPECIALIZE instance FooStorable D #-}

{-# SPECIALIZE bug :: D -> E #-}

bug
  :: FooStorable t
  => t
  -> E
bug = poke2
{-
sf 9160 # ghc -c -fforce-recomp -Wall B.hs 

B.hs:5:10: Warning: Defined but not used: data constructor ‘D’

B.hs:6:10: Warning: Defined but not used: data constructor ‘E’
ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1 for x86_64-unknown-linux):
        Template variable unbound in rewrite rule
  $fFooStorableD_XU
  [$fFooStorableD_XU]
  [$fFooStorableD_XU]
  []
  []

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
-}

comment:16 Changed 3 years ago by simonpj

Good report, but comment:15 and comment:16 are definitely a different bug to #9160. I've opened #10251.

Simon

comment:17 Changed 3 years ago by goldfire

Should we re-close this ticket then?

comment:18 Changed 3 years ago by simonpj

Resolution: fixed
Status: newclosed

Well, comment:10 claims that GHC 7.8.3 couldn't compile singletons. However I've confirmed that HEAD can compile singletons-1.1, so yes, I'll close this.

Simon

Note: See TracTickets for help on using tickets.