GHC inlines class method forever
irene-knapp showed me this over IRC, I refined the test case a bit:
{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses #-}
module Bug () where
class C a b where
discord :: C a b => a b () -- Remove the constraint and it works
rhyme :: a b ()
instance C (,) b => C (,) [b] where
discord = discord
rhyme = discord
GHC 7.2.2 compiling this with -O loops forever. I've worked out:
- The
C a bcontext in the class is completely superfluous but the bug isn't triggered without it. - The pattern of recursion in the two method signatures is fragile:
rhyme = rhymedoesn't trigger the bug, for example. - Adding a
NOINLINE discordstops the bug from triggering. Similarly, compiling without optimisations doesn't trigger the bug. - While it's looping, GHC slowly but steadily chews through all of your memory.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |