Skip to content

Bump io-classes version #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ jobs:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ env.CABAL_VERSION }}

- name: Install LLVM (macOS)
if: runner.os == 'macOS'
run: |
brew install llvm@13
echo "LLVM_CONFIG=$(brew --prefix llvm@13)/bin/llvm-config" >> $GITHUB_ENV
echo "$(brew --prefix llvm@13)/bin" >> $GITHUB_PATH

- name: Verify LLVM installation
if: runner.os == 'macOS'
run: |
llvm-config --version
opt --version

- name: Print environment variables
if: runner.os == 'macOS'
run: |
echo "PATH = $PATH"
echo "LLVM_CONFIG = $LLVM_CONFIG"

- uses: actions/checkout@v3

- name: "Configure cabal.project.local"
Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repository cardano-haskell-packages
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee

index-state:
hackage.haskell.org 2024-02-06T12:00:00Z
, cardano-haskell-packages 2023-05-16T03:39:10Z
hackage.haskell.org 2024-05-20T10:04:11Z
, cardano-haskell-packages 2024-05-15T19:28:23Z


packages: ./typed-protocols
Expand Down
35 changes: 16 additions & 19 deletions typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Network.TypedProtocol.Codec.CBOR
) where

import Control.Monad.Class.MonadST (MonadST (..))
import Control.Monad.ST

import qualified Codec.CBOR.Decoding as CBOR (Decoder)
import qualified Codec.CBOR.Encoding as CBOR (Encoding)
Expand All @@ -23,6 +22,7 @@ import qualified Data.ByteString.Builder.Extra as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Lazy.Internal as LBS (smallChunkSize)

import Control.Monad.Primitive (PrimMonad (..))
import Network.TypedProtocol.Codec
import Network.TypedProtocol.Core

Expand Down Expand Up @@ -67,24 +67,22 @@ mkCodecCborStrictBS cborMsgEncode cborMsgDecode =
convertCborDecoder
:: (forall s. CBOR.Decoder s a)
-> m (DecodeStep BS.ByteString DeserialiseFailure m a)
convertCborDecoder cborDecode =
withLiftST (convertCborDecoderBS cborDecode)
convertCborDecoder = convertCborDecoderBS

convertCborDecoderBS
:: forall s m a. Functor m
=> (CBOR.Decoder s a)
-> (forall b. ST s b -> m b)
:: forall m a. MonadST m
=> CBOR.Decoder (PrimState m) a
-> m (DecodeStep BS.ByteString DeserialiseFailure m a)
convertCborDecoderBS cborDecode liftST =
go <$> liftST (CBOR.deserialiseIncremental cborDecode)
convertCborDecoderBS cborDecode =
go <$> stToIO (CBOR.deserialiseIncremental cborDecode)
where
go :: CBOR.IDecode s a
go :: CBOR.IDecode (PrimState m) a
-> DecodeStep BS.ByteString DeserialiseFailure m a
go (CBOR.Done trailing _ x)
| BS.null trailing = DecodeDone x Nothing
| otherwise = DecodeDone x (Just trailing)
go (CBOR.Fail _ _ failure) = DecodeFail failure
go (CBOR.Partial k) = DecodePartial (fmap go . liftST . k)
go (CBOR.Partial k) = DecodePartial (fmap go . stToIO . k)


-- | Construct a 'Codec' for a CBOR based serialisation format, using lazy
Expand Down Expand Up @@ -123,19 +121,18 @@ mkCodecCborLazyBS cborMsgEncode cborMsgDecode =
:: (forall s. CBOR.Decoder s a)
-> m (DecodeStep LBS.ByteString CBOR.DeserialiseFailure m a)
convertCborDecoder cborDecode =
withLiftST (convertCborDecoderLBS cborDecode)
convertCborDecoderLBS cborDecode

convertCborDecoderLBS
:: forall s m a. Monad m
=> (CBOR.Decoder s a)
-> (forall b. ST s b -> m b)
:: forall m a. MonadST m
=> CBOR.Decoder (PrimState m) a
-> m (DecodeStep LBS.ByteString CBOR.DeserialiseFailure m a)
convertCborDecoderLBS cborDecode liftST =
go [] =<< liftST (CBOR.deserialiseIncremental cborDecode)
convertCborDecoderLBS cborDecode =
go [] =<< stToIO (CBOR.deserialiseIncremental cborDecode)
where
-- Have to mediate between a CBOR decoder that consumes strict bytestrings
-- and our choice here that consumes lazy bytestrings.
go :: [BS.ByteString] -> CBOR.IDecode s a
go :: [BS.ByteString] -> CBOR.IDecode (PrimState m) a
-> m (DecodeStep LBS.ByteString CBOR.DeserialiseFailure m a)
go [] (CBOR.Done trailing _ x)
| BS.null trailing = return (DecodeDone x Nothing)
Expand All @@ -147,9 +144,9 @@ convertCborDecoderLBS cborDecode liftST =

-- We keep a bunch of chunks and supply the CBOR decoder with them
-- until we run out, when we go get another bunch.
go (c:cs) (CBOR.Partial k) = go cs =<< liftST (k (Just c))
go (c:cs) (CBOR.Partial k) = go cs =<< stToIO (k (Just c))
go [] (CBOR.Partial k) = return $ DecodePartial $ \mbs -> case mbs of
Nothing -> go [] =<< liftST (k Nothing)
Nothing -> go [] =<< stToIO (k Nothing)
Just bs -> go cs (CBOR.Partial k)
where cs = LBS.toChunks bs

Expand Down
6 changes: 4 additions & 2 deletions typed-protocols-cborg/typed-protocols-cborg.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: typed-protocols-cborg
version: 0.1.0.4
version: 0.1.0.5
synopsis: CBOR codecs for typed-protocols
-- description:
license: Apache-2.0
Expand All @@ -22,8 +22,10 @@ library
bytestring >=0.10 && <0.13,
cborg >=0.2.1 && <0.3,

io-sim,
io-classes,
typed-protocols
typed-protocols,
primitive

hs-source-dirs: src
default-language: Haskell2010
Expand Down
2 changes: 2 additions & 0 deletions typed-protocols-doc/demo/DemoProtocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -Wno-redundant-constraints #-}

module DemoProtocol
where

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ pMainOptions =
)


defaultMain :: ( Codec codec
, HasInfo codec (DefEnumEncoding codec)
defaultMain :: ( HasInfo codec (DefEnumEncoding codec)
, HasInfo codec Word32
) => [ProtocolDescription codec] -> IO ()
) =>[ProtocolDescription codec] -> IO ()
defaultMain descriptions = do
mainOptions <- execParser $ info (pMainOptions <**> helper) fullDesc
if moListProtocols mainOptions then do
Expand All @@ -79,11 +78,10 @@ defaultMain descriptions = do
render = getRenderer (moOutputFormat mainOptions) (moOutputFile mainOptions)
write . render $ descriptions

getRenderer :: ( Codec codec
, HasInfo codec (DefEnumEncoding codec)
getRenderer :: ( HasInfo codec (DefEnumEncoding codec)
, HasInfo codec Word32
)
=> OutputFormat
=>OutputFormat
-> Maybe FilePath
-> [ProtocolDescription codec]
-> String
Expand All @@ -105,4 +103,4 @@ getRenderer OutputJSON _ =
abort :: String -> a
abort msg = unsafePerformIO $ do
hPutStrLn stderr msg
exitFailure
exitFailure
2 changes: 1 addition & 1 deletion typed-protocols/typed-protocols.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ library
, TypeOperators
, BangPatterns
build-depends: base,
io-classes >= 1.0 && < 1.4
io-classes >= 1.4.1 && < 1.6

hs-source-dirs: src
default-language: Haskell2010
Expand Down
Loading