on master help sign in
Add comments to explain inlining/fusion/rewrite-rules
commit0914c063307925103ece0d3d7398af12203c0401 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 28 Oct 2018, 01:49 (8 years ago) parent06242af
8 files changed+33−9
src/Streamly.hs+1−1 src/Streamly/Prelude.hs+1−1 src/Streamly/Streams/SVar.hs+1−1 src/Streamly/Streams/Serial.hs+1−1 src/Streamly/Streams/StreamD.hs+1−1 src/Streamly/Streams/inline.h−3 src/Streamly/Streams/inline.hs+27 streamly.cabal+1−1
src/Streamly.hs+1−1
@@ -61,7 +61,7 @@
6161{-# OPTIONS_GHC -Wno-orphans #-}
6262#endif
6363
64−#include "Streamly/Streams/inline.h"
64+#include "Streamly/Streams/inline.hs"
6565
6666module Streamly
6767 (
src/Streamly/Prelude.hs+1−1
@@ -9,7 +9,7 @@
99{-# OPTIONS_GHC -Wno-orphans #-}
1010#endif
1111
12−#include "Streams/inline.h"
12+#include "Streams/inline.hs"
1313
1414-- |
1515-- Module : Streamly.Prelude
src/Streamly/Streams/SVar.hs+1−1
@@ -6,7 +6,7 @@
66{-# LANGUAGE RankNTypes #-}
77{-# LANGUAGE UndecidableInstances #-} -- XXX
88
9−#include "inline.h"
9+#include "inline.hs"
1010
1111-- |
1212-- Module : Streamly.Streams.SVar
src/Streamly/Streams/Serial.hs+1−1
@@ -58,7 +58,7 @@ import qualified Streamly.Streams.StreamK as K
5858import qualified Streamly.Streams.StreamD as D
5959
6060#include "Instances.hs"
61−#include "inline.h"
61+#include "inline.hs"
6262
6363------------------------------------------------------------------------------
6464-- SerialT
src/Streamly/Streams/StreamD.hs+1−1
@@ -7,7 +7,7 @@
77{-# LANGUAGE MultiParamTypeClasses #-}
88{-# LANGUAGE RankNTypes #-}
99
10−#include "inline.h"
10+#include "inline.hs"
1111
1212-- |
1313-- 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:
8888 stack-8.0.yaml
8989 stack.yaml
9090 src/Streamly/Streams/Instances.hs
91− src/Streamly/Streams/inline.h
91+ src/Streamly/Streams/inline.hs
9292
9393source-repository head
9494 type: git