Skip to content

Simplifier ticks exhausted on recursive class method

GHC 7.8 and HEAD panic on the following code:

module C where

class C a where
  c :: C a => a -> Int
  c a = c a
  {-# INLINE c #-}

instance C ()

x :: Int
x = c ()

Note that it's the coincidence of the 3 conditions that triggers this bug:

  1. the c method has to be inlined (explicity or implicitly)
  2. it has to be recursive (but, it doesn't have to be as dumbly recursive as in the example)
  3. it has to have this weird, slightly mistaken type signature: C a => a -> Int instead of simply a -> Int.

But, when this incidentally happens (in my case, both 2. and 3. were unintentional), the user gets a very hard to debug issue. They don't even get an indication which module is responsible if c is used from a different module than the one with the class definition.

Also note that this happens even with a non-optimized build. And in this example c has to be explicitly marked NOINLINE to prevent it. (In the instance that I caught in the wild simply removing the INLINE annotation was enough.)

Finally, on a side note: shouldn't 3. by itself be an error? Or a warning at least?

Trac metadata
Trac field Value
Version 7.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information