Skip to content
Merged
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
41 changes: 33 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ jobs:
matrix:
include:
# Linux
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.2.8" }
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.4.8" }
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.6.7" }
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.8.4" }
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.10.2" }
- { cabal: "3.14", os: ubuntu-latest, ghc: "9.12.2" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.2.8" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.4.8" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.6.7" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.8.4" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.10.2" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.12.2" }
- { cabal: "3.16", os: ubuntu-latest, ghc: "9.14.1" }
fail-fast: false

steps:
Expand Down Expand Up @@ -63,12 +64,36 @@ jobs:
mkdir sdist
for nm in fixed-vector*; do cabal sdist $nm -o sdist; done
- name: Unpack
# NOTE: For time being aeson is not buildable with GHC9.14.
# See: https://github.com/haskell/aeson/issues/1155
# NOTE: same for cborg
# See: https://github.com/well-typed/cborg/issues/373
run: |
mkdir unpacked
for nm in sdist/*; do tar -C unpacked -xf $nm; done
cd unpacked
echo "packages: */*.cabal" > cabal.project
echo "tests: true" >> cabal.project
echo "packages:" > cabal.project
echo " fixed-vector-*/*.cabal" >> cabal.project
if [ {{ matrix.ghc }} != 9.14.1 ]; then
echo " fixed-vector-aeson-*/*.cabal" >> cabal.project;
else
rm -rf fixed-vector-aeson-*
fi
echo " fixed-vector-binary-*/*.cabal" >> cabal.project
if [ {{ matrix.ghc }} != 9.14.1 ]; then
echo " fixed-vector-cborg-*/*.cabal" >> cabal.project
else
rm -rf fixed-vector-cborg-*
fi
echo " fixed-vector-cereal-*/*.cabal" >> cabal.project
echo " fixed-vector-QC-*/*.cabal" >> cabal.project
if [ {{ matrix.ghc }} != 9.14.1 ]; then
echo " fixed-vector-test-*/*.cabal" >> cabal.project;
else
rm -rf fixed-vector-test-*
fi
echo "tests: true" >> cabal.project
cat cabal.project
# ----------------
- name: cabal check
run: |
Expand Down
3 changes: 3 additions & 0 deletions fixed-vector-QC/Data/Vector/Fixed/Instances/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import qualified Data.Vector.Fixed.Strict as FF
import qualified Data.Vector.Fixed.Unboxed as FU
import qualified Data.Vector.Fixed.Primitive as FP
import qualified Data.Vector.Fixed.Storable as FS
import qualified Data.Vector.Fixed.Mono as FM
import Test.QuickCheck


instance (Vector v a, Arbitrary a) => Arbitrary (ViaFixed v a) where
arbitrary = F.replicateM arbitrary
instance (FM.Prod a v, Arbitrary a) => Arbitrary (FM.ViaFixed a v) where
arbitrary = FM.replicateM arbitrary


deriving via ViaFixed (FB.Vec n) a instance (Arity n, Arbitrary a) => Arbitrary (FB.Vec n a)
Expand Down
15 changes: 7 additions & 8 deletions fixed-vector-QC/fixed-vector-QC.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ extra-source-files:
ChangeLog.md

tested-with:
GHC ==8.10.7
|| ==9.0.1
|| ==9.2.8
|| ==9.4.7
|| ==9.6.6
|| ==9.8.2
|| ==9.10.1
GHC ==9.4.7
|| ==9.6.7
|| ==9.8.4
|| ==9.10.2
|| ==9.12.2
|| ==9.14.1

source-repository head
type: git
Expand All @@ -32,7 +31,7 @@ source-repository head
Library
Ghc-options: -Wall
Default-Language: Haskell2010
Build-Depends: base >=4.14 && <5
Build-Depends: base >=4.16 && <5
, fixed-vector >=2.0
, QuickCheck >=2.13
Exposed-modules:
Expand Down
30 changes: 22 additions & 8 deletions fixed-vector-aeson/Data/Vector/Fixed/Instances/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
Expand All @@ -22,8 +23,10 @@ import qualified Data.Vector.Fixed.Strict as FF
import qualified Data.Vector.Fixed.Unboxed as FU
import qualified Data.Vector.Fixed.Primitive as FP
import qualified Data.Vector.Fixed.Storable as FS
import qualified Data.Vector.Fixed.Mono as FM
import Data.Aeson
import Data.Aeson.Types
import Data.Coerce

import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
Expand All @@ -35,48 +38,59 @@ import qualified Data.Vector.Mutable as MV

-- | Generic implementation of 'parseJSON' for data types which are
-- instances of 'Vector'.
fixedVectorParseJSON :: forall v a. (Vector v a, FromJSON a) => Value -> Parser (v a)
fixedVectorParseJSON :: forall v a. (FM.Prod a v, FromJSON a) => Value -> Parser v
{-# INLINE fixedVectorParseJSON #-}
fixedVectorParseJSON = withArray "fixed-vector" $ \arr -> do
let expected = F.length (undefined :: v a)
let expected = FM.length (undefined :: v)
when (V.length arr /= expected) $
fail $ "Expecting array of length " ++ show expected
F.generateM $ \i -> parseJSON (arr V.! i)
coerce $ FM.generateM @(FM.ViaFixed a v) $ \i -> parseJSON (arr V.! i)

-- | Generic implementation of 'toJSON' for data types which are
-- instances of 'Vector'.
fixedVectorToJSON :: forall v a. (Vector v a, ToJSON a) => v a -> Value
fixedVectorToJSON :: forall v a. (FM.Prod a v, ToJSON a) => v -> Value
{-# INLINE fixedVectorToJSON #-}
fixedVectorToJSON v = Array $ runST $ do
-- NOTE: (!) from fixed vector could have O(n) complexity so let
-- fold over fixed vector. Access to vector _is_ O(1)
vec <- MV.unsafeNew n
flip F.imapM_ v $ \i a -> MV.unsafeWrite vec i (toJSON a)
flip FM.imapM_ (FM.ViaFixed v) $ \i a -> MV.unsafeWrite vec i (toJSON a)
V.unsafeFreeze vec
where
n = F.length v
n = FM.length v

-- | Generic implementation of 'toEncoding' for data types which are
-- instances of 'Vector'.
fixedVectorToEncoding :: forall v a. (Vector v a, ToJSON a) => v a -> Encoding
fixedVectorToEncoding :: forall v a. (FM.Prod a v, ToJSON a) => v -> Encoding
{-# INLINE fixedVectorToEncoding #-}
fixedVectorToEncoding = foldable . F.cvec
fixedVectorToEncoding = foldable . FM.cvec


----------------------------------------------------------------
-- Instances
----------------------------------------------------------------

instance (Vector v a, FromJSON a) => FromJSON (ViaFixed v a) where
parseJSON = fixedVectorParseJSON
{-# INLINE parseJSON #-}

instance (FM.Prod a v, FromJSON a) => FromJSON (FM.ViaFixed a v) where
parseJSON = fixedVectorParseJSON
{-# INLINE parseJSON #-}


instance (Vector v a, ToJSON a) => ToJSON (ViaFixed v a) where
toJSON = fixedVectorToJSON
toEncoding = fixedVectorToEncoding
{-# INLINE toJSON #-}
{-# INLINE toEncoding #-}

instance (FM.Prod a v, ToJSON a) => ToJSON (FM.ViaFixed a v) where
toJSON = fixedVectorToJSON
toEncoding = fixedVectorToEncoding
{-# INLINE toJSON #-}
{-# INLINE toEncoding #-}



deriving via ViaFixed (FB.Vec n) a instance (Arity n, FromJSON a) => FromJSON (FB.Vec n a)
Expand Down
15 changes: 7 additions & 8 deletions fixed-vector-aeson/fixed-vector-aeson.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ extra-source-files:
ChangeLog.md

tested-with:
GHC ==8.10.7
|| ==9.0.1
|| ==9.2.8
|| ==9.4.7
|| ==9.6.6
|| ==9.8.2
|| ==9.10.1
GHC ==9.4.7
|| ==9.6.7
|| ==9.8.4
|| ==9.10.2
|| ==9.12.2
|| ==9.14.1

source-repository head
type: git
Expand All @@ -32,7 +31,7 @@ source-repository head
Library
Ghc-options: -Wall
Default-Language: Haskell2010
Build-Depends: base >=4.14 && <5
Build-Depends: base >=4.16 && <5
, fixed-vector >=2.0
, aeson >=2
, vector
Expand Down
7 changes: 7 additions & 0 deletions fixed-vector-binary/Data/Vector/Fixed/Instances/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Data.Vector.Fixed.Strict as FF
import qualified Data.Vector.Fixed.Unboxed as FU
import qualified Data.Vector.Fixed.Primitive as FP
import qualified Data.Vector.Fixed.Storable as FS
import qualified Data.Vector.Fixed.Mono as FM
import Data.Binary (Binary(..))

instance (Vector v a, Binary a) => Binary (ViaFixed v a) where
Expand All @@ -23,6 +24,12 @@ instance (Vector v a, Binary a) => Binary (ViaFixed v a) where
{-# INLINE put #-}
{-# INLINE get #-}

instance (FM.Prod a v, Binary a) => Binary (FM.ViaFixed a v) where
put = FM.mapM_ put
get = FM.replicateM get
{-# INLINE put #-}
{-# INLINE get #-}

deriving via ViaFixed (FB.Vec n) a instance (Arity n, Binary a) => Binary (FB.Vec n a)
deriving via ViaFixed (FF.Vec n) a instance (Arity n, Binary a) => Binary (FF.Vec n a)
deriving via ViaFixed (FP.Vec n) a instance (Arity n, Binary a, FP.Prim a) => Binary (FP.Vec n a)
Expand Down
15 changes: 7 additions & 8 deletions fixed-vector-binary/fixed-vector-binary.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ extra-source-files:
ChangeLog.md

tested-with:
GHC ==8.10.7
|| ==9.0.1
|| ==9.2.8
|| ==9.4.7
|| ==9.6.6
|| ==9.8.2
|| ==9.10.1
GHC ==9.4.7
|| ==9.6.7
|| ==9.8.4
|| ==9.10.2
|| ==9.12.2
|| ==9.14.1

source-repository head
type: git
Expand All @@ -32,7 +31,7 @@ source-repository head
Library
Ghc-options: -Wall
Default-Language: Haskell2010
Build-Depends: base >=4.14 && <5
Build-Depends: base >=4.16 && <5
, fixed-vector >=2.0
, binary
Exposed-modules:
Expand Down
20 changes: 14 additions & 6 deletions fixed-vector-cborg/Data/Vector/Fixed/Instances/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ import qualified Data.Vector.Fixed.Strict as FF
import qualified Data.Vector.Fixed.Unboxed as FU
import qualified Data.Vector.Fixed.Primitive as FP
import qualified Data.Vector.Fixed.Storable as FS

import qualified Data.Vector.Fixed.Mono as FM
import Data.Coerce

instance (Vector v a, Serialise a) => Serialise (ViaFixed v a) where
encode = encodeFixedVector
decode = decodeFixedVector
{-# INLINE encode #-}
{-# INLINE decode #-}

instance (FM.Prod a v, Serialise a) => Serialise (FM.ViaFixed a v) where
encode = encodeFixedVector
decode = decodeFixedVector
{-# INLINE encode #-}
{-# INLINE decode #-}

deriving via ViaFixed (FB.Vec n) a instance (Arity n, Serialise a) => Serialise (FB.Vec n a)
deriving via ViaFixed (FF.Vec n) a instance (Arity n, Serialise a) => Serialise (FF.Vec n a)
deriving via ViaFixed (FP.Vec n) a instance (Arity n, Serialise a, FP.Prim a) => Serialise (FP.Vec n a)
Expand All @@ -49,15 +56,16 @@ instance Serialise (F.Empty a) where

-- | Encode vector with statically known size as CBOR list. There's no
-- type tag
encodeFixedVector :: (F.Vector v a, Serialise a) => v a -> Encoding
encodeFixedVector :: (FM.Prod a v, Serialise a) => v -> Encoding
{-# INLINE encodeFixedVector #-}
encodeFixedVector v = encodeListLen (fromIntegral $ F.length v)
<> F.foldMap encode v
encodeFixedVector v
= encodeListLen (fromIntegral $ FM.length v)
<> FM.foldMap encode (FM.ViaFixed v)

-- | Decode vector with statically known size as CBOR list. There's no
-- type tag
decodeFixedVector :: forall v s a. (F.Vector v a, Serialise a) => Decoder s (v a)
decodeFixedVector :: forall v s a. (FM.Prod a v, Serialise a) => Decoder s v
{-# INLINE decodeFixedVector #-}
decodeFixedVector = do
decodeListLenOf (fromIntegral $ peanoToInt (proxy# @(Dim v)))
F.replicateM decode
coerce $ FM.replicateM @(FM.ViaFixed a v) decode
15 changes: 7 additions & 8 deletions fixed-vector-cborg/fixed-vector-cborg.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ extra-source-files:
ChangeLog.md

tested-with:
GHC ==8.10.7
|| ==9.0.1
|| ==9.2.8
|| ==9.4.7
|| ==9.6.6
|| ==9.8.2
|| ==9.10.1
GHC ==9.4.7
|| ==9.6.7
|| ==9.8.4
|| ==9.10.2
|| ==9.12.2
|| ==9.14.1

source-repository head
type: git
Expand All @@ -32,7 +31,7 @@ source-repository head
Library
Ghc-options: -Wall
Default-Language: Haskell2010
Build-Depends: base >=4.14 && <5
Build-Depends: base >=4.16 && <5
, fixed-vector >=2.0
, cborg
, serialise
Expand Down
7 changes: 7 additions & 0 deletions fixed-vector-cereal/Data/Vector/Fixed/Instances/Cereal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Data.Vector.Fixed.Strict as FF
import qualified Data.Vector.Fixed.Unboxed as FU
import qualified Data.Vector.Fixed.Primitive as FP
import qualified Data.Vector.Fixed.Storable as FS
import qualified Data.Vector.Fixed.Mono as FM
import Data.Serialize (Serialize(..))


Expand All @@ -24,6 +25,12 @@ instance (Vector v a, Serialize a) => Serialize (ViaFixed v a) where
{-# INLINE put #-}
{-# INLINE get #-}

instance (FM.Prod a v, Serialize a) => Serialize (FM.ViaFixed a v) where
put = FM.mapM_ put
get = FM.replicateM get
{-# INLINE put #-}
{-# INLINE get #-}

deriving via ViaFixed (FB.Vec n) a instance (Arity n, Serialize a) => Serialize (FB.Vec n a)
deriving via ViaFixed (FF.Vec n) a instance (Arity n, Serialize a) => Serialize (FF.Vec n a)
deriving via ViaFixed (FP.Vec n) a instance (Arity n, Serialize a, FP.Prim a) => Serialize (FP.Vec n a)
Expand Down
15 changes: 7 additions & 8 deletions fixed-vector-cereal/fixed-vector-cereal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ extra-source-files:
ChangeLog.md

tested-with:
GHC ==8.10.7
|| ==9.0.1
|| ==9.2.8
|| ==9.4.7
|| ==9.6.6
|| ==9.8.2
|| ==9.10.1
GHC ==9.4.7
|| ==9.6.7
|| ==9.8.4
|| ==9.10.2
|| ==9.12.2
|| ==9.14.1

source-repository head
type: git
Expand All @@ -32,7 +31,7 @@ source-repository head
Library
Ghc-options: -Wall
Default-Language: Haskell2010
Build-Depends: base >=4.14 && <5
Build-Depends: base >=4.16 && <5
, fixed-vector >=2.0
, cereal
Exposed-modules:
Expand Down
Loading
Loading