Skip to content

Commit a811a86

Browse files
committed
Make sure that 'length' can be inlined (Fixes #97)
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.
1 parent acdcff3 commit a811a86

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Data/Vector/Generic.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ import qualified Data.Traversable as T (Traversable(mapM))
228228
-- | /O(1)/ Yield the length of the vector
229229
length :: Vector v a => v a -> Int
230230
{-# INLINE length #-}
231-
length = Bundle.length . stream
231+
length = Bundle.length . stream'
232232

233233
-- | /O(1)/ Test whether a vector is empty
234234
null :: Vector v a => v a -> Bool
@@ -1995,7 +1995,13 @@ unsafeCopy dst src = UNSAFE_CHECK(check) "unsafeCopy" "length mismatch"
19951995
-- | /O(1)/ Convert a vector to a 'Bundle'
19961996
stream :: Vector v a => v a -> Bundle v a
19971997
{-# INLINE_FUSED stream #-}
1998-
stream v = Bundle.fromVector v
1998+
stream v = stream' v
1999+
2000+
-- Same as 'stream', but can be used to avoid having a cycle in the dependency
2001+
-- graph of functions, which forces GHC to create a loop breaker.
2002+
stream' :: Vector v a => v a -> Bundle v a
2003+
{-# INLINE stream' #-}
2004+
stream' v = Bundle.fromVector v
19992005

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

0 commit comments

Comments
 (0)