Opened 3 years ago

Closed 10 months ago

#7241 closed bug (fixed)

GHC-7.6.1 panics on template haskell code

Reported by: akamaus Owned by: Yuras
Priority: normal Milestone: 7.8.3
Component: Template Haskell Version: 7.6.1
Keywords: Cc: lightwing15@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

While experimenting with TH I stumbled upon a repeating compiler panic. After minifying I got this example which triggers the failure:

% cat Peekler.hs
module Peekler where

import Language.Haskell.TH

tst = do
  o <- newName "Foo"
  return $ [DataD [] o [] [RecC o []] [''Show]]
% cat PeeklerTest.hs
module PeeklerTest where

import Peekler

$(tst)

test = print Foo
% ghci -XTemplateHaskell PeeklerTest.hs             
GHCi, version 7.6.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Peekler          ( Peekler.hs, interpreted )
[2 of 2] Compiling PeeklerTest      ( PeeklerTest.hs, interpreted )
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
ghc: panic! (the 'impossible' happened)
  (GHC version 7.6.1 for i386-unknown-linux):
        lookupExactOcc
<<details unavailable>>

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

> 
Leaving GHCi.
% ghc  -XTemplateHaskell PeeklerTest.hs
[1 of 2] Compiling Peekler          ( Peekler.hs, Peekler.o )
[2 of 2] Compiling PeeklerTest      ( PeeklerTest.hs, PeeklerTest.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
ghc: panic! (the 'impossible' happened)
  (GHC version 7.6.1 for i386-unknown-linux):
        lookupExactOcc
    Foo_a18S{tc}
    [main:PeeklerTest.Foo{tc a18S} defined at PeeklerTest.hs:5:3,
     main:PeeklerTest.Foo{d a18S} defined at PeeklerTest.hs:5:3]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:        12.04
Codename:       precise

Attachments (1)

0001-Emit-error-in-case-of-duplicate-GRE-fixes-Trac-7241.patch (4.8 KB) - added by Yuras 10 months ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 3 years ago by simonpj

  • difficulty set to Unknown

Thanks. You are defining the same precise name twice:

  data Foo_79 = Foo_79

where Foo_79 is the exact name. This is bad, because you are defining the same name twice. You probably intended mkName rather than newName.

But GHC shouldn't crash, and I will fix that. Thanks.

Simon

comment:2 Changed 2 years ago by igloo

  • Component changed from Compiler to Template Haskell
  • Milestone set to 7.8.1
  • Owner set to simonpj

comment:3 Changed 11 months ago by thoughtpolice

  • Status changed from new to infoneeded

comment:4 Changed 11 months ago by Yuras

It seems to be a duplicate of or similar to #8932

comment:5 Changed 10 months ago by Yuras

  • Status changed from infoneeded to new

Well, the original issue was indeed fixed by #8932,
but it still crashes a bit later:

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 7.9.20140523 for x86_64-unknown-linux):
	kcLookupKind APromotionErr RecDataConPE

comment:6 Changed 10 months ago by Yuras

  • Owner changed from simonpj to Yuras

So, the comment added in changeset:d8d798b1b33ab0593ed03f193360b8725ba2c2ba is not fully correct. findLocalDupsRdrEnv doesn't catch this particular case because duplicate Names are totally identical, including SrcSpan.

I'll prepare a patch to emit error in case of duplicate GRE. The test case from #8932 will produce two errors, but I think it is ok. Definitely better then obscure panic.

Please let me know if I'm going in wrong direction.

comment:7 Changed 10 months ago by Yuras

  • Status changed from new to patch

comment:8 Changed 10 months ago by Amatic

  • Cc lightwing15@… added

comment:9 Changed 10 months ago by Austin Seipp <austin@…>

In c226d25fef519db663d0c9efe7845637423f1dca/ghc:

Emit error in case of duplicate GRE; fixes #7241

Signed-off-by: Austin Seipp <[email protected]>

comment:10 Changed 10 months ago by thoughtpolice

  • Status changed from patch to merge

comment:11 Changed 10 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed

Merged.

Note: See TracTickets for help on using tickets.