Skip to content
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

Merge shortbytestring package back into bytestring wrt #444 #471

Merged
merged 73 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2125e9d
Merge `shortbytestring` package back into `bytestring` wrt #444
hasufell Jan 21, 2022
46b128a
Fix build on ARM
hasufell Jan 21, 2022
09a8916
Speed up reverse by using byteSwap64 tricks
hasufell Jan 22, 2022
d69c427
Remove phase control from inlines
hasufell Jan 22, 2022
cb349be
Improve performance of elemIndex
hasufell Jan 22, 2022
e29f102
Use setByteArray in replicate
hasufell Jan 22, 2022
fcb3170
Implement intercalate manually
hasufell Jan 22, 2022
5975e88
Annotate partial functions with HasCallStack
hasufell Jan 22, 2022
f78661a
Fix build on base < 4.12.0.0
hasufell Jan 22, 2022
b88e4fe
Add uncons/unsnoc
hasufell Jan 22, 2022
c2b2bfd
Correct complexities
hasufell Jan 22, 2022
6fb3195
Exclude reverse optimization path from ARM
hasufell Jan 23, 2022
6cf6dce
Add benchmarks for ShortByteString
hasufell Jan 24, 2022
df1c784
Improve inlining
hasufell Jan 24, 2022
e492432
Adjust haddock identifiers
hasufell Jan 24, 2022
6238e76
Get rid of writeCharArray#
hasufell Jan 24, 2022
ecc57b1
Haddock fixes
hasufell Jan 24, 2022
f06fdf5
Clean up tests
hasufell Jan 25, 2022
ba067f8
Use -fexpose-all-unfoldings
hasufell Jan 25, 2022
cdd34a5
Improve reverse
hasufell Jan 25, 2022
04eb82f
Cleanup 'reverse'
hasufell Jan 25, 2022
95aa7ab
Fix possible GC race with foreign imports
hasufell Jan 27, 2022
96caf73
Disable asserts in shortbytestring.c
hasufell Jan 27, 2022
00606ab
Remove redundant import
hasufell Jan 27, 2022
454b3b5
Add documentation about partial functions
hasufell Jan 27, 2022
b3f90b4
Fold ShortByteString prop tests into ByteString
hasufell Jan 27, 2022
0140332
Restore previous INLINEs
hasufell Jan 30, 2022
5acda9d
Improve naming of bindings
hasufell Jan 30, 2022
1be5f98
Consolidate error handling functions
hasufell Jan 30, 2022
01a760b
Remove trailing whitespace
hasufell Jan 30, 2022
4bc5bce
Fix uncons in documentation
hasufell Jan 30, 2022
bea295a
Rename indexWord64Array to indexWord8ArrayAsWord64
hasufell Jan 30, 2022
557f5f6
Improve error message
hasufell Jan 30, 2022
2855d47
Clean up incorrect documentation
hasufell Jan 30, 2022
ac32771
Use div/mod instead of quot/rem
hasufell Jan 30, 2022
afafd32
Simplify branching in reverse
hasufell Jan 30, 2022
2ff0e3c
Move asserts to Haskell
hasufell Jan 30, 2022
a1aec25
Prefix C functions
hasufell Jan 30, 2022
2246ce1
Fix return type of c_elem_index
hasufell Jan 30, 2022
441cc5e
Fix documentation in unfoldrN
hasufell Jan 30, 2022
d2834df
Make unfoldrN more efficient
hasufell Jan 30, 2022
51467b8
Fix maintainer field
hasufell Jan 30, 2022
9b77b82
Fix formatting
hasufell Jan 30, 2022
0e945f5
Implement takeEnd, dropeEnd and splitAt manually
hasufell Jan 30, 2022
f5a4d7a
Fix some haddock identifiers
hasufell Jan 30, 2022
e5fcb93
Fix unfoldrN doc
hasufell Jan 30, 2022
b389c42
Add a primops bounds-checking job to CI
hasufell Jan 31, 2022
81b1e8e
Document and clean up createAndTrim
hasufell Feb 1, 2022
6ef1b41
Rename errorEmptyList to errorEmptySBS
hasufell Feb 1, 2022
b1ce7fd
Improve documentation for findFromEndUntil
hasufell Feb 1, 2022
7ba6ed1
Improve documentation and naming
hasufell Feb 6, 2022
a7e0765
Optimize out quotRem
hasufell Feb 6, 2022
bb7924a
Document compareByteArraysOff
hasufell Feb 7, 2022
820827f
Simplify findIndexOrLength and findFromEndUntil
hasufell Feb 7, 2022
fc988b5
Use c_count for count
hasufell Feb 7, 2022
e72b3f9
Simplify elemIndex
hasufell Feb 7, 2022
409c1fc
Remove use of 'mempty'
hasufell Feb 7, 2022
ae7ff05
Make sure breakSubstring is inlined into isInfixOf
hasufell Feb 7, 2022
08c8b5d
Simplify stripSuffix and stripPrefix
hasufell Feb 7, 2022
3d0c977
Fix redundant import warnings
hasufell Feb 7, 2022
e05f05d
Improve 'take'
hasufell Feb 7, 2022
659edd9
Use existing bounnds check in 'drop'
hasufell Feb 7, 2022
fd83ec2
Avoid 'create' when bytestring is empty
hasufell Feb 7, 2022
98450fc
Optimize filter
hasufell Feb 7, 2022
b647760
Remove redundant INLINABLE
hasufell Feb 7, 2022
6289d9f
Use shorter 'createAndTrim' in 'filter'
hasufell Feb 7, 2022
28b8686
Simplify 'take'
hasufell Feb 7, 2022
bc90b58
Simplify 'drop'
hasufell Feb 7, 2022
fed9a73
Better formatting
hasufell Feb 7, 2022
213218c
Add comment to explain DNDEBUG
hasufell Feb 8, 2022
04e2392
Refactor elemIndex
hasufell Feb 8, 2022
3d6722b
Optimize 'partition'
hasufell Feb 8, 2022
d12ad66
Optimize hot loop in 'partition'
hasufell Feb 8, 2022
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
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,24 @@ jobs:
ghc --version
ghc --make -Iinclude -itests:tests/builder -o Main cbits/*.c tests/Main.hs +RTS -s
./Main +RTS -s
bounds-checking:
runs-on: ubuntu-latest
container:
image: fedora:34
steps:
- name: install deps
run: |
dnf install -y gcc gmp gmp-devel make ncurses ncurses-compat-libs xz perl
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 sh
source ~/.ghcup/env
ghcup install ghc -u https://downloads.haskell.org/~ghcup/unofficial-bindists/ghc/9.3.20220124/ghc-9.3.20220124-x86_64-linux-fedora-34-bounds-checking-ddf50f4b.tar.xz --set 9.3.20220124
ghcup install cabal
shell: bash
- uses: actions/checkout@v1
- name: test
run: |
source ~/.ghcup/env
cabal update
cabal run -w ghc-9.3.20220124 --ghc-options='-fcheck-prim-bounds -fno-ignore-asserts' bytestring-tests
shell: bash
10 changes: 9 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
* [`readInt` returns `Nothing`, if the sequence of digits cannot be represented by an `Int`, instead of overflowing silently](https://github.com/haskell/bytestring/pull/309)
* [Remove `zipWith` rewrite rule](https://github.com/haskell/bytestring/pull/387)

[0.12.0.0]: https://github.com/haskell/bytestring/compare/0.11.2.0...0.12.0.0
[0.12.0.0]: https://github.com/haskell/bytestring/compare/0.11.3.0...0.12.0.0

[0.11.3.0] — Unreleased

* merge `shortbytestring` package back into `bytestring` wrt [#444](https://github.com/haskell/bytestring/issues/444),
adding lots of additional API:
- [Add `all`, `any`, `append`, `break`, `breakEnd`, `breakSubstring`, `concat`, `cons`, `count`, `drop`, `dropEnd`, `dropWhile`, `dropWhileEnd`, `elem`, `elemIndex`, `elemIndices`, `filter`, `find`, `findIndex`, `findIndices`, `foldl'`, `foldl`, `foldl1'`, `foldl1`, `foldr'`, `foldr`, `foldr1'`, `foldr1`, `head`, `init`, `intercalate`, `isInfixOf`, `isPrefixOf`, `isSuffixOf`, `last`, `map`, `partition`, `replicate`, `reverse`, `singleton`, `snoc`, `span`, `spanEnd`, `split`, `splitAt`, `splitWith`, `stripPrefix`, `stripSuffix`, `tail`, `take`, `takeEnd`, `takeWhile`, `takeWhileEnd`, `uncons`, `unfoldr`, `unfoldrN`, `unsnoc`](https://github.com/haskell/bytestring/pull/471)

[0.11.3.0]: https://github.com/haskell/bytestring/compare/0.11.2.0...0.11.3.0

[0.11.2.0] — December 2021

Expand Down
10 changes: 5 additions & 5 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ splitAt n ps@(BS x l)
| otherwise = (BS x n, BS (plusForeignPtr x n) (l-n))
{-# INLINE splitAt #-}

-- | Similar to 'P.takeWhile',
-- | Similar to 'Prelude.takeWhile',
-- returns the longest (possibly empty) prefix of elements
-- satisfying the predicate.
takeWhile :: (Word8 -> Bool) -> ByteString -> ByteString
Expand Down Expand Up @@ -983,7 +983,7 @@ takeWhileEnd :: (Word8 -> Bool) -> ByteString -> ByteString
takeWhileEnd f ps = unsafeDrop (findFromEndUntil (not . f) ps) ps
{-# INLINE takeWhileEnd #-}

-- | Similar to 'P.dropWhile',
-- | Similar to 'Prelude.dropWhile',
-- drops the longest (possibly empty) prefix of elements
-- satisfying the predicate and returns the remainder.
dropWhile :: (Word8 -> Bool) -> ByteString -> ByteString
Expand All @@ -1001,7 +1001,7 @@ dropWhile f ps = unsafeDrop (findIndexOrLength (not . f) ps) ps
dropWhile (`eqWord8` x) = snd . spanByte x
#-}

-- | Similar to 'P.dropWhileEnd',
-- | Similar to 'Prelude.dropWhileEnd',
-- drops the longest (possibly empty) suffix of elements
-- satisfying the predicate and returns the remainder.
--
Expand All @@ -1012,7 +1012,7 @@ dropWhileEnd :: (Word8 -> Bool) -> ByteString -> ByteString
dropWhileEnd f ps = unsafeTake (findFromEndUntil (not . f) ps) ps
{-# INLINE dropWhileEnd #-}

-- | Similar to 'P.break',
-- | Similar to 'Prelude.break',
-- returns the longest (possibly empty) prefix of elements which __do not__
-- satisfy the predicate and the remainder of the string.
--
Expand Down Expand Up @@ -1058,7 +1058,7 @@ breakByte c p = case elemIndex c p of
breakEnd :: (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
breakEnd p ps = splitAt (findFromEndUntil p ps) ps

-- | Similar to 'P.span',
-- | Similar to 'Prelude.span',
-- returns the longest (possibly empty) prefix of elements
-- satisfying the predicate and the remainder of the string.
--
Expand Down
10 changes: 5 additions & 5 deletions Data/ByteString/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ splitAt i cs0 = splitAt' i cs0
in (Chunk c cs', cs'')


-- | Similar to 'P.takeWhile',
-- | Similar to 'Prelude.takeWhile',
-- returns the longest (possibly empty) prefix of elements
-- satisfying the predicate.
takeWhile :: (Word8 -> Bool) -> ByteString -> ByteString
Expand Down Expand Up @@ -882,7 +882,7 @@ takeWhileEnd f = takeWhileEnd'
c' | S.length c' == S.length c -> (True, Chunk c bs)
| otherwise -> (False, fromStrict c' `append` bs)

-- | Similar to 'P.dropWhile',
-- | Similar to 'Prelude.dropWhile',
-- drops the longest (possibly empty) prefix of elements
-- satisfying the predicate and returns the remainder.
dropWhile :: (Word8 -> Bool) -> ByteString -> ByteString
Expand All @@ -893,7 +893,7 @@ dropWhile f = dropWhile'
n | n < S.length c -> Chunk (S.drop n c) cs
| otherwise -> dropWhile' cs

-- | Similar to 'P.dropWhileEnd',
-- | Similar to 'Prelude.dropWhileEnd',
-- drops the longest (possibly empty) suffix of elements
-- satisfying the predicate and returns the remainder.
--
Expand All @@ -916,7 +916,7 @@ dropWhileEnd f = go []
x' | S.null x' -> dropEndBytes xs
| otherwise -> List.foldl' (flip Chunk) Empty (x' : xs)

-- | Similar to 'P.break',
-- | Similar to 'Prelude.break',
-- returns the longest (possibly empty) prefix of elements which __do not__
-- satisfy the predicate and the remainder of the string.
--
Expand Down Expand Up @@ -995,7 +995,7 @@ spanByte c (LPS ps) = case (spanByte' ps) of (a,b) -> (LPS a, LPS b)
| otherwise -> (x' : [], x'' : xs)
-}

-- | Similar to 'P.span',
-- | Similar to 'Prelude.span',
-- returns the longest (possibly empty) prefix of elements
-- satisfying the predicate and the remainder of the string.
--
Expand Down
107 changes: 97 additions & 10 deletions Data/ByteString/Short.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

-- |
-- Module : Data.ByteString.Short
-- Copyright : (c) Duncan Coutts 2012-2013
-- Copyright : (c) Duncan Coutts 2012-2013, Julian Ospald 2022
-- License : BSD-style
--
-- Maintainer : [email protected]
-- Maintainer : [email protected]
-- Stability : stable
-- Portability : ghc only
--
Expand Down Expand Up @@ -67,26 +67,113 @@ module Data.ByteString.Short (
-- small unpinned strings are allocated in the same way as normal heap
-- allocations, rather than in a separate pinned area.

-- * Conversions
toShort,
fromShort,
-- * Introducing and eliminating 'ShortByteString's
empty,
singleton,
pack,
unpack,
fromShort,
toShort,

-- * Other operations
empty, null, length, index, indexMaybe, (!?),
-- * Basic interface
snoc,
cons,
append,
last,
tail,
uncons,
head,
init,
unsnoc,
null,
length,

-- ** Encoding validation
-- * Encoding validation
isValidUtf8,

-- * Transforming ShortByteStrings
map,
reverse,
intercalate,

-- * Reducing 'ShortByteString's (folds)
foldl,
foldl',
foldl1,
foldl1',

foldr,
foldr',
foldr1,
foldr1',

-- ** Special folds
all,
any,
concat,

-- ** Generating and unfolding ByteStrings
replicate,
unfoldr,
unfoldrN,

-- * Substrings

-- ** Breaking strings
take,
takeEnd,
takeWhileEnd,
takeWhile,
drop,
dropEnd,
dropWhile,
dropWhileEnd,
breakEnd,
break,
span,
spanEnd,
splitAt,
split,
splitWith,
stripSuffix,
stripPrefix,

-- * Predicates
isInfixOf,
isPrefixOf,
isSuffixOf,

-- ** Search for arbitrary substrings
breakSubstring,

-- * Searching ShortByteStrings

-- ** Searching by equality
elem,

-- ** Searching with a predicate
find,
filter,
partition,

-- * Indexing ShortByteStrings
index,
indexMaybe,
(!?),
elemIndex,
elemIndices,
count,
findIndex,
findIndices,

-- * Low level conversions
-- ** Packing 'Foreign.C.String.CString's and pointers
packCString,
packCStringLen,

-- ** Using ByteStrings as 'Foreign.C.String.CString's
-- ** Using ShortByteStrings as 'Foreign.C.String.CString's
useAsCString,
useAsCStringLen
useAsCStringLen,
) where

import Data.ByteString.Short.Internal
Expand Down
Loading