Opened 8 years ago

# New way to make the simplifier diverge

Reported by: Owned by: simonpj normal ⊥ Compiler 6.12.1 anton.nik@… Unknown/Multiple Unknown/Multiple None/Unknown #5400 #5448

### Description

GHC's simplifier can go into a loop if you use fixpoints in a funny way, as documented here http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html#bugs-ghc (12.2.1, third bullet). But GADTs provide new opportunities. This ticket records one, thanks to Ryan Ingram and Matthieu Sozeau:

module Contr where

newtype I f = I (f ())
data R o a where R :: (a (I a) -> o) -> R o (I a)

run :: R o (I (R o)) -> R o (I (R o)) -> o
run x (R f) = f x
rir :: (R o) (I (R o))
rir = R (\x -> run x x)

absurd :: a
absurd = run rir rir

Now the simplifier can loop. Look:

run rir rir

= {inline run}
case rir of R f -> f rir

= {case of known constructor}
let { f = \x -> run x x } in f rir

= {inline f}
run rir rir

### comment:3 Changed 3 months ago by sgraf

Related Tickets: → #5400 #5448

This doesn't loop infinitely anymore with GHC 8.2.1 and instead panics:

ghc.exe: panic! (the 'impossible' happened)
(GHC version 8.2.1 for x86_64-unknown-mingw32):
Simplifier ticks exhausted
When trying UnfoldingDone rir_s1bm
To increase the limit, use -fsimpl-tick-factor=N (default 100)
If you need to do this, let GHC HQ know, and what factor you needed
To see detailed counts use -ddump-simpl-stats
Total ticks: 11721
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler\utils\Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler\utils\Outputable.hs:1137:37 in ghc:Outputable