[GHC] #10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Keywords: | Operating System: Linux Architecture: | Type of failure: Compile-time Unknown/Multiple | crash Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- I've seen a few related tickets, but they are market as closed. % ghc -O2 binlist.hs [1 of 1] Compiling Main ( binlist.hs, binlist.o ) ghc: panic! (the 'impossible' happened) (GHC version 7.10.1.20150630 for x86_64-unknown-linux): Template variable unbound in rewrite rule sg_s5zh [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [: @ a_a3fo sc_s5zf sc_s5zg] [: @ a_a3fo sc_s5zb sc_s5zc] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug % cat binlist.hs import Control.Monad import Data.Binary import Data.List newtype A a = A [a] instance Binary a => Binary (A a) where put (A xs) = case splitAt 254 xs of (_, []) -> mapM_ put xs (a, b) -> put (A b) get = do xs <- replicateM 254 get A ys <- get return $ A $ xs ++ ys main :: IO () main = undefined -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Description changed by goldfire: Old description:
I've seen a few related tickets, but they are market as closed.
% ghc -O2 binlist.hs
[1 of 1] Compiling Main ( binlist.hs, binlist.o ) ghc: panic! (the 'impossible' happened) (GHC version 7.10.1.20150630 for x86_64-unknown-linux): Template variable unbound in rewrite rule sg_s5zh [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [: @ a_a3fo sc_s5zf sc_s5zg] [: @ a_a3fo sc_s5zb sc_s5zc]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
% cat binlist.hs import Control.Monad import Data.Binary import Data.List
newtype A a = A [a]
instance Binary a => Binary (A a) where put (A xs) = case splitAt 254 xs of (_, []) -> mapM_ put xs (a, b) -> put (A b)
get = do xs <- replicateM 254 get A ys <- get return $ A $ xs ++ ys
main :: IO () main = undefined
New description: I've seen a few related tickets, but they are market as closed. {{{ % ghc -O2 binlist.hs [1 of 1] Compiling Main ( binlist.hs, binlist.o ) ghc: panic! (the 'impossible' happened) (GHC version 7.10.1.20150630 for x86_64-unknown-linux): Template variable unbound in rewrite rule sg_s5zh [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [: @ a_a3fo sc_s5zf sc_s5zg] [: @ a_a3fo sc_s5zb sc_s5zc] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug % cat binlist.hs import Control.Monad import Data.Binary import Data.List newtype A a = A [a] instance Binary a => Binary (A a) where put (A xs) = case splitAt 254 xs of (_, []) -> mapM_ put xs (a, b) -> put (A b) get = do xs <- replicateM 254 get A ys <- get return $ A $ xs ++ ys main :: IO () main = undefined }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * priority: normal => highest * os: Linux => Unknown/Multiple Comment: This is a regression since 7.10.1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by bgamari): * owner: => bgamari Comment: Oh dear. I'll have a look. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): Precisely what version of GHC are you using? I can reproduce this neither with 7.10.1 nor the current state of the 7.10.2 branch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => infoneeded -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomie): I can reproduce this, but only with the `perf` build, not the `stage2` build. Strange. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by pacak): rc2 downloaded from ghc website as {{{ghc-7.10.1.20150630-src.tar.xz}}} {{{ % cat mk/build.mk GhcRTSWays += debug GhcRTSWays += debug_p GhcRTSWays += thr_debug GhcRTSWays += thr_debug_p BUILD_DOCBOOK_HTML = YES DYNAMIC_GHC_PROGRAMS = NO }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by pacak): ghc 7.10.1 can compile the same code without any problems. This build of rc2 was compiled by ghc 7.10.1 plus a few patches on top related to event manager issues. Before submitting the bug I've confirmed that somebody from #ghc can reproduce it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): I observed the failure with 7.10.2-rc1 (7.10.1.20150612). I forget if I built it myself or downloaded from somewhere. I don't have more recent builds to hand. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by pacak): Step by step manual to reproduce {{{ % tar xf ../ghc-7.10.1.20150630-src.tar.xz % cp mk/build.mk.sample build.mk % vim mk/build.mk -- uncomment BuildFlavour = perf % autoreconf % perl boot % ./configure && make -j4 [stuff] % ./inplace/bin/ghc-stage2 binlist.hs -O2 [1 of 1] Compiling Main ( binlist.hs, binlist.o ) ghc-stage2: panic! (the 'impossible' happened) (GHC version 7.10.1.20150630 for x86_64-unknown-linux): Template variable unbound in rewrite rule sg_s5zd [sc_s5zb, sc_s5zc, sg_s5zd, sg_s5ze] [sc_s5zb, sc_s5zc, sg_s5zd, sg_s5ze] [: @ a_a3fj sc_s5zb sc_s5zc] [: @ a_a3fj sc_s5z7 sc_s5z8] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): Indeed I have reproduced this. Previously I missed that `-O2` was necessary; I believe I was just using `-O` previously. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): Hmm, that being said, this is an extremely sensitive bug. I still haven't been able to reproduce it with the current state of the `ghc-7.10` branch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): If it's working in HEAD and at the tip of the ghc-7.10 branch, I think it's safe to close the ticket with a regression test. Given the sensitivity of the bug, it might be worth the trouble to make sure that the regression test actually fails on, say, 7.10.2-rc1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with
-O2
-------------------------------------+-------------------------------------
Reporter: pacak | Owner: bgamari
Type: bug | Status: infoneeded
Priority: highest | Milestone: 7.10.2
Component: Compiler | Version: 7.10.2-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomie): Test still fails when `base` is compiled with -O2 (as it is in a perf or default/release build). {{{ $ make TEST=T10602 TEST_HC=ghc-7.10.1.20150710 ... =====> T10602(optasm) 92 of 92 [0, 0, 0] cd . && "/opt/ghc/7.10.2/bin/ghc-7.10.1.20150710" -c T10602.hs -fforce- recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-warn-tabs -fno-ghci-history -O -fasm -O2 > T10602.comp.stderr 2>&1 Compile failed (status 256) errors were: ghc: panic! (the 'impossible' happened) (GHC version 7.10.1.20150710 for x86_64-unknown-linux): Template variable unbound in rewrite rule sg_s5zh [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi] [: @ a_a3fj sc_s5zf sc_s5zg] [: @ a_a3fj sc_s5zb sc_s5zc] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomie): I attached an alternative test that also fails with a devel2 build. `-fno- spec-constr` makes the problem go away, as do a few other things (see `T10602.hs`). Maybe this debug message is of help to someone: {{{ $ ./ghc-devel2/inplace/bin/ghc-stage2 T10602.hs [2 of 2] Compiling T10602 ( T10602.hs, T10602.o ) SpecConstr Function ‘$wgo_s13x’ has one call pattern, but the limit is 0 Use -fspec-constr-count=n to set the bound Use -dppr-debug to see specialisations ghc-stage2: panic! (the 'impossible' happened) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): Hmm, this is very odd. thomie, I suppose your alternate test case still on reproduces with the `ghc-stage2` binary? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomie): I'm not sure what you're asking. For me, it fails with both `ghc-stage1` and `ghc-stage2` from a devel2 build of HEAD, as well as with `ghc-7.10.1.20150710` from hvr's ppa. If it wasn't clear: you need both `T10602.hs` and `T10602b.hs`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: infoneeded Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): OK I'm on it. Thank you for a simple repro case. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with
-O2
-------------------------------------+-------------------------------------
Reporter: pacak | Owner: bgamari
Type: bug | Status: merge
Priority: highest | Milestone: 7.10.2
Component: Compiler | Version: 7.10.2-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash | Test Case:
Blocked By: | simplCore/should_compile/T10602
Related Tickets: | Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by simonpj):
* status: infoneeded => merge
* testcase: => simplCore/should_compile/T10602
Comment:
Fixed by
{{{
commit 7da7b0e48598af7df25e1129772b42cb31649c74
Author: Simon Peyton Jones
---------------------------------------------------------------
7da7b0e48598af7df25e1129772b42cb31649c74 compiler/specialise/SpecConstr.hs | 25 ++++++++++-- testsuite/tests/simplCore/should_compile/T10602.hs | 46 +++++++++------------- .../tests/simplCore/should_compile/T10602b.hs | 20 ++++++++++ testsuite/tests/simplCore/should_compile/all.T | 2 +- 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/compiler/specialise/SpecConstr.hs b/compiler/specialise/SpecConstr.hs }}} I forgot to mention the ticket in the commit message. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10602: ghc panic: Template variable unbound in rewrite rule when compiling with -O2 -------------------------------------+------------------------------------- Reporter: pacak | Owner: bgamari Type: bug | Status: closed Priority: highest | Milestone: 7.10.2 Component: Compiler | Version: 7.10.2-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | simplCore/should_compile/T10602 Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-7.10` in 3cadf440c490abc1c8d5d45f5d034809c8912815. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10602#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC