on master help sign in
Add comments to explain inlining/fusion/rewrite-rules
0914c06Harendra Kumar
src/Streamly.hs+1−1
@@ -61,7 +61,7 @@
61{-# OPTIONS_GHC -Wno-orphans #-}
61{-# OPTIONS_GHC -Wno-orphans #-}
62#endif
62#endif
63
63
64−#include "Streamly/Streams/inline.h"
64+#include "Streamly/Streams/inline.hs"
65
65
66module Streamly
66module Streamly
67 (
67 (
src/Streamly/Prelude.hs+1−1
@@ -9,7 +9,7 @@
9{-# OPTIONS_GHC -Wno-orphans #-}
9{-# OPTIONS_GHC -Wno-orphans #-}
10#endif
10#endif
11
11
12−#include "Streams/inline.h"
12+#include "Streams/inline.hs"
13
13
14-- |
14-- |
15-- Module : Streamly.Prelude
15-- Module : Streamly.Prelude
src/Streamly/Streams/SVar.hs+1−1
@@ -6,7 +6,7 @@
6{-# LANGUAGE RankNTypes #-}
6{-# LANGUAGE RankNTypes #-}
7{-# LANGUAGE UndecidableInstances #-} -- XXX
7{-# LANGUAGE UndecidableInstances #-} -- XXX
8
8
9−#include "inline.h"
9+#include "inline.hs"
10
10
11-- |
11-- |
12-- Module : Streamly.Streams.SVar
12-- Module : Streamly.Streams.SVar
src/Streamly/Streams/Serial.hs+1−1
@@ -58,7 +58,7 @@ import qualified Streamly.Streams.StreamK as K
58import qualified Streamly.Streams.StreamD as D
58import qualified Streamly.Streams.StreamD as D
59
59
60#include "Instances.hs"
60#include "Instances.hs"
61−#include "inline.h"
61+#include "inline.hs"
62
62
63------------------------------------------------------------------------------
63------------------------------------------------------------------------------
64-- SerialT
64-- SerialT
src/Streamly/Streams/StreamD.hs+1−1
@@ -7,7 +7,7 @@
7{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RankNTypes #-}
9
9
10−#include "inline.h"
10+#include "inline.hs"
11
11
12-- |
12-- |
13-- Module : Streamly.Streams.StreamD
13-- Module : Streamly.Streams.StreamD
src/Streamly/Streams/inline.hdeleted−3
@@ -1,3 +0,0 @@
1−#define INLINE_EARLY INLINE [2]
2−#define INLINE_NORMAL INLINE [1]
3−#define INLINE_LATE INLINE [0]
src/Streamly/Streams/inline.hsnew file+27
@@ -0,0 +1,27 @@
1+-- We use fromStreamK/toStreamK to convert the direct style stream to CPS
2+-- style. In the first phase we try fusing the fromStreamK/toStreamK using:
3+--
4+-- {-# RULES "fromStreamK/toStreamK fusion"
5+-- forall s. toStreamK (fromStreamK s) = s #-}
6+--
7+-- If for some reason some of the operations could not be fused then we have
8+-- fallback rules in the second phase. For example:
9+--
10+-- {-# INLINE_EARLY unfoldr #-}
11+-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12+-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
13+-- {-# RULES "unfoldr fallback to StreamK" [1]
14+-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
15+--
16+-- Then, fromStreamK/toStreamK are inlined in the last phase:
17+--
18+-- {-# INLINE_LATE toStreamK #-}
19+-- toStreamK :: Monad m => Stream m a -> K.Stream m a```
20+--
21+-- The fallback rules make sure that if we could not fuse the direct style
22+-- operations then better use the CPS style operation, because unfused direct
23+-- style would have worse performance than the CPS style ops.
24+
25+#define INLINE_EARLY INLINE [2]
26+#define INLINE_NORMAL INLINE [1]
27+#define INLINE_LATE INLINE [0]
streamly.cabal+1−1
@@ -88,7 +88,7 @@ extra-source-files:
88 stack-8.0.yaml
88 stack-8.0.yaml
89 stack.yaml
89 stack.yaml
90 src/Streamly/Streams/Instances.hs
90 src/Streamly/Streams/Instances.hs
91− src/Streamly/Streams/inline.h
91+ src/Streamly/Streams/inline.hs
92
92
93source-repository head
93source-repository head
94 type: git
94 type: git