Code bloat with -XStrictData leads to large compile time
@jappeace posted the following reproducer on reddit:
{-# LANGUAGE Haskell2010, OverloadedStrings, StrictData #-}
module Display where
import Data.Text (Text, pack)
data OpCode = OpCode OpName deriving (Eq, Show)
data OpName
= LDA | LDX | LDY | STA | STX | STY | TAX | TAY | TXA | TYA | TSX | TXS | PHA | PHP | PLA | PLP | AND | EOR | ORA | BIT | ADC
| SBC | CMP | CPX | CPY | INC | INX | INY | DEC | DEX | DEY | ASL | LSR | ROL | ROR | JMP | JSR | RTS | BCC | BCS | BEQ | BMI | BNE | BPL
| BVC | BVS | CLC | CLD | CLI | CLV | SEC | SED | SEI | BRK | NOP | RTI
deriving (Eq, Show)
class Display a where
display :: a -> Text
instance Display OpCode where
display (OpCode opn ) =
"OpCode - " <> pack (show opn)
Compiling this module with GHC master and -O2
takes 6GB! (Down from 6.8 in GHC 8.10, though). 2GB alone are spent in CodeGen. Remove the StrictData
pragma and it compiles instantaneously.
It appears that we inline pack
and show
, expose a Stream fusion pipeline and try to fuse it with the Text
literal prefix. The code is enormous.
I can make out at least two sources for the bloat:
- The Simplifier blows up the program from roughly 2k terms to 34k terms within one run after
FloatOut
. (That's probably phase 1 simplification, which will inlinepack
) - The final nail in the coffin is added by SpecConstr, which blows the program up to 110k terms
I have a hunch that (1) is related to #20246 (closed) and #19996 (closed).