Ticket #2597 (closed merge: fixed)

Opened 5 years ago

Last modified 5 years ago

panic! (the 'impossible' happened) (using TH)

Reported by: jcab Owned by: igloo
Priority: normal Milestone:
Component: Template Haskell Version: 6.8.3
Keywords: Cc:
Operating System: Windows Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: th/T2597a, th/T2597b Blocked By:
Blocking: Related Tickets:

Description

ghc: panic! (the 'impossible' happened)

(GHC version 6.8.3 for i386-unknown-mingw32):

Prelude.init: empty list

Attached the compilable files for your enjoyment and reproduction.

Attachments

bug.zip Download (5.5 KB) - added by jcab 5 years ago.
Compilable project (just use the batch file as "ghcmake kk.hs")

Change History

Changed 5 years ago by jcab

Compilable project (just use the batch file as "ghcmake kk.hs")

Changed 5 years ago by simonpj

  • difficulty set to Unknown

The good news is that things are better with the HEAD, as you see below.

But I have no idea what the "Failing due to -Werror" is about, since I hvae not specified -Werror. Ian, Simon, any ideas?

Simon

c:/darcs/HEAD/ghc/stage2-inplace/ghc --make kk.hs -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances -fno-monomorphism-restriction -threaded -lKernel32 -lUser32 -lGdi32 -lOle32 -lComctl32 -optc-D_WIN32_IE=0x700 -optc-D_WIN32_WINNT=0x600 -ilib -odir obj -hidir obj -stubdir obj 

on the commandline:
    Warning: -fallow-undecidable-instances is deprecated: use -XUndecidableInstances or pragma {-# LANGUAGE UndecidableInstances#-} instead

on the commandline:
    Warning: -fallow-overlapping-instances is deprecated: use -XOverlappingInstances or pragma {-# LANGUAGE OverlappingInstances#-} instead

on the commandline:
    Warning: -fno-monomorphism-restriction is deprecated: use -XNoMonomorphismRestriction or pragma {-# LANGUAGE NoMonomorphismRestriction#-} instead

kk.hs:1:11:
    Warning: -fth is deprecated: use -XTemplateHaskell or pragma {-# LANGUAGE TemplateHaskell#-} instead

lib\JCAB\TH.hs:1:11:
    Warning: -fth is deprecated: use -XTemplateHaskell or pragma {-# LANGUAGE TemplateHaskell#-} instead

lib\Win32\System\TH.hs:1:11:
    Warning: -fth is deprecated: use -XTemplateHaskell or pragma {-# LANGUAGE TemplateHaskell#-} instead
[4 of 4] Compiling Main             ( kk.hs, obj\Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Loading object (dynamic) Kernel32 ... done
Loading object (dynamic) User32 ... done
Loading object (dynamic) Gdi32 ... done
Loading object (dynamic) Ole32 ... done
Loading object (dynamic) Comctl32 ... done
final link ... done
Loading package syb ... linking ... done.
Loading package array-0.1 ... linking ... done.
Loading package packedstring-0.1 ... linking ... done.

<no location info>: 
Failing due to -Werror.

Loading package containers-0.1 ... linking ... done.
Loading package pretty-1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package mtl-1.1.0.1 ... linking ... done.
make: *** [default] Error 1
bash-3.2$ 

Changed 5 years ago by jcab

A-ha! I've reduced this to the minimal. It is caused by trying to expand list comprehensions:

mkBug = returnQ $ CompE [BindS (VarP $ mkName "p") (ListE []), NoBindS (VarE $ mkName "p")]

That simple template causes the panic (on 6.8.3) when invoked:

bug = $mkBug

My code seems to work correctly if I get the comprehensions eliminated at template-compile time so there are no comprehensions in the returned expression tree.

BTW: defining comprehensions as "CompE [Stmt]" is... weird. Putting the two statements in the opposite order doesn't change the outcome.

Changed 5 years ago by jcab

And yet another case that gives GHC the shivers:

mkBug2 = returnQ $ DoE []

Granted, that's an incorrect tree, but...

Changed 5 years ago by simonpj

  • owner set to simonpj

Great report thank you. Actually there are two bugs, which I have fixed. I'll push a patch shortly.

Simon

Changed 5 years ago by simonpj

  • owner changed from simonpj to igloo
  • type changed from bug to merge

Here are the patches.

Sat Sep 20 22:20:10 GMT Daylight Time 2008  simonpj@microsoft.com
  * Fix Trac #2597 (first bug): correct type checking for empty list
  
  The GHC front end never generates (ExplicitList []), but TH can.
  This patch makes the typechecker robust to such programs.
  

Sat Sep 20 22:11:01 GMT Daylight Time 2008  simonpj@microsoft.com
  * Fix Trac #2597 (second bug): complain about an empty DoE block
  
  When converting an empty do-block from TH syntax to HsSyn,
  complain rather than crashing.

Ian; worth merging these across I think. Both are small

Simon

Changed 5 years ago by simonpj

  • testcase set to th/T2597a, th/T2597b

Changed 5 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Both merged.

Note: See TracTickets for help on using tickets.