Z-Data 0.1.3.1 → 0.1.4.0
raw patch · 19 files changed
+73/−39 lines, 19 filesdep ~ghc-primdep ~template-haskellsetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghc-prim, template-haskell
API changes (from Hackage documentation)
- Z.Data.Array.UnalignedAccess: instance GHC.Classes.Eq (Z.Data.Array.UnalignedAccess.UnalignedSize a)
- Z.Data.Array.UnalignedAccess: instance GHC.Show.Show (Z.Data.Array.UnalignedAccess.UnalignedSize a)
- Z.Data.Builder.Base: instance (a GHC.Types.~ ()) => Data.String.IsString (Z.Data.Builder.Base.Builder a)
- Z.Data.JSON.Base: instance (Z.Data.Generics.Utils.ProductSize a, Z.Data.JSON.Base.GFromFields a, Z.Data.JSON.Base.GFromFields b, Z.Data.JSON.Base.LookupTable a GHC.Types.~ Z.Data.JSON.Base.LookupTable b) => Z.Data.JSON.Base.GFromFields (a GHC.Generics.:*: b)
- Z.Data.JSON.Base: instance (Z.Data.Generics.Utils.ProductSize a, Z.Data.JSON.Base.GWriteFields a, Z.Data.JSON.Base.GWriteFields b, Z.Data.JSON.Base.Field a GHC.Types.~ Z.Data.JSON.Base.Field b) => Z.Data.JSON.Base.GWriteFields (a GHC.Generics.:*: b)
- Z.Data.Text.Builder: instance (a GHC.Types.~ ()) => Data.String.IsString (Z.Data.Text.Builder.TextBuilder a)
- Z.Data.Vector: [getDown] :: Down a -> a
- Z.Data.Vector.Base: instance (a GHC.Types.~ GHC.Word.Word8) => Data.String.IsString (Z.Data.Vector.Base.PrimVector a)
- Z.Data.Vector.Sort: [getDown] :: Down a -> a
+ Z.Data.Array.UnalignedAccess: instance forall k (a :: k). GHC.Classes.Eq (Z.Data.Array.UnalignedAccess.UnalignedSize a)
+ Z.Data.Array.UnalignedAccess: instance forall k (a :: k). GHC.Show.Show (Z.Data.Array.UnalignedAccess.UnalignedSize a)
+ Z.Data.Builder.Base: instance (a Data.Type.Equality.~ ()) => Data.String.IsString (Z.Data.Builder.Base.Builder a)
+ Z.Data.JSON.Base: instance (Z.Data.Generics.Utils.ProductSize a, Z.Data.JSON.Base.GFromFields a, Z.Data.JSON.Base.GFromFields b, Z.Data.JSON.Base.LookupTable a Data.Type.Equality.~ Z.Data.JSON.Base.LookupTable b) => Z.Data.JSON.Base.GFromFields (a GHC.Generics.:*: b)
+ Z.Data.JSON.Base: instance (Z.Data.Generics.Utils.ProductSize a, Z.Data.JSON.Base.GWriteFields a, Z.Data.JSON.Base.GWriteFields b, Z.Data.JSON.Base.Field a Data.Type.Equality.~ Z.Data.JSON.Base.Field b) => Z.Data.JSON.Base.GWriteFields (a GHC.Generics.:*: b)
+ Z.Data.Parser: fail' :: Text -> Parser a
+ Z.Data.Parser.Base: fail' :: Text -> Parser a
+ Z.Data.Text.Builder: instance (a Data.Type.Equality.~ ()) => Data.String.IsString (Z.Data.Text.Builder.TextBuilder a)
+ Z.Data.Vector.Base: instance (a Data.Type.Equality.~ GHC.Word.Word8) => Data.String.IsString (Z.Data.Vector.Base.PrimVector a)
+ Z.Foreign: pinPrimArray :: Prim a => PrimArray a -> IO (PrimArray a)
+ Z.Foreign: pinPrimVector :: Prim a => PrimVector a -> IO (PrimVector a)
- Z.Data.Array: data RealWorld
+ Z.Data.Array: data RealWorld :: Type
- Z.Data.Array: isMutablePrimArrayPinned :: MutablePrimArray s a -> Bool
+ Z.Data.Array: isMutablePrimArrayPinned :: () => MutablePrimArray s a -> Bool
- Z.Data.Array: isPrimArrayPinned :: PrimArray a -> Bool
+ Z.Data.Array: isPrimArrayPinned :: () => PrimArray a -> Bool
- Z.Data.Array: mutablePrimArrayContents :: MutablePrimArray s a -> Ptr a
+ Z.Data.Array: mutablePrimArrayContents :: () => MutablePrimArray s a -> Ptr a
- Z.Data.Array: primArrayContents :: PrimArray a -> Ptr a
+ Z.Data.Array: primArrayContents :: () => PrimArray a -> Ptr a
- Z.Data.Array.Checked: data RealWorld
+ Z.Data.Array.Checked: data RealWorld :: Type
- Z.Data.Array.Checked: isMutablePrimArrayPinned :: MutablePrimArray s a -> Bool
+ Z.Data.Array.Checked: isMutablePrimArrayPinned :: () => MutablePrimArray s a -> Bool
- Z.Data.Array.Checked: isPrimArrayPinned :: PrimArray a -> Bool
+ Z.Data.Array.Checked: isPrimArrayPinned :: () => PrimArray a -> Bool
- Z.Data.Array.Checked: mutablePrimArrayContents :: MutablePrimArray s a -> Ptr a
+ Z.Data.Array.Checked: mutablePrimArrayContents :: () => MutablePrimArray s a -> Ptr a
- Z.Data.Array.Checked: primArrayContents :: PrimArray a -> Ptr a
+ Z.Data.Array.Checked: primArrayContents :: () => PrimArray a -> Ptr a
- Z.Foreign: castPtr :: Ptr a -> Ptr b
+ Z.Foreign: castPtr :: () => Ptr a -> Ptr b
Files
- ChangeLog.md +6/−0
- README.md +9/−4
- Setup.hs +2/−0
- Z-Data.cabal +6/−6
- Z/Data/Array.hs +6/−4
- Z/Data/Array/Cast.hs +1/−2
- Z/Data/Array/QQ.hs +1/−2
- Z/Data/Array/UnalignedAccess.hs +2/−2
- Z/Data/Builder/Base.hs +1/−3
- Z/Data/JSON/Builder.hs +0/−1
- Z/Data/JSON/Value.hs +2/−3
- Z/Data/Parser.hs +1/−1
- Z/Data/Parser/Base.hs +3/−2
- Z/Data/Parser/Numeric.hs +1/−1
- Z/Data/PrimRef/PrimIORef.hs +2/−3
- Z/Data/PrimRef/PrimSTRef.hs +1/−1
- Z/Data/Text/UTF8Codec.hs +1/−2
- Z/Data/Vector/Base.hs +1/−1
- Z/Foreign.hs +27/−1
ChangeLog.md view
@@ -1,5 +1,11 @@ # Revision history for Z-Data +## 0.1.4.0 -- 2020-09-24++* Make library works with GHC 8.6 and 8.8 again.+* Add `pinPrimVector` and `pinPrimArray` to `Z.Foreign`.+* Export `fail'` from `Z.Data.Parser`+ ## 0.1.3.1 -- 2020-09-24 * Change `clearMBA` 's type to match `clearPtr`.
README.md view
@@ -4,8 +4,10 @@ ## Z-Data -[](https://travis-ci.org/haskell-z/z-data)+[](https://github.com/haskell-Z/z-data/actions) +[](https://github.com/haskell-Z/z-data/actions)+ This package provides basic data structures and functions: * Array, vector(array slice)@@ -14,6 +16,12 @@ * Parsing and building monad * JSON encoding and decoding +## Requirements++* A working haskell compiler system, GHC(>=8.6), cabal-install(>=2.4), hsc2hs.++* Tests need [hspec-discover](https://hackage.haskell.org/package/hspec-discover).+ ## Example usage ```haskell@@ -72,9 +80,6 @@ ``` ## Dev guide--+ GHC(>=8.10.2) -+ cabal-install(>=3.4) ```bash # get code
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
Z-Data.cabal view
@@ -1,8 +1,9 @@+cabal-version: 2.4 name: Z-Data-version: 0.1.3.1+version: 0.1.4.0 synopsis: Array, vector and text description: This package provides array, slice and text operations-license: BSD3+license: BSD-3-Clause license-file: LICENSE author: Dong Han, Tao He maintainer: winterland1989@gmail.com@@ -10,7 +11,6 @@ (c) Tao He, 2017-2020 category: Data build-type: Simple-cabal-version: >=1.10 homepage: https://github.com/haskell-Z/z-data bug-reports: https://github.com/haskell-Z/z-data/issues @@ -111,14 +111,14 @@ Z.Foreign build-depends: base >= 4.12 && <5.0- , ghc-prim >= 0.6.1 && < 0.6.2+ , ghc-prim >= 0.5.3 && < 0.6.2 , primitive >= 0.7.1 && < 0.7.2 , scientific == 0.3.* , hashable == 1.3.* , case-insensitive == 1.2.* , deepseq >= 1.4 && < 1.5 , QuickCheck >= 2.10- , template-haskell == 2.16.*+ , template-haskell >= 2.14.0 , unordered-containers == 0.2.* , tagged == 0.8.* @@ -161,7 +161,7 @@ third_party/utf8rewind/source/utf8rewind.c default-language: Haskell2010- build-tools: hsc2hs, hspec-discover+ build-tool-depends: hsc2hs:hsc2hs, hspec-discover:hspec-discover cc-options: -march=native ghc-options: -Wall -Wno-unticked-promoted-constructors
Z/Data/Array.hs view
@@ -76,8 +76,7 @@ import Data.Primitive.Ptr (copyPtrToMutablePrimArray) import Data.Primitive.SmallArray import Data.Primitive.Types-import GHC.Prim-import GHC.Types+import GHC.Exts import Z.Data.Array.Cast import Z.Data.Array.UnliftedArray @@ -392,8 +391,11 @@ copySmallMutableArray marr' 0 marr 0 (sizeofSmallMutableArray marr) return marr' {-# INLINE resizeMutableArr #-}- shrinkMutableArr (SmallMutableArray smarr#) (I# n#) = primitive_ (- shrinkSmallMutableArray# smarr# n#)+#if MIN_VERSION_base(4,14,0)+ shrinkMutableArr = shrinkSmallMutableArray+#else+ shrinkMutableArr _ _ = return ()+#endif {-# INLINE shrinkMutableArr #-} sameMutableArr (SmallMutableArray smarr1#) (SmallMutableArray smarr2#) =
Z/Data/Array/Cast.hs view
@@ -24,8 +24,7 @@ ( Cast(..) ) where -import GHC.Prim-import GHC.Types+import GHC.Exts import GHC.Int import GHC.Word #if WORD_SIZE_IN_BITS < 64
Z/Data/Array/QQ.hs view
@@ -67,8 +67,7 @@ import Data.Bits import Data.Char (ord) import Data.Primitive.PrimArray-import GHC.Prim-import GHC.Ptr+import GHC.Exts import Data.Word import Data.Int import Language.Haskell.TH
Z/Data/Array/UnalignedAccess.hs view
@@ -7,6 +7,7 @@ {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-} {-| Module : Z.Data.Array.UnalignedAccess@@ -26,8 +27,7 @@ import Data.Primitive.ByteArray import Data.Primitive.PrimArray import GHC.Int-import GHC.Prim-import GHC.Types+import GHC.Exts import GHC.Word import GHC.Float (stgFloatToWord32, stgWord32ToFloat, stgWord64ToDouble, stgDoubleToWord64) import Foreign.C.Types
Z/Data/Builder/Base.hs view
@@ -77,12 +77,10 @@ import Control.Monad.ST.Unsafe (unsafeInterleaveST) import Data.Bits (shiftL, shiftR, (.&.)) import Data.Primitive.Ptr (copyPtrToMutablePrimArray)-import Data.String (IsString (..)) import Data.Word import Data.Int import GHC.CString (unpackCString#, unpackCStringUtf8#)-import GHC.Prim-import GHC.Ptr+import GHC.Exts import qualified Z.Data.Array as A import Z.Data.Array.UnalignedAccess import qualified Z.Data.Text.Base as T
Z/Data/JSON/Builder.hs view
@@ -41,7 +41,6 @@ import qualified Z.Data.Builder as B import qualified Z.Data.Builder.Base as B import qualified Z.Data.Text as T-import qualified Z.Data.Text.Base as T import Z.Data.Vector.Base as V import Z.Foreign import Z.Data.JSON.Value (Value(..))
Z/Data/JSON/Value.hs view
@@ -58,7 +58,6 @@ import Z.Data.Parser ((<?>)) import qualified Z.Data.Text as T import Z.Data.Text.Builder (ToText)-import qualified Z.Data.Text.Base as T import Z.Data.Vector.Base as V import Z.Data.Vector.Extra as V import Z.Foreign@@ -183,7 +182,7 @@ C_t -> P.bytes "true" $> (Bool True) C_n -> P.bytes "null" $> Null _ | w >= 48 && w <= 57 || w == MINUS -> Number <$> P.scientific'- | otherwise -> fail "Z.Data.JSON.Value.value: not a valid json value"+ | otherwise -> P.fail' "Z.Data.JSON.Value.value: not a valid json value" -- | parse json array with leading OPEN_SQUARE. array :: P.Parser (V.Vector Value)@@ -263,7 +262,7 @@ _ -> T.validateMaybe bs case mt of Just t -> P.skipWord8 $> t- _ -> fail "Z.Data.JSON.Value.string_: utf8 validation or unescaping failed"+ _ -> P.fail' "Z.Data.JSON.Value.string_: utf8 validation or unescaping failed" where go :: Word32 -> V.Bytes -> Either Word32 (V.Bytes, V.Bytes, Word32) go !state v =
Z/Data/Parser.hs view
@@ -53,7 +53,7 @@ , scientific' , scientifically' -- * Misc- , isSpace, isHexDigit, isDigit+ , isSpace, isHexDigit, isDigit, fail' ) where import Z.Data.Parser.Base
Z/Data/Parser/Base.hs view
@@ -50,6 +50,7 @@ , text -- * Misc , isSpace+ , fail' ) where import Control.Applicative@@ -485,7 +486,7 @@ case w of 10 -> return () 13 -> word8 10- _ -> fail "Z.Data.Parser.Base.endOfLine: mismatch byte"+ _ -> fail' "Z.Data.Parser.Base.endOfLine: mismatch byte" -------------------------------------------------------------------------------- @@ -627,7 +628,7 @@ takeWhile1 p = do bs <- takeWhile p if V.null bs- then fail "Z.Data.Parser.Base.takeWhile1: no satisfied byte"+ then fail' "Z.Data.Parser.Base.takeWhile1: no satisfied byte" else return bs -- | @bytes s@ parses a sequence of bytes that identically match @s@.
Z/Data/Parser/Numeric.hs view
@@ -346,7 +346,7 @@ !sign <- P.peek when (sign == MINUS) (P.skipWord8) -- no leading plus is allowed !intPart <- P.takeWhile1 isDigit- when (V.length intPart > 1 && V.head intPart == C_0) (fail "leading zeros are not allowed")+ when (V.length intPart > 1 && V.head intPart == C_0) (P.fail' "leading zeros are not allowed") mdot <- P.peekMaybe !sci <- case mdot of Just DOT -> do
Z/Data/PrimRef/PrimIORef.hs view
@@ -53,9 +53,8 @@ import Data.Primitive.Types import Data.Primitive.ByteArray-import GHC.Prim-import GHC.Types-import GHC.IO(stToIO)+import GHC.Exts+import GHC.IO import Z.Data.PrimRef.PrimSTRef -- | A mutable variable in the IO monad which can hold an instance of 'Prim'.
Z/Data/PrimRef/PrimSTRef.hs view
@@ -25,7 +25,7 @@ import Data.Primitive.Types import Data.Primitive.ByteArray import GHC.ST-import GHC.Types+import GHC.Exts -- | A mutable variable in the ST monad which can hold an instance of 'Prim'. --
Z/Data/Text/UTF8Codec.hs view
@@ -20,9 +20,8 @@ import Control.Monad.Primitive import Data.Primitive.ByteArray import Data.Primitive.PrimArray-import GHC.Prim+import GHC.Exts import GHC.ST-import GHC.Types import GHC.Word -- | Return a codepoint's encoded length in bytes
Z/Data/Vector/Base.hs view
@@ -114,9 +114,9 @@ import Data.Primitive.Ptr import qualified Data.Traversable as T import Foreign.C-import GHC.CString import GHC.Exts import GHC.Stack+import GHC.CString import GHC.Word import Prelude hiding (concat, concatMap, elem, notElem, null, length, map,
Z/Foreign.hs view
@@ -72,6 +72,8 @@ , withPrimVectorSafe , withPrimSafe , allocPrimSafe+ , pinPrimArray+ , pinPrimVector -- ** Pointer helpers , BA#, MBA# , clearMBA@@ -79,6 +81,7 @@ , castPtr -- ** re-export , module Data.Primitive.ByteArray+ , module Foreign.C.Types , module Data.Primitive.Ptr , module Z.Data.Array.UnalignedAccess ) where@@ -278,7 +281,7 @@ buf <- newPinnedPrimArray siz withMutablePrimArrayContents buf f --- | Pass 'PrimVector' to unsafe FFI as pointer+-- | Pass 'PrimVector' to safe FFI as pointer -- -- The 'PrimVector' version of 'withPrimArraySafe'. The 'Ptr' is already pointed -- to the first element, thus no offset is provided. After call returned, pointer is no longer valid.@@ -317,6 +320,29 @@ !b <- withMutablePrimArrayContents buf $ \ ptr -> f ptr !a <- readPrimArray buf 0 return (a, b)++-- | Convert a 'PrimArray' to a pinned one(memory won't moved by GC) if necessary.+pinPrimArray :: Prim a => PrimArray a -> IO (PrimArray a)+{-# INLINE pinPrimArray #-}+pinPrimArray arr+ | isPrimArrayPinned arr = return arr+ | otherwise = do+ let l = sizeofPrimArray arr+ buf <- newPinnedPrimArray l+ copyPrimArray buf 0 arr 0 l+ arr' <- unsafeFreezePrimArray buf+ return arr'++-- | Convert a 'PrimVector' to a pinned one(memory won't moved by GC) if necessary.+pinPrimVector :: Prim a => PrimVector a -> IO (PrimVector a)+{-# INLINE pinPrimVector #-}+pinPrimVector v@(PrimVector pa s l)+ | isPrimArrayPinned pa = return v+ | otherwise = do+ buf <- newPinnedPrimArray l+ copyPrimArray buf 0 pa s l+ pa' <- unsafeFreezePrimArray buf+ return (PrimVector pa' 0 l) --------------------------------------------------------------------------------