@@ -318,6 +318,7 @@ mkSerializeExpr headTy cons =
320-- $(deriveSerializeInternal
320-- $(deriveSerializeInternal
321+-- defaultSerializeTHConfig
321-- [AppT (ConT ''Serialize) (VarT (mkName "b"))]
322-- [AppT (ConT ''Serialize) (VarT (mkName "b"))]
323-- (AppT (ConT ''CustomDataType) (VarT (mkName "a")))
324-- (AppT (ConT ''CustomDataType) (VarT (mkName "a")))
@@ -331,17 +332,18 @@ mkSerializeExpr headTy cons =
331-- [(Nothing, (ConT ''Bool)), (Nothing, (VarT (mkName "b")))]
332-- [(Nothing, (ConT ''Bool)), (Nothing, (VarT (mkName "b")))]
334−deriveSerializeInternal :: Cxt -> Type -> [DataCon] -> Q [Dec]
335+deriveSerializeInternal ::
336+ SerializeTHConfig -> Cxt -> Type -> [DataCon] -> Q [Dec]
335−deriveSerializeInternal preds headTy cons = do
337+deriveSerializeInternal (SerializeTHConfig{..}) preds headTy cons = do
336 sizeOfMethod <- mkSizeOfExpr headTy cons
338 sizeOfMethod <- mkSizeOfExpr headTy cons
337 peekMethod <- mkDeserializeExpr headTy cons
339 peekMethod <- mkDeserializeExpr headTy cons
338 pokeMethod <- mkSerializeExpr headTy cons
340 pokeMethod <- mkSerializeExpr headTy cons
339 let methods =
341 let methods =
340 -- INLINE on sizeOf actually worsens some benchmarks, and improves
342 -- INLINE on sizeOf actually worsens some benchmarks, and improves
342− [ -- PragmaD (InlineP 'size Inlinable FunLike AllPhases)
344+ [ PragmaD (InlineP 'size inlineSize FunLike AllPhases)
343− FunD 'size [Clause [] (NormalB sizeOfMethod) []]
345+ , FunD 'size [Clause [] (NormalB sizeOfMethod) []]
344− , PragmaD (InlineP 'deserialize Inline FunLike AllPhases)
346+ , PragmaD (InlineP 'deserialize inlineDeserialize FunLike AllPhases)
346 'deserialize
348 'deserialize
@@ -351,7 +353,7 @@ deriveSerializeInternal preds headTy cons = do
351 (NormalB peekMethod)
353 (NormalB peekMethod)
354− , PragmaD (InlineP 'serialize Inline FunLike AllPhases)
356+ , PragmaD (InlineP 'serialize inlineSerialize FunLike AllPhases)
356 'serialize
358 'serialize
@@ -403,13 +405,13 @@ data SerializeTHConfig =
405 -- @f@ is replaced with 'Identity' and becomes unconstrained.
407 -- @f@ is replaced with 'Identity' and becomes unconstrained.
407 , inlineSize :: Inline
408 , inlineSize :: Inline
408− -- ^ Inline value for 'size'.
409+ -- ^ Inline value for 'size'. Default is Inline.
409 , inlineSerialize :: Inline
410 , inlineSerialize :: Inline
410− -- ^ Inline value for 'serialize'.
411+ -- ^ Inline value for 'serialize'. Default is Inline.
411 , inlineDeserialize :: Inline
412 , inlineDeserialize :: Inline
412− -- ^ Inline value for 'deserialize'.
413+ -- ^ Inline value for 'deserialize'. Default is Inline.
413 , constructorTagAsString :: Bool
415 , constructorTagAsString :: Bool
414 -- ^ If True, encode constructors as Latin-1 byte sequence. This
416 -- ^ If True, encode constructors as Latin-1 byte sequence. This
415 -- allows addition, removal, and reordering of constructors. If False
417 -- allows addition, removal, and reordering of constructors. If False
@@ -422,19 +424,26 @@ data SerializeTHConfig =
424defaultSerializeTHConfig :: SerializeTHConfig
426defaultSerializeTHConfig :: SerializeTHConfig
425−defaultSerializeTHConfig = SerializeTHConfig {unconstrainedTypeVars = [], typeVarSubstitutions = []}
427+defaultSerializeTHConfig =
429+ { unconstrainedTypeVars = []
430+ , typeVarSubstitutions = []
431+ , inlineSize = Inline
432+ , inlineSerialize = Inline
433+ , inlineDeserialize = Inline
427-- | Similar to 'deriveSerialize,' but take a 'SerializeTHConfig' to control how
436-- | Similar to 'deriveSerialize,' but take a 'SerializeTHConfig' to control how
428-- the instance is generated.
437-- the instance is generated.
430-- Usage: @$(deriveSerializeWith config ''CustomDataType)@
439-- Usage: @$(deriveSerializeWith config ''CustomDataType)@
431deriveSerializeWith :: SerializeTHConfig -> Name -> Q [Dec]
440deriveSerializeWith :: SerializeTHConfig -> Name -> Q [Dec]
432−deriveSerializeWith (SerializeTHConfig {..}) name = do
441+deriveSerializeWith conf@(SerializeTHConfig {..}) name = do
433 dt <- reifyDataType name
442 dt <- reifyDataType name
434 let preds = map (unboxPred . VarT) (filterOutVars (dtTvs dt))
443 let preds = map (unboxPred . VarT) (filterOutVars (dtTvs dt))
435 headTy = appsT (ConT name) (map substituteVar (dtTvs dt))
444 headTy = appsT (ConT name) (map substituteVar (dtTvs dt))
436 cons = dtCons dt
445 cons = dtCons dt
437− deriveSerializeInternal preds headTy cons
446+ deriveSerializeInternal conf preds headTy cons
440 allUnconstrainedTypeVars =
449 allUnconstrainedTypeVars =