Skip to content

Commit 1f12de4

Browse files
Use GHC2024 and GHC2021 extensions
1 parent 99d0790 commit 1f12de4

File tree

19 files changed

+204
-64
lines changed

19 files changed

+204
-64
lines changed

benchmark/Streamly/Benchmark/Data/Array.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
66

77
import Control.DeepSeq (deepseq)
8+
#if __GLASGOW_HASKELL__ >= 810
9+
import Data.Kind (Type)
10+
#endif
811

912
import qualified Streamly.Internal.Data.Array as IA
1013
import qualified GHC.Exts as GHC
1114

1215
-- import qualified Streamly.Data.Array as A
1316
import qualified Streamly.Internal.Data.Array as A
1417

18+
#if __GLASGOW_HASKELL__ >= 810
19+
type Stream :: Type -> Type
20+
#endif
1521
type Stream = A.Array
1622

1723
#include "Streamly/Benchmark/Data/Array/Common.hs"

benchmark/Streamly/Benchmark/Data/MutArray.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import Control.DeepSeq (NFData(..))
2323
import Control.Monad.IO.Class (MonadIO)
2424
import Data.Functor ((<&>))
25+
#if __GLASGOW_HASKELL__ >= 810
26+
import Data.Kind (Type)
27+
#endif
2528
import System.Random (randomRIO)
2629
import Prelude
2730
( IO
@@ -52,6 +55,9 @@ import qualified Streamly.Internal.Data.Stream as Stream
5255
import Test.Tasty.Bench
5356
import Streamly.Benchmark.Common hiding (benchPureSrc)
5457

58+
#if __GLASGOW_HASKELL__ >= 810
59+
type Stream :: Type -> Type
60+
#endif
5561
type Stream = MutArray
5662

5763
instance NFData (MutArray a) where

benchmark/streamly-benchmarks.cabal

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,23 @@ flag use-prelude
6969
-------------------------------------------------------------------------------
7070

7171
common default-extensions
72+
default-language: Haskell2010
73+
74+
-- GHC2024 may include more extensions than we are actually using, see the
75+
-- full list below. We enable this to ensure that we are able to compile
76+
-- with this i.e. there is no interference by other extensions.
77+
if impl(ghc >= 9.10)
78+
default-language: GHC2024
79+
80+
if impl(ghc >= 9.2) && impl(ghc < 9.10)
81+
default-language: GHC2021
82+
83+
if impl(ghc >= 8.10)
84+
default-extensions: StandaloneKindSignatures
85+
86+
-- In GHC 2024
7287
default-extensions:
7388
BangPatterns
74-
CApiFFI
75-
CPP
7689
ConstraintKinds
7790
DeriveDataTypeable
7891
DeriveGeneric
@@ -84,29 +97,33 @@ common default-extensions
8497
InstanceSigs
8598
KindSignatures
8699
LambdaCase
87-
MagicHash
88100
MultiParamTypeClasses
89-
PatternSynonyms
90101
RankNTypes
91-
RecordWildCards
92102
ScopedTypeVariables
93103
TupleSections
94104
TypeApplications
95-
TypeFamilies
96105
TypeOperators
97-
ViewPatterns
98106

99-
-- MonoLocalBinds, enabled by TypeFamilies, causes performance
100-
-- regressions. Disable it. This must come after TypeFamilies,
101-
-- otherwise TypeFamilies will enable it again.
102-
NoMonoLocalBinds
107+
-- Not in GHC2024
108+
CApiFFI
109+
CPP
110+
MagicHash
111+
RecordWildCards
112+
-- MonoLocalBinds, enabled by TypeFamilies and GHC2024, was
113+
-- once found to cause runtime performance regressions which
114+
-- does not seem to be the case anymore, but need more testing
115+
-- to confirm. It is confirmed that it requires more memory
116+
-- for compilation at least in some cases (Data.Fold.Window
117+
-- benchmark on GHC-9.10.1 macOS). Disabling this must come
118+
-- after TypeFamilies, otherwise TypeFamilies will enable it
119+
-- again.
120+
-- NoMonoLocalBinds
103121

104122
-- UndecidableInstances -- Does not show any perf impact
105123
-- UnboxedTuples -- interferes with (#.)
106124

107125
common compile-options
108126
import: default-extensions
109-
default-language: Haskell2010
110127

111128
if flag(use-streamly-core)
112129
cpp-options: -DUSE_STREAMLY_CORE
@@ -229,7 +246,7 @@ library
229246
common bench-options
230247
import: compile-options, optimization-options, bench-depends
231248
include-dirs: .
232-
ghc-options: -rtsopts
249+
ghc-options: -rtsopts -with-rtsopts "-t"
233250
if flag(limit-build-mem)
234251
ghc-options: +RTS -M512M -RTS
235252
build-depends: streamly-benchmarks == 0.0.0
@@ -239,7 +256,7 @@ common bench-options-threaded
239256
import: compile-options, optimization-options, bench-depends
240257
-- -threaded and -N2 is important because some GC and space leak issues
241258
-- trigger only with these options.
242-
ghc-options: -threaded -rtsopts -with-rtsopts "-N2"
259+
ghc-options: -threaded -rtsopts -with-rtsopts "-t -N2"
243260
if flag(limit-build-mem)
244261
ghc-options: +RTS -M512M -RTS
245262
build-depends: streamly-benchmarks == 0.0.0
@@ -313,6 +330,10 @@ benchmark Data.Fold.Window
313330
type: exitcode-stdio-1.0
314331
hs-source-dirs: Streamly/Benchmark/Data/Fold
315332
main-is: Window.hs
333+
-- MonoLocalBinds increases the memory requirement from 400MB to 1000MB,
334+
-- observed on macOS.
335+
if flag(limit-build-mem)
336+
ghc-options: +RTS -M1000M -RTS
316337

317338
benchmark Data.MutArray
318339
import: bench-options

core/src/Streamly/Internal/Data/IORef.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ where
3939
#include "inline.hs"
4040

4141
import Control.Monad.IO.Class (MonadIO(..))
42+
#if __GLASGOW_HASKELL__ >= 810
43+
import Data.Kind (Type)
44+
#endif
4245
import Data.Proxy (Proxy(..))
4346
import Streamly.Internal.Data.MutByteArray.Type (MutByteArray)
4447
import Streamly.Internal.Data.Unbox (Unbox(..), sizeOf)
@@ -47,6 +50,9 @@ import qualified Streamly.Internal.Data.MutByteArray.Type as MBA
4750
import qualified Streamly.Internal.Data.Stream.Type as D
4851

4952
-- | An 'IORef' holds a single 'Unbox'-able value.
53+
#if __GLASGOW_HASKELL__ >= 810
54+
type IORef :: Type -> Type
55+
#endif
5056
newtype IORef a = IORef MutByteArray
5157

5258
-- | Create a new 'IORef'.

core/src/Streamly/Internal/Data/Parser.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE NoMonoLocalBinds #-}
23
-- |
34
-- Module : Streamly.Internal.Data.Parser
45
-- Copyright : (c) 2020 Composewell Technologies

core/src/Streamly/Internal/Data/Parser/Type.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE NoMonoLocalBinds #-}
23
-- |
34
-- Module : Streamly.Internal.Data.Parser.ParserD.Type
45
-- Copyright : (c) 2020 Composewell Technologies

core/src/Streamly/Internal/Data/Pipe/Type.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ where
3636
-- import Control.Arrow (Arrow(..))
3737
import Control.Category (Category(..))
3838
import Data.Functor ((<&>))
39+
#if __GLASGOW_HASKELL__ >= 810
40+
import Data.Kind (Type)
41+
#endif
3942
import Fusion.Plugin.Types (Fuse(..))
4043
import Streamly.Internal.Data.Fold.Type (Fold(..))
4144
import Streamly.Internal.Data.Scanr (Scanr(..))
@@ -146,6 +149,9 @@ instance Functor m => Functor (Pipe m a) where
146149
-------------------------------------------------------------------------------
147150

148151
{-# ANN type ComposeConsume Fuse #-}
152+
#if __GLASGOW_HASKELL__ >= 810
153+
type ComposeConsume :: Type -> Type -> Type -> Type
154+
#endif
149155
data ComposeConsume csL psL csR =
150156
ComposeConsume csL csR
151157

@@ -614,6 +620,9 @@ filter f = filterM (return Prelude.. f)
614620
-- that.
615621

616622
{-# ANN type FromFoldConsume Fuse #-}
623+
#if __GLASGOW_HASKELL__ >= 810
624+
type FromFoldConsume :: Type -> Type -> Type
625+
#endif
617626
data FromFoldConsume s x = FoldConsumeInit | FoldConsumeGo s
618627

619628
{-# ANN type FromFoldProduce Fuse #-}

core/src/Streamly/Internal/Data/Stream/Type.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ import Control.Monad.IO.Class (MonadIO(..))
172172
import Data.Foldable (Foldable(foldl'), fold, foldr)
173173
import Data.Functor (($>))
174174
import Data.Functor.Identity (Identity(..))
175+
#if __GLASGOW_HASKELL__ >= 810
176+
import Data.Kind (Type)
177+
#endif
175178
import Data.Maybe (fromMaybe)
176179
import Data.Semigroup (Endo(..))
177180
import Fusion.Plugin.Types (Fuse(..))
@@ -1837,6 +1840,9 @@ foldIterateBfs = undefined
18371840

18381841
-- s = stream state, fs = fold state
18391842
{-# ANN type FoldManyPost Fuse #-}
1843+
#if __GLASGOW_HASKELL__ >= 810
1844+
type FoldManyPost :: Type -> Type -> Type -> Type -> Type
1845+
#endif
18401846
data FoldManyPost s fs b a
18411847
= FoldManyPostStart s
18421848
| FoldManyPostLoop s fs
@@ -1918,6 +1924,9 @@ foldManySepBy :: -- Monad m =>
19181924
foldManySepBy _f1 _f2 = undefined
19191925

19201926
{-# ANN type FoldMany Fuse #-}
1927+
#if __GLASGOW_HASKELL__ >= 810
1928+
type FoldMany :: Type -> Type -> Type -> Type -> Type
1929+
#endif
19211930
data FoldMany s fs b a
19221931
= FoldManyStart s
19231932
| FoldManyFirst fs s

core/src/Streamly/Internal/Data/StreamK/Type.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ import Control.Monad.IO.Class (MonadIO(..))
164164
import Data.Foldable (Foldable(foldl'), fold, foldr)
165165
import Data.Function (fix)
166166
import Data.Functor.Identity (Identity(..))
167+
#if __GLASGOW_HASKELL__ >= 810
168+
import Data.Kind (Type)
169+
#endif
167170
import Data.Maybe (fromMaybe)
168171
import Data.Semigroup (Endo(..))
169172
import GHC.Exts (IsList(..), IsString(..), oneShot)
@@ -233,12 +236,18 @@ mkStream
233236
mkStream = MkStream
234237

235238
-- | A terminal function that has no continuation to follow.
239+
#if __GLASGOW_HASKELL__ >= 810
240+
type StopK :: (Type -> Type) -> Type
241+
#endif
236242
type StopK m = forall r. m r -> m r
237243

238244
-- | A monadic continuation, it is a function that yields a value of type "a"
239245
-- and calls the argument (a -> m r) as a continuation with that value. We can
240246
-- also think of it as a callback with a handler (a -> m r). Category
241247
-- theorists call it a codensity type, a special type of right kan extension.
248+
#if __GLASGOW_HASKELL__ >= 810
249+
type YieldK :: (Type -> Type) -> Type -> Type
250+
#endif
242251
type YieldK m a = forall r. (a -> m r) -> m r
243252

244253
_wrapM :: Monad m => m a -> YieldK m a

core/src/Streamly/Internal/FileSystem/File.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ where
9595

9696
import Control.Monad.Catch (MonadCatch)
9797
import Control.Monad.IO.Class (MonadIO(..))
98+
import Data.Kind (Type)
9899
import Data.Word (Word8)
99100
import System.IO (Handle, openFile, IOMode(..), hClose)
100101
import Prelude hiding (read)
@@ -204,15 +205,15 @@ usingFile3 = UF.bracketIO before after
204205
-- /Pre-release/
205206
--
206207
{-# INLINABLE putChunk #-}
207-
putChunk :: FilePath -> Array a -> IO ()
208+
putChunk :: forall (a :: Type). FilePath -> Array a -> IO ()
208209
putChunk file arr = SIO.withFile file WriteMode (`FH.putChunk` arr)
209210

210211
-- | append an array to a file.
211212
--
212213
-- /Pre-release/
213214
--
214215
{-# INLINABLE writeAppendArray #-}
215-
writeAppendArray :: FilePath -> Array a -> IO ()
216+
writeAppendArray :: forall (a :: Type). FilePath -> Array a -> IO ()
216217
writeAppendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
217218

218219
-------------------------------------------------------------------------------
@@ -369,7 +370,7 @@ readShared = undefined
369370
-------------------------------------------------------------------------------
370371

371372
{-# INLINE fromChunksMode #-}
372-
fromChunksMode :: (MonadIO m, MonadCatch m)
373+
fromChunksMode :: forall m (a :: Type). (MonadIO m, MonadCatch m)
373374
=> IOMode -> FilePath -> Stream m (Array a) -> m ()
374375
fromChunksMode mode file xs = S.fold drain $
375376
withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
@@ -379,7 +380,7 @@ fromChunksMode mode file xs = S.fold drain $
379380
-- /Pre-release/
380381
--
381382
{-# INLINE fromChunks #-}
382-
fromChunks :: (MonadIO m, MonadCatch m)
383+
fromChunks :: forall m (a :: Type). (MonadIO m, MonadCatch m)
383384
=> FilePath -> Stream m (Array a) -> m ()
384385
fromChunks = fromChunksMode WriteMode
385386

@@ -431,7 +432,7 @@ write = toHandleWith A.defaultChunkSize
431432
--
432433
-- /Pre-release/
433434
{-# INLINE writeChunks #-}
434-
writeChunks :: (MonadIO m, MonadCatch m)
435+
writeChunks :: forall m (a :: Type). (MonadIO m, MonadCatch m)
435436
=> FilePath -> Fold m (Array a) ()
436437
writeChunks path = Fold step initial extract final
437438
where
@@ -487,7 +488,7 @@ write = writeWith defaultChunkSize
487488
-- /Pre-release/
488489
--
489490
{-# INLINE writeAppendChunks #-}
490-
writeAppendChunks :: (MonadIO m, MonadCatch m)
491+
writeAppendChunks :: forall m (a :: Type). (MonadIO m, MonadCatch m)
491492
=> FilePath -> Stream m (Array a) -> m ()
492493
writeAppendChunks = fromChunksMode AppendMode
493494

0 commit comments

Comments
 (0)