Opened 4 years ago

Closed 4 years ago

#5569 closed bug (fixed)

Ineffective seq/BangPatterns

Reported by: Owned by: igloo
Priority: normal Milestone: 7.4.1
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This could be related to #5557, but it might be something else. 7.2.1 was very picky about where you placed your bangs/seqs, for example

{-# LANGUAGE BangPatterns #-}
module Main (main) where

main :: IO ()
main = print (f 1000000)

f :: Integer -> Integer
f n = go n 0
    go 0 !sm = sm
    go k acc = go (k-1) (acc+k)


module Main (main) where

main :: IO ()
main = print (f 1000000)

f :: Integer -> Integer
f n = go n 0
    go a b | a `seq` b `seq` False = undefined
    go k acc
        | k == 0    = acc
        | otherwise = go (k-1) (acc+k)

gave a stack overflow when compiled with ghc -O2. You have to place the bang/seq on the second equation for it to work. Older ghc versions treated it well, as does HEAD, so it seems fixed, but perhaps a regression test is in order?

Change History (3)

comment:1 Changed 4 years ago by

  • Type of failure changed from None/Unknown to Runtime performance bug

comment:2 Changed 4 years ago by igloo

  • Milestone set to 7.4.1
  • Owner set to igloo

The bang on the first equation is redundant: Pattern matching is left-to-right, so sm is only forced if the first argument is 0.

But with your code I'm getting a stack overflow with release builds, but not validate builds, of 7.2.2. We should investigate.

comment:3 Changed 4 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

I can't reproduce the above problem with the HEAD, so marking this as fixed.

Note: See TracTickets for help on using tickets.