Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#2154 closed merge (fixed)

Stack overflow due to unsafePerformIO

Reported by: dons Owned by: igloo
Priority: normal Milestone: 6.8.3
Component: Runtime System Version: 6.8.2
Keywords: Cc: dons@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):


The following program, extracted from a utf8 decoder for ByteStrings, overflows the stack when run with rules on. Speaking to SimonM, this is due to the stack squeezing optimisation not working for unsafePerformIO, meaning the resulting loop actually uses up stack.

import qualified Data.ByteString.Char8 as S 

main = putStrLn $ filter (\x -> enc x /= [x]) list
  where list = ['\0'..'\x10ffff'] ++ ['\0'..'\10']

{-# NOINLINE enc #-}
enc :: Char -> String
enc x = S.singleton x `seq` [x]

After fusing and optimising, S.singleton here is allocated using unsafePerformIO to wrap the allocation, and seems to run out of stack.

However, I've confirmed this code does work if its changed to use unsafeDupablePerformIO.

I'm filing this ticket to get documentation on what is going on here, so we can have something to point to if it comes up again, and to clarify that unsafeDupablePerformIO is the correct fix.

SimonM, could you summarise what the issue is?

Change History (4)

comment:1 Changed 8 years ago by simonmar

  • difficulty set to Unknown
  • Milestone set to 6.8.3
  • Owner set to igloo
  • Type changed from bug to merge

Fixed in this patch I committed yesterday:

Thu Feb  7 04:24:45 PST 2008  Simon Marlow <[email protected]>
  * Tweaks to stack squeezing
  1. We weren't squeezing two frames if one of them was a marked update
     frame.  This is easy to fix.
  2. The heuristic to decide whether to squeeze was a little
     conservative.  It's worth copying 3 words to save an update frame.

comment:2 Changed 8 years ago by igloo

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


comment:3 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:4 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.