on master help sign in
Add an inspection test for #214
commite7a7801cd919096198c680ab7172c0bae6b86dec authorArtyom Kazak <yom@artyom.me> dateFri 26 Jul 2019, 18:32 (7 years ago) parenta74914d
3 files changed+51−7
src/Streamly/Streams/StreamD.hs+6−6 streamly.cabal+12−1 test/inspection.hs+33
src/Streamly/Streams/StreamD.hs+6−6
@@ -273,7 +273,7 @@ import qualified Control.Monad.Catch as MC
273273import Streamly.Mem.Array.Types (Array(..))
274274import Streamly.Fold.Types (Fold(..))
275275import Streamly.Pipe.Types (Pipe(..), PipeState(..))
276−import Streamly.SVar (MonadAsync, defState, adaptState, State)
276+import Streamly.SVar (MonadAsync, defState, adaptState)
277277
278278import Streamly.Streams.StreamD.Type
279279
@@ -370,11 +370,11 @@ replicateM :: forall m a. Monad m => Int -> m a -> Stream m a
370370replicateM n p = Stream step n
371371 where
372372 {-# INLINE_LATE step #-}
373− step :: State K.Stream m a -> Int -> m (Step Int a)
374− step _ i | i <= 0 = return Stop
375− | otherwise = do
376− x <- p
377− return $ Yield x (i - 1)
373+ step _ (i :: Int)
374+ | i <= 0 = return Stop
375+ | otherwise = do
376+ x <- p
377+ return $ Yield x (i - 1)
378378
379379{-# INLINE_NORMAL replicate #-}
380380replicate :: Monad m => Int -> a -> Stream m a
streamly.cabal+12−1
@@ -339,7 +339,7 @@ test-suite test
339339-- , base >= 4.8 && < 5
340340-- , hspec >= 2.0 && < 3
341341-- default-language: Haskell2010
342−--
342+--
343343-- test-suite pure-streams-streamly
344344-- type: exitcode-stdio-1.0
345345-- main-is: PureStreams.hs
@@ -502,6 +502,17 @@ test-suite parallel-loops
502502 , base >= 4.8 && < 5
503503 , random >= 1.0.0 && < 2
504504
505+test-suite inspection
506+ type: exitcode-stdio-1.0
507+ default-language: Haskell2010
508+ main-is: inspection.hs
509+ hs-source-dirs: test
510+ ghc-options: -fno-ignore-asserts -O2 -Wall -threaded -with-rtsopts=-N
511+ build-Depends:
512+ streamly
513+ , base >= 4.8 && < 5
514+ , inspection-testing >= 0.4 && < 0.5
515+
505516-------------------------------------------------------------------------------
506517-- Benchmarks
507518-------------------------------------------------------------------------------
test/inspection.hsnew file+33
@@ -0,0 +1,33 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE TemplateHaskell #-}
3+
4+{-# OPTIONS_GHC -O -fplugin Test.Inspection.Plugin #-}
5+
6+import Streamly
7+import qualified Streamly.Prelude as S
8+import Test.Inspection
9+
10+main :: IO ()
11+main = pure () -- If the test compiles, it passes
12+
13+-------------------------------------------------------------------------------
14+-- #214 regression test: 'concatMap (replicate n)' should be specialized
15+-------------------------------------------------------------------------------
16+
17+{-# INLINE concatMap1 #-}
18+concatMap1 :: MonadAsync m => SerialT m Int -> m ()
19+concatMap1 src = S.drain $ S.concatMap (S.replicate 3) src
20+
21+{-# INLINE sourceUnfoldrMN #-}
22+sourceUnfoldrMN :: MonadAsync m => Int -> Int -> SerialT m Int
23+sourceUnfoldrMN m n = S.unfoldrM step n
24+ where
25+ step cnt =
26+ if cnt > n + m
27+ then return Nothing
28+ else return (Just (cnt, cnt + 1))
29+
30+test214 :: IO ()
31+test214 = concatMap1 (sourceUnfoldrMN 1000000 5)
32+
33+inspect $ hasNoTypeClasses 'test214