@@ -26,6 +26,13 @@ import Data.Functor.Identity (Identity (..))
2626import Data.Proxy (Proxy(..))
2727import GHC.Generics (Generic, Rep(..))
2828import GHC.Real (Ratio(..))
29+
30+{-
31+XXX Will be added in the future
32+import Streamly.Internal.Data.Unbox.TH
33+import Language.Haskell.TH
34+-}
35+
2936import Streamly.Internal.Data.Unbox
3037 ( PeekRep(..)
3138 , PokeRep(..)
@@ -44,57 +51,83 @@ import Test.Hspec as H
4451-- Types
4552--------------------------------------------------------------------------------
4653
54+-- #define USE_TH
55+
56+#ifdef USE_TH
57+#define MODULE_NAME "Data.Unbox.Deriving.TH"
58+#define DERIVE_UNBOX(typ) $(makeUnbox ''typ)
59+#else
60+#define MODULE_NAME "Data.Unbox.Deriving.Generic"
61+#define DERIVE_UNBOX(typ) deriving instance Unbox (typ)
62+#endif
63+
64+--------------------------------------------------------------------------------
65+-- Types
66+--------------------------------------------------------------------------------
67+
4768-- Unit instance uses a hack, so test all cases
4869data Unit =
4970 Unit
50− deriving (Unbox, Show, Generic, Eq)
71+ deriving (Show, Generic, Eq)
72+DERIVE_UNBOX(Unit)
5173
5274data UnarySum
5375 = Sum1
5476 | Sum2
55− deriving (Unbox, Show, Generic, Eq)
77+ deriving (Show, Generic, Eq)
78+DERIVE_UNBOX(UnarySum)
79+
5680
5781data UnarySum2
5882 = UnitSum1 Unit
5983 | UnitSum2 Unit
60− deriving (Generic, Unbox, Eq, Show)
84+ deriving (Generic, Eq, Show)
85+DERIVE_UNBOX(UnarySum2)
6186
6287data Unit1 =
6388 Unit1 Unit
64− deriving (Generic, Unbox, Eq, Show)
89+ deriving (Generic, Eq, Show)
90+DERIVE_UNBOX(Unit1)
6591
6692data Unit2 =
6793 Unit2 Unit Unit
68− deriving (Generic, Unbox, Eq, Show)
94+ deriving (Generic, Eq, Show)
95+DERIVE_UNBOX(Unit2)
6996
7097data Unit3 =
7198 Unit3 Int Unit Int
72− deriving (Generic, Unbox, Eq, Show)
99+ deriving (Generic, Eq, Show)
100+DERIVE_UNBOX(Unit3)
73101
74102data Unit4 =
75103 Unit4 Int Unit1 Int
76− deriving (Generic, Unbox, Eq, Show)
104+ deriving (Generic, Eq, Show)
105+DERIVE_UNBOX(Unit4)
77106
78107{-# ANN Single "HLint: ignore" #-}
79108data Single =
80109 Single Int
81− deriving (Unbox, Show, Generic, Eq)
110+ deriving (Show, Generic, Eq)
111+DERIVE_UNBOX(Single)
82112
83113data Product2 =
84114 Product2 Int Char
85− deriving (Unbox, Show, Generic, Eq)
115+ deriving (Show, Generic, Eq)
116+DERIVE_UNBOX(Product2)
86117
87118data SumOfProducts
88119 = SOP0
89120 | SOP1 Int
90121 | SOP2 Int Char
91122 | SOP3 Int Int Int
92− deriving (Unbox, Show, Generic, Eq)
123+ deriving (Show, Generic, Eq)
124+DERIVE_UNBOX(SumOfProducts)
93125
94126data NestedSOP
95127 = NSOP0 SumOfProducts
96128 | NSOP1 SumOfProducts
97− deriving (Unbox, Show, Generic, Eq)
129+ deriving (Show, Generic, Eq)
130+DERIVE_UNBOX(NestedSOP)
98131
99132--------------------------------------------------------------------------------
100133-- Standalone derivations
@@ -213,7 +246,7 @@ testCases = do
213246--------------------------------------------------------------------------------
214247
215248moduleName :: String
216−moduleName = "Data.Unboxed"
249+moduleName = MODULE_NAME
217250
218251main :: IO ()
219252main = hspec $ H.parallel $ describe moduleName testCases