diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index a57b3c5d..3fafa5fc 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -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" diff --git a/cabal.project b/cabal.project index ea7f328c..6bf2aa71 100644 --- a/cabal.project +++ b/cabal.project @@ -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 diff --git a/typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs b/typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs index 22d1721e..790131ab 100644 --- a/typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs +++ b/typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/typed-protocols-cborg/typed-protocols-cborg.cabal b/typed-protocols-cborg/typed-protocols-cborg.cabal index 2ed32bd1..871edc21 100644 --- a/typed-protocols-cborg/typed-protocols-cborg.cabal +++ b/typed-protocols-cborg/typed-protocols-cborg.cabal @@ -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 @@ -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 diff --git a/typed-protocols-doc/demo/DemoProtocol.hs b/typed-protocols-doc/demo/DemoProtocol.hs index a408cf13..303b11ad 100644 --- a/typed-protocols-doc/demo/DemoProtocol.hs +++ b/typed-protocols-doc/demo/DemoProtocol.hs @@ -12,6 +12,8 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -Wno-redundant-constraints #-} + module DemoProtocol where diff --git a/typed-protocols-doc/src/Network/TypedProtocol/Documentation/DefaultMain.hs b/typed-protocols-doc/src/Network/TypedProtocol/Documentation/DefaultMain.hs index b293094d..02ad81dd 100644 --- a/typed-protocols-doc/src/Network/TypedProtocol/Documentation/DefaultMain.hs +++ b/typed-protocols-doc/src/Network/TypedProtocol/Documentation/DefaultMain.hs @@ -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 @@ -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 @@ -105,4 +103,4 @@ getRenderer OutputJSON _ = abort :: String -> a abort msg = unsafePerformIO $ do hPutStrLn stderr msg - exitFailure + exitFailure diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index 1d92114d..56e7ac2b 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -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