on master help sign in
Add ability to not use any INLINE pragma on size
626e355Harendra Kumar
core/src/Streamly/Internal/Data/Serialize/TH.hs+30−17
@@ -169,9 +169,12 @@ mkSizeDec (Config {..}) headTy cons = do
169 cfgRecordSyntaxWithHeader
169 cfgRecordSyntaxWithHeader
170 (typeOfType headTy cons)
170 (typeOfType headTy cons)
171 pure
171 pure
172+ ( maybe
173+ []
172− [ PragmaD (InlineP 'size cfgInlineSize FunLike AllPhases)
174+ (\x -> [PragmaD (InlineP 'size x FunLike AllPhases)])
175+ cfgInlineSize
173− , FunD 'size [Clause [] (NormalB sizeOfMethod) []]
176+ ++ [FunD 'size [Clause [] (NormalB sizeOfMethod) []]]
174− ]
177+ )
175
178
176--------------------------------------------------------------------------------
179--------------------------------------------------------------------------------
177-- Peek
180-- Peek
@@ -275,8 +278,12 @@ mkDeserializeDec (Config {..}) headTy cons = do
275 headTy
278 headTy
276 (typeOfType headTy cons)
279 (typeOfType headTy cons)
277 pure
280 pure
281+ ( maybe
282+ []
278− [ PragmaD (InlineP 'deserialize cfgInlineDeserialize FunLike AllPhases)
283+ (\x -> [PragmaD (InlineP 'deserialize x FunLike AllPhases)])
284+ cfgInlineDeserialize
285+ ++
279− , FunD
286+ [ FunD
280 'deserialize
287 'deserialize
281 [ Clause
288 [ Clause
282 (if isUnitType cons && not cfgConstructorTagAsString
289 (if isUnitType cons && not cfgConstructorTagAsString
@@ -285,7 +292,8 @@ mkDeserializeDec (Config {..}) headTy cons = do
285 (NormalB peekMethod)
292 (NormalB peekMethod)
286 []
293 []
287 ]
294 ]
288− ]
295+ ]
296+ )
289
297
290--------------------------------------------------------------------------------
298--------------------------------------------------------------------------------
291-- Poke
299-- Poke
@@ -379,17 +387,22 @@ mkSerializeDec (Config {..}) headTy cons = do
379 cfgRecordSyntaxWithHeader
387 cfgRecordSyntaxWithHeader
380 (typeOfType headTy cons)
388 (typeOfType headTy cons)
381 pure
389 pure
390+ ( maybe
391+ []
382− [ PragmaD (InlineP 'serialize cfgInlineSerialize FunLike AllPhases)
392+ (\x -> [PragmaD (InlineP 'serialize x FunLike AllPhases)])
393+ cfgInlineSerialize
394+ ++
383− , FunD
395+ [FunD
384− 'serialize
396+ 'serialize
385− [ Clause
397+ [ Clause
386− (if isUnitType cons && not cfgConstructorTagAsString
398+ (if isUnitType cons && not cfgConstructorTagAsString
387− then [VarP _initialOffset, WildP, WildP]
399+ then [VarP _initialOffset, WildP, WildP]
388− else [VarP _initialOffset, VarP _arr, VarP _val])
400+ else [VarP _initialOffset, VarP _arr, VarP _val])
389− (NormalB pokeMethod)
401+ (NormalB pokeMethod)
390− []
402+ []
391− ]
403+ ]
392− ]
404+ ]
405+ )
393
406
394--------------------------------------------------------------------------------
407--------------------------------------------------------------------------------
395-- Main
408-- Main
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+25−21
@@ -74,38 +74,42 @@ import Streamly.Internal.Data.Unbox.TH (DataCon(..))
74-- Config
74-- Config
75--------------------------------------------------------------------------------
75--------------------------------------------------------------------------------
76
76
77−-- XXX Need to make it (Maybe Inline) so that we can use Nothing as default.
78−
79-- | Configuration to control how the 'Serialize' instance is generated. Use
77-- | Configuration to control how the 'Serialize' instance is generated. Use
80-- 'defaultConfig' and config setter functions to generate desired Config. For
78-- 'defaultConfig' and config setter functions to generate desired Config. For
81-- example:
79-- example:
82--
80--
83−-- >>> (inlineSize Inline) . (inlineSerialize Inlinable) defaultConfig
81+-- >>> (inlineSize (Just Inline)) . (inlineSerialize (Just Inlinable)) defaultConfig
84--
82--
85data Config =
83data Config =
86 Config
84 Config
87− { cfgInlineSize :: Inline
85+ { cfgInlineSize :: Maybe Inline
88− , cfgInlineSerialize :: Inline
86+ , cfgInlineSerialize :: Maybe Inline
89− , cfgInlineDeserialize :: Inline
87+ , cfgInlineDeserialize :: Maybe Inline
90 , cfgConstructorTagAsString :: Bool
88 , cfgConstructorTagAsString :: Bool
91 , cfgRecordSyntaxWithHeader :: Bool
89 , cfgRecordSyntaxWithHeader :: Bool
92 }
90 }
93
91
94-- | How should we inline the 'size' function? The default in 'defaultConfig'
92-- | How should we inline the 'size' function? The default in 'defaultConfig'
95−-- is 'Inline'. However, aggressive inlining can bloat the code and increase
93+-- is 'Nothing' which means left to the compiler. Forcing inline on @size@
96−-- compilation times in when there are big functions and too many nesting
94+-- function actually worsens some benchmarks and improves none.
97−-- levels so you can change it accordingly.
98−inlineSize :: Inline -> Config -> Config
95+inlineSize :: Maybe Inline -> Config -> Config
99inlineSize v cfg = cfg {cfgInlineSize = v}
96inlineSize v cfg = cfg {cfgInlineSize = v}
100
97
98+-- XXX Should we make the default Inlinable instead?
99+
101−-- | How should we inline the 'serialize' function? See guidelines in
100+-- | How should we inline the 'serialize' function? The default in
102−-- 'inlineSize'.
101+-- 'defaultConfig' is 'Just Inline'. However, aggressive inlining can bloat the
102+-- code and increase in compilation times when there are big functions and too
103+-- many nesting levels so you can change it accordingly. A 'Nothing' value
104+-- leaves the decision to the compiler.
103−inlineSerialize :: Inline -> Config -> Config
105+inlineSerialize :: Maybe Inline -> Config -> Config
104inlineSerialize v cfg = cfg {cfgInlineSerialize = v}
106inlineSerialize v cfg = cfg {cfgInlineSerialize = v}
105
107
108+-- XXX Should we make the default Inlinable instead?
109+
106-- | How should we inline the 'deserialize' function? See guidelines in
110-- | How should we inline the 'deserialize' function? See guidelines in
107−-- 'inlineSize'.
111+-- 'inlineSerialize'.
108−inlineDeserialize :: Inline -> Config -> Config
112+inlineDeserialize :: Maybe Inline -> Config -> Config
109inlineDeserialize v cfg = cfg {cfgInlineDeserialize = v}
113inlineDeserialize v cfg = cfg {cfgInlineDeserialize = v}
110
114
111-- | __Experimental__
115-- | __Experimental__
@@ -174,16 +178,16 @@ encodeRecordFields v cfg = cfg {cfgRecordSyntaxWithHeader = v}
174
178
175-- | The default configuration settings are:
179-- | The default configuration settings are:
176--
180--
177−-- * 'inlineSize' 'Inline'
181+-- * 'inlineSize' 'Nothing'
178−-- * 'inlineSerialize' 'Inline'
182+-- * 'inlineSerialize' 'Just Inline'
179−-- * 'inlineDeserialize' 'Inline'
183+-- * 'inlineDeserialize' 'Just Inline'
180--
184--
181defaultConfig :: Config
185defaultConfig :: Config
182defaultConfig =
186defaultConfig =
183 Config
187 Config
184− { cfgInlineSize = Inline
188+ { cfgInlineSize = Nothing
185− , cfgInlineSerialize = Inline
189+ , cfgInlineSerialize = Just Inline
186− , cfgInlineDeserialize = Inline
190+ , cfgInlineDeserialize = Just Inline
187 , cfgConstructorTagAsString = False
191 , cfgConstructorTagAsString = False
188 , cfgRecordSyntaxWithHeader = False
192 , cfgRecordSyntaxWithHeader = False
189 }
193 }