Skip to content

Commit

Permalink
[#90] Check more ghc warnings through ghc-options (#91)
Browse files Browse the repository at this point in the history
* [#90] Check more ghc warnings through ghc-options

Resolves #90

* Clean up LANGUAGE extensions
  • Loading branch information
vrom911 authored Apr 18, 2020
1 parent 497e182 commit 22af858
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 277 deletions.
85 changes: 46 additions & 39 deletions benchmark/CMap.hs
Original file line number Diff line number Diff line change
@@ -1,70 +1,77 @@
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

module CMap
( spec
) where

import Criterion.Main (bench, nf, env, whnf)
( spec
) where

import Prelude hiding (lookup)

import Spec
import Criterion.Main (bench, env, nf, whnf)
import Data.Kind (Type)
import Data.Maybe (fromJust)
import Data.Proxy (Proxy (..))
import Data.Typeable (Typeable)
import GHC.TypeLits
import GHC.TypeLits (type (+), KnownNat, Nat)

import Data.TypeRep.CMap (TypeRepMap (..), empty, insert, lookup)

import Spec (BenchSpec (..))


spec :: BenchSpec
spec = BenchSpec
{ benchLookup = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env (mkMap 10000) $ \ ~(bigMap) ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Just $ \name ->
env (mkMap 10) $ \ ~(smallMap) ->
bench name $ whnf (inserts smallMap 10) (Proxy @ 0)
, benchUpdateBig = Just $ \name ->
env (mkMap 10000) $ \ ~(bigMap) ->
bench name $ whnf (inserts bigMap 10) (Proxy @ 0)
}
{ benchLookup = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Just $ \name ->
env (mkMap 10) $ \ ~smallMap ->
bench name $ whnf (inserts smallMap 10) (Proxy @ 0)
, benchUpdateBig = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ whnf (inserts bigMap 10) (Proxy @ 0)
}

tenLookups :: TypeRepMap (Proxy :: Nat -> *)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups
:: TypeRepMap (Proxy :: Nat -> Type)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
where
lp :: forall (a::Nat). Typeable a => Proxy a
lp = fromJust $ lookup tmap

inserts :: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> *)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> *)
inserts
:: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> Type)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> Type)
inserts !c 0 _ = c
inserts !c n x = inserts
(insert x c)
(n-1)
(Proxy :: Proxy (a+1))
(insert x c)
(n-1)
(Proxy :: Proxy (a+1))

mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> *))
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> Type))
mkMap n = pure $ buildBigMap n (Proxy :: Proxy 0) empty

buildBigMap :: forall a . (KnownNat a) => Int -> Proxy (a :: Nat) -> TypeRepMap (Proxy :: Nat -> *) -> TypeRepMap (Proxy :: Nat -> *)
buildBigMap
:: forall a . (KnownNat a)
=> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> Type)
-> TypeRepMap (Proxy :: Nat -> Type)
buildBigMap 1 x = insert x
buildBigMap n x = insert x . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))
93 changes: 48 additions & 45 deletions benchmark/CacheMap.hs
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

module CacheMap
( spec
) where

import Criterion.Main (bench, nf, whnf, env)
import Spec
( spec
) where

import Prelude hiding (lookup)

import Criterion.Main (bench, env, nf, whnf)
import Data.Kind (Type)
import Data.Maybe (fromJust)
import Data.Proxy (Proxy (..))
import Data.Typeable (Typeable)
import GHC.Exts (fromList)
import GHC.TypeLits
import GHC.TypeLits (type (+), KnownNat, Nat)

import Data.TypeRepMap.Internal (TypeRepMap (..), WrapTypeable (..), empty, insert, lookup)

import Spec (BenchSpec (..))

import Data.TypeRepMap.Internal (TypeRepMap (..), WrapTypeable (..), lookup, insert, empty)

spec :: BenchSpec
spec = BenchSpec
{ benchLookup = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env (mkMap 10000) $ \ ~(bigMap) ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Just $ \name ->
env (mkMap 10) $ \ ~(smallMap) ->
bench name $ whnf (inserts smallMap 10) (Proxy @ 0)
, benchUpdateBig = Just $ \name ->
env (mkMap 10000) $ \ ~(bigMap) ->
bench name $ whnf (inserts bigMap 10) (Proxy @ 0)
}
{ benchLookup = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Just $ \name ->
env (mkMap 10) $ \ ~smallMap ->
bench name $ whnf (inserts smallMap 10) (Proxy @ 0)
, benchUpdateBig = Just $ \name ->
env (mkMap 10000) $ \ ~bigMap ->
bench name $ whnf (inserts bigMap 10) (Proxy @ 0)
}

tenLookups :: TypeRepMap (Proxy :: Nat -> *)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups
:: TypeRepMap (Proxy :: Nat -> Type)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
where
lp :: forall (a::Nat). Typeable a => Proxy a
lp :: forall (a :: Nat) . Typeable a => Proxy a
lp = fromJust $ lookup tmap

inserts :: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> *)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> *)
inserts
:: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> Type)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> Type)
inserts !c 0 _ = c
inserts !c n x = inserts
(insert x c)
(n-1)
(Proxy :: Proxy (a+1))
(insert x c)
(n-1)
(Proxy :: Proxy (a + 1))

mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> *))
mkMap :: Int -> IO (TypeRepMap (Proxy :: Nat -> Type))
mkMap n = pure $ fromList $ buildBigMap n (Proxy :: Proxy 0) []


buildBigMap :: forall a . (KnownNat a)
=> Int
-> Proxy (a :: Nat)
-> [WrapTypeable (Proxy :: Nat -> *)]
-> [WrapTypeable (Proxy :: Nat -> *)]
buildBigMap
:: forall a . (KnownNat a)
=> Int
-> Proxy (a :: Nat)
-> [WrapTypeable (Proxy :: Nat -> Type)]
-> [WrapTypeable (Proxy :: Nat -> Type)]
buildBigMap 1 x = (WrapTypeable x :)
buildBigMap n x = (WrapTypeable x :) . buildBigMap (n - 1) (Proxy :: Proxy (a + 1))
87 changes: 45 additions & 42 deletions benchmark/DMap.hs
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}

module DMap
( spec
) where

import Criterion.Main (bench, env, nf, whnf)
( spec
) where

import Prelude hiding (lookup)

import Control.DeepSeq (NFData (..))
import Criterion.Main (bench, env, nf, whnf)
import Data.Kind (Type)
import Data.Maybe (fromJust)
import Data.Proxy (Proxy (..))
import GHC.TypeLits
import Spec
import GHC.TypeLits (type (+), KnownNat, Nat)
import Type.Reflection (TypeRep, Typeable, typeRep)
import Type.Reflection.Unsafe (typeRepFingerprint)

import Data.Dependent.Map (DMap, empty, insert, keys, lookup)
import Data.Some (Some (Some))

type TypeRepMap = DMap TypeRep
import Spec (BenchSpec (..))


type TypeRepMap = DMap TypeRep

spec :: BenchSpec
spec = BenchSpec
{ benchLookup = Just $ \name ->
env mkBigMap $ \ ~(DMapNF bigMap) ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env mkBigMap $ \ ~(DMapNF bigMap) ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Nothing -- Not implemented
, benchUpdateBig = Nothing -- Not implemented
}
{ benchLookup = Just $ \name ->
env mkBigMap $ \ ~(DMapNF bigMap) ->
bench name $ nf tenLookups bigMap
, benchInsertSmall = Just $ \name ->
bench name $ whnf (inserts empty 10) (Proxy @ 99999)
, benchInsertBig = Just $ \name ->
env mkBigMap $ \ ~(DMapNF bigMap) ->
bench name $ whnf (inserts bigMap 1) (Proxy @ 99999)
, benchUpdateSmall = Nothing -- Not implemented
, benchUpdateBig = Nothing -- Not implemented
}

tenLookups :: TypeRepMap (Proxy :: Nat -> *)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups
:: TypeRepMap (Proxy :: Nat -> Type)
-> ( Proxy 10, Proxy 20, Proxy 30, Proxy 40
, Proxy 50, Proxy 60, Proxy 70, Proxy 80
)
tenLookups tmap = (lp, lp, lp, lp, lp, lp, lp, lp)
where
lp :: forall (a :: Nat) . Typeable a => Proxy a
lp = fromJust $ lookup (typeRep @a) tmap

inserts :: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> *)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> *)
inserts
:: forall a . (KnownNat a)
=> TypeRepMap (Proxy :: Nat -> Type)
-> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> Type)
inserts !c 0 _ = c
inserts !c n x = inserts
(insert (typeRep @ a) x c)
(n-1)
(Proxy :: Proxy (a+1))
(insert (typeRep @ a) x c)
(n-1)
(Proxy :: Proxy (a+1))

-- TypeRepMap of 10000 elements
mkBigMap :: IO (DMapNF (Proxy :: Nat -> *))
mkBigMap :: IO (DMapNF (Proxy :: Nat -> Type))
mkBigMap = pure . DMapNF $ buildBigMap 10000 (Proxy :: Proxy 0) empty

buildBigMap :: forall a . (KnownNat a)
=> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> *)
-> TypeRepMap (Proxy :: Nat -> *)
buildBigMap
:: forall a . (KnownNat a)
=> Int
-> Proxy (a :: Nat)
-> TypeRepMap (Proxy :: Nat -> Type)
-> TypeRepMap (Proxy :: Nat -> Type)
buildBigMap 1 x = insert (typeRep @a) x
buildBigMap n x = insert (typeRep @a) x
. buildBigMap (n - 1) (Proxy @(a + 1))
Expand All @@ -82,5 +84,6 @@ buildBigMap n x = insert (typeRep @a) x
newtype DMapNF f = DMapNF (TypeRepMap f)

instance NFData (DMapNF f) where
rnf (DMapNF x) =
rnf . map (\(Some t) -> typeRepFingerprint t) $ keys x
rnf :: DMapNF f -> ()
rnf (DMapNF x) =
rnf . map (\(Some t) -> typeRepFingerprint t) $ keys x
Loading

0 comments on commit 22af858

Please sign in to comment.