Skip to content

Commit 1271b5c

Browse files
Use GHC2024 and GHC2021 extensions
1 parent 4e2fccb commit 1271b5c

File tree

16 files changed

+105
-21
lines changed

16 files changed

+105
-21
lines changed

benchmark/Streamly/Benchmark/Data/Array.hs

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

77
import Control.DeepSeq (deepseq)
8+
import Data.Kind (Type)
89

910
import qualified Streamly.Internal.Data.Array as IA
1011
import qualified GHC.Exts as GHC
1112

1213
-- import qualified Streamly.Data.Array as A
1314
import qualified Streamly.Internal.Data.Array as A
1415

16+
type Stream :: Type -> Type
1517
type Stream = A.Array
1618

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

benchmark/Streamly/Benchmark/Data/MutArray.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import Control.DeepSeq (NFData(..))
2323
import Control.Monad.IO.Class (MonadIO)
2424
import Data.Functor ((<&>))
25+
import Data.Kind (Type)
2526
import System.Random (randomRIO)
2627
import Prelude
2728
( IO
@@ -52,6 +53,7 @@ import qualified Streamly.Internal.Data.Stream as Stream
5253
import Test.Tasty.Bench
5354
import Streamly.Benchmark.Common hiding (benchPureSrc)
5455

56+
type Stream :: Type -> Type
5557
type Stream = MutArray
5658

5759
instance NFData (MutArray a) where

benchmark/streamly-benchmarks.cabal

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ flag use-prelude
6969
-------------------------------------------------------------------------------
7070

7171
common default-extensions
72+
-- GHC2024 may include more extensions than we are actually using, see the
73+
-- full list below. We enable this to ensure that we are able to compile
74+
-- with this i.e. there is no interference by other extensions.
75+
if impl(ghc >= 9.10)
76+
default-extensions:
77+
GHC2024
78+
79+
if impl(ghc >= 9.2) && impl(ghc < 9.10)
80+
default-extensions:
81+
GHC2021
82+
7283
default-extensions:
7384
BangPatterns
7485
CApiFFI

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: 19 additions & 1 deletion
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
@@ -969,7 +970,7 @@ data Fused3 a b c = Fused3 !a !b !c
969970
-- /Pre-release/
970971
--
971972
{-# INLINE splitMany #-}
972-
splitMany :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
973+
splitMany :: forall m a b c. Monad m => Parser a m b -> Fold m b c -> Parser a m c
973974
splitMany (Parser step1 initial1 extract1) (Fold fstep finitial _ ffinal) =
974975
Parser step initial extract
975976

@@ -978,6 +979,22 @@ splitMany (Parser step1 initial1 extract1) (Fold fstep finitial _ ffinal) =
978979
-- Caution! There is mutual recursion here, inlining the right functions is
979980
-- important.
980981

982+
{-
983+
iHandleCollect partial done fres =
984+
case fres of
985+
FL.Partial fs -> do
986+
pres <- initial1
987+
case pres of
988+
IPartial ps -> return $ partial $ Fused3 ps 0 fs
989+
IDone pb ->
990+
iRunCollectorWith (iHandleCollect partial done) fs pb
991+
IError _ -> done <$> ffinal fs
992+
FL.Done fb -> return $ done fb
993+
iRunCollectorWith cont fs pb = fstep fs pb >>= cont
994+
-}
995+
996+
-- XXX A copy of the code above. polymorphism does not work with
997+
-- MonoLocalBinds.
981998
handleCollect partial done fres =
982999
case fres of
9831000
FL.Partial fs -> do
@@ -993,6 +1010,7 @@ splitMany (Parser step1 initial1 extract1) (Fold fstep finitial _ ffinal) =
9931010

9941011
-- See notes in Fold.many for the reason why the parser must be initialized
9951012
-- right away instead of on first input.
1013+
-- initial = finitial >>= iHandleCollect IPartial IDone
9961014
initial = finitial >>= handleCollect IPartial IDone
9971015

9981016
{-# INLINE step #-}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ 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+
import Data.Kind (Type)
167168
import Data.Maybe (fromMaybe)
168169
import Data.Semigroup (Endo(..))
169170
import GHC.Exts (IsList(..), IsString(..), oneShot)
@@ -233,12 +234,14 @@ mkStream
233234
mkStream = MkStream
234235

235236
-- | A terminal function that has no continuation to follow.
237+
type StopK :: (Type -> Type) -> Type
236238
type StopK m = forall r. m r -> m r
237239

238240
-- | A monadic continuation, it is a function that yields a value of type "a"
239241
-- and calls the argument (a -> m r) as a continuation with that value. We can
240242
-- also think of it as a callback with a handler (a -> m r). Category
241243
-- theorists call it a codensity type, a special type of right kan extension.
244+
type YieldK :: (Type -> Type) -> Type -> Type
242245
type YieldK m a = forall r. (a -> m r) -> m r
243246

244247
_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

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ where
121121
import Control.Exception (assert)
122122
import Control.Monad.IO.Class (MonadIO(..))
123123
import Data.Function ((&))
124+
import Data.Kind (Type)
124125
import Data.Maybe (isNothing, fromJust)
125126
import Data.Word (Word8)
126127
import Streamly.Internal.Data.Unbox (Unbox)
@@ -373,7 +374,7 @@ read = A.concat . readChunks
373374
-- | Write an 'Array' to a file handle.
374375
--
375376
{-# INLINABLE putChunk #-}
376-
putChunk :: MonadIO m => Handle -> Array a -> m ()
377+
putChunk :: forall m (a :: Type). MonadIO m => Handle -> Array a -> m ()
377378
putChunk _ arr | byteLength arr == 0 = return ()
378379
putChunk h arr = A.unsafePinnedAsPtr arr $ \ptr byteLen ->
379380
liftIO $ hPutBuf h ptr byteLen
@@ -392,7 +393,8 @@ putChunk h arr = A.unsafePinnedAsPtr arr $ \ptr byteLen ->
392393
-- >>> putChunks h = Stream.fold (Fold.drainBy (Handle.putChunk h))
393394
--
394395
{-# INLINE putChunks #-}
395-
putChunks :: MonadIO m => Handle -> Stream m (Array a) -> m ()
396+
putChunks :: forall m (a :: Type). MonadIO m =>
397+
Handle -> Stream m (Array a) -> m ()
396398
putChunks h = S.fold (FL.drainMapM (putChunk h))
397399

398400
-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
@@ -437,14 +439,14 @@ putBytes = putBytesWith defaultChunkSize
437439
-- writeChunks h = Fold.drainBy (Handle.putChunk h)
438440
--
439441
{-# INLINE writeChunks #-}
440-
writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
442+
writeChunks :: forall m (a :: Type). MonadIO m => Handle -> Fold m (Array a) ()
441443
writeChunks h = FL.drainMapM (putChunk h)
442444

443445
-- | Like writeChunks but uses the experimental 'Refold' API.
444446
--
445447
-- /Internal/
446448
{-# INLINE chunkWriter #-}
447-
chunkWriter :: MonadIO m => Refold m Handle (Array a) ()
449+
chunkWriter :: forall m (a :: Type). MonadIO m => Refold m Handle (Array a) ()
448450
chunkWriter = Refold.drainBy putChunk
449451

450452
-- | @writeChunksWith bufsize handle@ writes a stream of arrays

core/streamly-core.cabal

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ common compile-options
214214
cpp-options: -DUSE_UNLIFTIO
215215

216216
common default-extensions
217+
-- GHC2024 may include more extensions than we are actually using, see the
218+
-- full list below. We enable this to ensure that we are able to compile
219+
-- with this i.e. there is no interference by other extensions.
220+
if impl(ghc >= 9.10)
221+
default-extensions:
222+
GHC2024
223+
-- XXX Check performance with MonoLocalBinds
224+
-- NoMonoLocalBinds
225+
226+
if impl(ghc >= 9.2) && impl(ghc < 9.10)
227+
default-extensions:
228+
GHC2021
229+
230+
-- In GHC 2024
217231
default-extensions:
218232
BangPatterns
219233
ConstraintKinds
@@ -226,6 +240,7 @@ common default-extensions
226240
GeneralizedNewtypeDeriving
227241
InstanceSigs
228242
KindSignatures
243+
LambdaCase
229244
MultiParamTypeClasses
230245
RankNTypes
231246
ScopedTypeVariables
@@ -234,11 +249,10 @@ common default-extensions
234249
TypeApplications
235250
TypeOperators
236251

237-
-- Not GHC2021
252+
-- Not in GHC2024
238253
CApiFFI
239254
CPP
240255
DefaultSignatures
241-
LambdaCase
242256
MagicHash
243257
RecordWildCards
244258

src/Streamly/Internal/Data/Stream/Channel/Operations.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Control.Exception (fromException)
3333
import Control.Monad (when)
3434
import Control.Monad.Catch (throwM, MonadThrow)
3535
import Control.Monad.IO.Class (MonadIO(liftIO))
36+
import Data.Kind (Type)
3637
import Data.IORef (newIORef, readIORef, mkWeakIORef, writeIORef)
3738
import Data.Maybe (isNothing)
3839
import Streamly.Internal.Control.Concurrent
@@ -262,6 +263,7 @@ fromChannelK chan =
262263
fromChannel :: MonadAsync m => Channel m a -> Stream m a
263264
fromChannel = Stream.fromStreamK . fromChannelK
264265

266+
type FromSVarState :: Type -> (Type -> Type) -> Type -> Type
265267
data FromSVarState t m a =
266268
FromSVarInit
267269
| FromSVarRead (Channel m a)

0 commit comments

Comments
 (0)