From b9e13b0dbde5e91261333c808b408c77e7be7141 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Mon, 20 Mar 2023 12:36:23 +0100 Subject: [PATCH 1/2] Distinguish between IO and pure functions --- src/Foreign/Rust/Marshall/Variable.hs | 45 ++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Foreign/Rust/Marshall/Variable.hs b/src/Foreign/Rust/Marshall/Variable.hs index 25e8465..a84b591 100644 --- a/src/Foreign/Rust/Marshall/Variable.hs +++ b/src/Foreign/Rust/Marshall/Variable.hs @@ -13,6 +13,10 @@ module Foreign.Rust.Marshall.Variable ( , withBorshVarBuffer , withBorshMaxBuffer , withBorshFailure + -- ** Pure variants + , withPureBorshVarBuffer + , withPureBorshMaxBuffer + , withPureBorshFailure ) where import Codec.Borsh @@ -66,7 +70,7 @@ withBorshVarBuffer :: forall a. , StaticBorshSize a ~ 'HasVariableSize , Typeable a ) - => (Buffer a -> IO ()) -> a + => (Buffer a -> IO ()) -> IO a withBorshVarBuffer = withBorshBufferOfInitSize 1024 withBorshMaxBuffer :: forall a. @@ -75,7 +79,7 @@ withBorshMaxBuffer :: forall a. , BorshMaxSize a , Typeable a ) - => (Buffer a -> IO ()) -> a + => (Buffer a -> IO ()) -> IO a withBorshMaxBuffer = withBorshBufferOfInitSize initBufSize where @@ -89,8 +93,39 @@ withBorshFailure :: forall a. , Typeable a , HasCallStack ) + => (Buffer (Either Text a) -> IO ()) -> IO (Either Failure a) +withBorshFailure = fmap (first mkFailure) . withBorshVarBuffer + +{------------------------------------------------------------------------------- + Pure variants +-------------------------------------------------------------------------------} + +withPureBorshVarBuffer :: forall a. + ( FromBorsh a + , StaticBorshSize a ~ 'HasVariableSize + , Typeable a + ) + => (Buffer a -> IO ()) -> a +withPureBorshVarBuffer = unsafePerformIO . withBorshVarBuffer + +withPureBorshMaxBuffer :: forall a. + ( FromBorsh a + , StaticBorshSize a ~ 'HasVariableSize + , BorshMaxSize a + , Typeable a + ) + => (Buffer a -> IO ()) -> a +withPureBorshMaxBuffer = unsafePerformIO . withBorshMaxBuffer + +withPureBorshFailure :: forall a. + ( FromBorsh a + , StaticBorshSize a ~ 'HasVariableSize + , Typeable a + , HasCallStack + ) => (Buffer (Either Text a) -> IO ()) -> Either Failure a -withBorshFailure = first mkFailure . withBorshVarBuffer +withPureBorshFailure = unsafePerformIO . withBorshFailure + {------------------------------------------------------------------------------- Internal auxiliary @@ -102,8 +137,8 @@ withBorshBufferOfInitSize :: forall a. , StaticBorshSize a ~ 'HasVariableSize , Typeable a ) - => CULong -> (Buffer a -> IO ()) -> a -withBorshBufferOfInitSize initBufSize f = unsafePerformIO $ do + => CULong -> (Buffer a -> IO ()) -> IO a +withBorshBufferOfInitSize initBufSize f = do mFirstAttempt <- allocaBytes (culongToInt initBufSize) $ \buf -> do (bigEnough, reqSz) <- callWithSize buf initBufSize if bigEnough then From ebb6549319fa3bafb3003161b5d0aa065f54a8fb Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Mon, 20 Mar 2023 13:29:53 +0100 Subject: [PATCH 2/2] Disable cabal check --- .github/workflows/haskell-ci.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index aa75ac9..cfe996c 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -1,6 +1,6 @@ # This GitHub workflow config has been generated by a script via # -# haskell-ci 'github' 'cabal.project' +# haskell-ci 'github' '--no-cabal-check' 'cabal.project' # # To regenerate the script (for example after adjusting tested-with) run # @@ -10,7 +10,7 @@ # # version: 0.15.20230312 # -# REGENDATA ("0.15.20230312",["github","cabal.project"]) +# REGENDATA ("0.15.20230312",["github","--no-cabal-check","cabal.project"]) # name: Haskell-CI on: @@ -214,10 +214,6 @@ jobs: - name: tests run: | $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct - - name: cabal check - run: | - cd ${PKGDIR_foreign_rust} || false - ${CABAL} -vnormal check - name: haddock run: | $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all