Skip to content

Commit ba8c37a

Browse files
authored
Documentation improvements (#710)
* Documentation improvements * Fix CI * Drop support of GHC 8.4
1 parent 10099d9 commit ba8c37a

File tree

9 files changed

+49
-23
lines changed

9 files changed

+49
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: true
1919
matrix:
2020
os: [ubuntu-latest]
21-
ghc: ['8.4', '8.6', '8.8', '8.10', '9.0', '9.2', '9.4', '9.6', '9.8', '9.10', '9.12']
21+
ghc: ['8.6', '8.8', '8.10', '9.0', '9.2', '9.4', '9.6', '9.8', '9.10', '9.12']
2222
include:
2323
- os: macOS-latest
2424
ghc: 'latest'

Data/ByteString.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,13 @@ isValidUtf8 (BS ptr len) = accursedUnutterablePerformIO $ unsafeWithForeignPtr p
15581558

15591559
-- | Break a string on a substring, returning a pair of the part of the
15601560
-- string prior to the match, and the rest of the string.
1561+
-- If the substring is not found, return the entire string in the first component
1562+
-- and an empty string in the second component.
1563+
--
1564+
-- >>> breakSubstring "needle" "hayneedlestraw"
1565+
-- ("hay","needlestraw")
1566+
-- >>> breakSubstring "needle" "hay"
1567+
-- ("hay","")
15611568
--
15621569
-- The following relationships hold:
15631570
--
@@ -1576,7 +1583,7 @@ isValidUtf8 (BS ptr len) = accursedUnutterablePerformIO $ unsafeWithForeignPtr p
15761583
--
15771584
-- > fst (breakSubstring x y)
15781585
--
1579-
-- Note that calling `breakSubstring x` does some preprocessing work, so
1586+
-- Note that calling 'breakSubstring' @x@ does some preprocessing work, so
15801587
-- you should avoid unnecessarily duplicating breakSubstring calls with the same
15811588
-- pattern.
15821589
--
@@ -2017,8 +2024,7 @@ hGetContentsSizeHint hnd =
20172024
-- we grow the buffer sizes, but not too huge
20182025
-- we concatenate in the end anyway
20192026

2020-
-- | getContents. Read stdin strictly. Equivalent to hGetContents stdin
2021-
-- The 'Handle' is closed after the contents have been read.
2027+
-- | Equivalent to 'hGetContents' 'stdin', reading it /strictly/.
20222028
--
20232029
getContents :: IO ByteString
20242030
getContents = hGetContents stdin

Data/ByteString/Lazy.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,21 @@ illegalBufferSize handle fn sz =
15971597
msg = fn ++ ": illegal ByteString size " ++ showsPrec 9 sz []
15981598

15991599
-- | Read entire handle contents /lazily/ into a 'ByteString'. Chunks
1600-
-- are read on demand, using the default chunk size.
1600+
-- are read on demand, using the default chunk size ('defaultChunkSize').
16011601
--
16021602
-- File handles are closed on EOF if all the file is read, or through
16031603
-- garbage collection otherwise.
16041604
--
1605+
-- Beware of using this function inside of 'Control.Exception.bracket' \/
1606+
-- 'System.IO.withFile' \/ 'System.IO.withBinaryFile':
1607+
-- lazy I/O can easily escape it, causing 'Control.Exception.bracket' to close a handle prematurely:
1608+
--
1609+
-- >>> withBinaryFile "foo.txt" ReadMode BL.hGetContents >>= print
1610+
-- "*** Exception: foo.txt: hGetBufSome: illegal operation (handle is closed)
1611+
--
1612+
-- The expected way of using 'hGetContents' is to open a handle,
1613+
-- pass it to 'hGetContents', and leave 'hGetContents' to close the handle when it sees fit.
1614+
--
16051615
hGetContents :: Handle -> IO ByteString
16061616
hGetContents = hGetContentsN defaultChunkSize
16071617

@@ -1644,7 +1654,7 @@ writeFile = modifyFile WriteMode
16441654
appendFile :: FilePath -> ByteString -> IO ()
16451655
appendFile = modifyFile AppendMode
16461656

1647-
-- | getContents. Equivalent to hGetContents stdin. Will read /lazily/
1657+
-- | Equivalent to 'hGetContents' 'stdin', reading it /lazily/.
16481658
--
16491659
getContents :: IO ByteString
16501660
getContents = hGetContents stdin

Data/ByteString/Lazy/Internal.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ import Control.Exception (assert)
7878
-- 8-bit characters.
7979
--
8080
#ifndef HS_BYTESTRING_ASSERTIONS
81-
data ByteString = Empty | Chunk {-# UNPACK #-} !S.StrictByteString ByteString
82-
-- INVARIANT: The S.StrictByteString field of any Chunk is not empty.
83-
-- (See also the 'invariant' and 'checkInvariant' functions.)
81+
data ByteString
82+
= Empty
83+
| Chunk
84+
{-# UNPACK #-} !S.StrictByteString
85+
-- ^ Must be nonempty. Consider using
86+
-- the smart constructor 'chunk' to ensure this invariant.
87+
-- See also the 'invariant' and 'checkInvariant' functions.
88+
LazyByteString
8489

8590
-- To make testing of this invariant convenient, we add an
8691
-- assertion to that effect when the HS_BYTESTRING_ASSERTIONS

Data/ByteString/Short/Internal.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,13 @@ isSuffixOf sbs1 = \sbs2 -> do
12961296

12971297
-- | Break a string on a substring, returning a pair of the part of the
12981298
-- string prior to the match, and the rest of the string.
1299+
-- If the substring is not found, return the entire string in the first component
1300+
-- and an empty string in the second component.
1301+
--
1302+
-- >>> breakSubstring "needle" "hayneedlestraw"
1303+
-- ("hay","needlestraw")
1304+
-- >>> breakSubstring "needle" "hay"
1305+
-- ("hay","")
12991306
--
13001307
-- The following relationships hold:
13011308
--

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ of `ByteString` values from smaller pieces during binary serialization.
1616
Requirements:
1717

1818
* Cabal 2.2 or greater
19-
* GHC 8.4 or greater
19+
* GHC 8.6 or greater
2020

2121
### Authors
2222

bench/BenchReadInt.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import Test.Tasty.Bench
1818
import Data.Int
1919
import Data.Word
2020
import Numeric.Natural
21-
#if !(MIN_VERSION_base(4,11,0))
22-
import Data.Semigroup (Semigroup((<>)))
23-
#endif
2421
import Data.Monoid (mconcat)
2522

2623
------------------------------------------------------------------------------

bytestring.cabal

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,16 @@ Author: Don Stewart,
5757
Maintainer: Haskell Bytestring Team <[email protected]>, Core Libraries Committee
5858
Homepage: https://github.com/haskell/bytestring
5959
Bug-reports: https://github.com/haskell/bytestring/issues
60-
Tested-With: GHC==9.12.1,
61-
GHC==9.10.1,
60+
Tested-With: GHC==9.12.2,
61+
GHC==9.10.2,
6262
GHC==9.8.4,
63-
GHC==9.6.6,
63+
GHC==9.6.7,
6464
GHC==9.4.8,
6565
GHC==9.2.8,
6666
GHC==9.0.2,
6767
GHC==8.10.7,
6868
GHC==8.8.4,
69-
GHC==8.6.5,
70-
GHC==8.4.4
69+
GHC==8.6.5
7170
Build-Type: Simple
7271
extra-source-files: README.md Changelog.md include/bytestring-cpp-macros.h
7372

@@ -110,7 +109,7 @@ common language
110109

111110
library
112111
import: language
113-
build-depends: base >= 4.11 && < 5, ghc-prim, deepseq, template-haskell
112+
build-depends: base >= 4.12 && < 5, ghc-prim, deepseq, template-haskell
114113

115114
if impl(ghc < 9.4)
116115
build-depends: data-array-byte >= 0.1 && < 0.2
@@ -232,6 +231,10 @@ test-suite bytestring-tests
232231
if !arch(wasm32)
233232
ghc-options: -threaded
234233

234+
-- https://github.com/haskellari/splitmix/issues/101
235+
if os(openbsd)
236+
build-depends: splitmix < 0.1.3 || > 0.1.3.1
237+
235238
benchmark bytestring-bench
236239
import: language
237240
main-is: BenchAll.hs
@@ -245,8 +248,7 @@ benchmark bytestring-bench
245248
hs-source-dirs: bench
246249

247250
ghc-options: -O2 "-with-rtsopts=-A32m"
248-
if impl(ghc >= 8.6)
249-
ghc-options: -fproc-alignment=64
251+
-fproc-alignment=64
250252
build-depends: base,
251253
bytestring,
252254
deepseq,

include/bytestring-cpp-macros.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ which are known not to trap (either to the kernel for emulation, or crash).
2323

2424

2525
#define HS_UNALIGNED_ByteArray_OPS_OK \
26-
MIN_VERSION_base(4,12,0) \
27-
&& (MIN_VERSION_base(4,16,1) || HS_UNALIGNED_POKES_OK)
26+
MIN_VERSION_base(4,16,1) || HS_UNALIGNED_POKES_OK
2827
/*
2928
The unaligned ByteArray# primops became available with base-4.12.0/ghc-8.6,
3029
but require an unaligned-friendly host architecture to be safe to use

0 commit comments

Comments
 (0)