Skip to content

RULES for recursive functions don't work properly

someone mentioned to me that this expression:

mapM_ action [n..m]

isn't being optimised properly, so I thought I'd look into it. Sure enough, we don't get down to a simple loop like we should, although the F/B transformation is happening (see ~simonmar/scratch/mapm.hs). The problem is that GHC.Enum.eftIntFB isn't being inlined, it's defined like this:

{-# INLINE [0] eftIntFB #-}
eftIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> r
eftIntFB c n x y | x ># y    = n	
		 | otherwise = go x
		 where
		   go x = I# x `c` if x ==# y then n else go (x +# 1#)

but, strangely, the inlining doesn't appear in the interface:

eftIntFB :: (GHC.Base.Int -> r -> r) -> r -> GHC.Prim.Int# -> GHC.Prim.Int# -> r
  {- Arity: 4 HasNoCafRefs Strictness: LLLL -}

This is becuase the RULE make eftIntFB look recursive, so its inlining isnt' exposed. Bad, bad.

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information