summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2019-08-22 12:09:24 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2019-08-23 12:04:15 +0300
commita8300520a714fa5e46e342e10175d237d89221c5 (patch)
tree90823e8854bebb6288a94e36613f8c022336a367 /compiler/utils
parentc3e26ab3bd450a2ad17cc80b41dda084558039a2 (diff)
downloadhaskell-a8300520a714fa5e46e342e10175d237d89221c5.tar.gz
Make non-streaming LLVM and C backends streaming
This adds a Stream.consume function, uses it in LLVM and C code generators, and removes the use of Stream.collect function which was used to collect streaming Cmm generation results into a list. LLVM and C backends now properly use streamed Cmm generation, instead of collecting Cmm groups into a list before generating LLVM/C code.
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Stream.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/utils/Stream.hs b/compiler/utils/Stream.hs
index ad01fad40c..2ad2b8cc7a 100644
--- a/compiler/utils/Stream.hs
+++ b/compiler/utils/Stream.hs
@@ -7,7 +7,7 @@
-- -----------------------------------------------------------------------------
module Stream (
Stream(..), yield, liftIO,
- collect, fromList,
+ collect, consume, fromList,
Stream.map, Stream.mapM, Stream.mapAccumL
) where
@@ -71,6 +71,15 @@ collect str = go str []
Left () -> return (reverse acc)
Right (a, str') -> go str' (a:acc)
+consume :: Monad m => Stream m a b -> (a -> m ()) -> m b
+consume str f = do
+ r <- runStream str
+ case r of
+ Left ret -> return ret
+ Right (a, str') -> do
+ f a
+ consume str' f
+
-- | Turn a list into a 'Stream', by yielding each element in turn.
fromList :: Monad m => [a] -> Stream m a ()
fromList = mapM_ yield