Skip to content

Commit

Permalink
Make sure that 'length' can be inlined (Fixes haskell#97)
Browse files Browse the repository at this point in the history
Previously there was a cycle in the dependency graph of functions,
consisting of {stream, clone, length, unsafeCopy}. This was causing GHC
to mark one of these functions, length, as a loop breaker.

This commit breaks this down this strongly-connected component by
removing the edge from length to stream.
  • Loading branch information
takano-akio committed Feb 17, 2017
1 parent acdcff3 commit a811a86
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Data/Vector/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ import qualified Data.Traversable as T (Traversable(mapM))
-- | /O(1)/ Yield the length of the vector
length :: Vector v a => v a -> Int
{-# INLINE length #-}
length = Bundle.length . stream
length = Bundle.length . stream'

-- | /O(1)/ Test whether a vector is empty
null :: Vector v a => v a -> Bool
Expand Down Expand Up @@ -1995,7 +1995,13 @@ unsafeCopy dst src = UNSAFE_CHECK(check) "unsafeCopy" "length mismatch"
-- | /O(1)/ Convert a vector to a 'Bundle'
stream :: Vector v a => v a -> Bundle v a
{-# INLINE_FUSED stream #-}
stream v = Bundle.fromVector v
stream v = stream' v

-- Same as 'stream', but can be used to avoid having a cycle in the dependency
-- graph of functions, which forces GHC to create a loop breaker.
stream' :: Vector v a => v a -> Bundle v a
{-# INLINE stream' #-}
stream' v = Bundle.fromVector v

{-
stream v = v `seq` n `seq` (Bundle.unfoldr get 0 `Bundle.sized` Exact n)
Expand Down

0 comments on commit a811a86

Please sign in to comment.