Skip to content
Draft
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
21 changes: 17 additions & 4 deletions Data/ByteString/Internal/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ import GHC.Int (Int (..))
import GHC.ForeignPtr (unsafeWithForeignPtr)
#endif

import qualified Language.Haskell.TH.Lib as TH
#if __GLASGOW_HASKELL__ >= 914
import qualified Language.Haskell.TH.Lift as TH
#else
import qualified Language.Haskell.TH.Syntax as TH
import qualified Language.Haskell.TH.Lib as TH
#endif

#if !HS_unsafeWithForeignPtr_AVAILABLE
unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
Expand Down Expand Up @@ -360,7 +364,13 @@ byteStringDataType = mkDataType "Data.ByteString.ByteString" [packConstr]

-- | @since 0.11.2.0
instance TH.Lift ByteString where
#if MIN_VERSION_template_haskell(2,16,0)
#if __GLASGOW_HASKELL__ >= 914
lift (BS ptr len) =
[| unsafePackLenLiteral
$(TH.lift len)
$(TH.liftAddrCompat ptr 0 (fromIntegral len))
|]
#elif __GLASGOW_HASKELL__ >= 810
-- template-haskell-2.16 first ships with ghc-8.10
lift (BS ptr len) = [| unsafePackLenLiteral |]
`TH.appE` TH.litE (TH.integerL (fromIntegral len))
Expand All @@ -371,10 +381,13 @@ instance TH.Lift ByteString where
`TH.appE` TH.litE (TH.StringPrimL $ unpackBytes bs)
#endif

#if MIN_VERSION_template_haskell(2,17,0)
#if __GLASGOW_HASKELL__ >= 914
-- template-haskell-lift-0.1 first ships with ghc-9.16
liftTyped = TH.defaultLiftTyped
#elif __GLASGOW_HASKELL__ >= 900
-- template-haskell-2.17 first ships with ghc-9.0
liftTyped = TH.unsafeCodeCoerce . TH.lift
#elif MIN_VERSION_template_haskell(2,16,0)
#elif __GLASGOW_HASKELL__ >= 810
-- template-haskell-2.16 first ships with ghc-8.10
liftTyped = TH.unsafeTExpCoerce . TH.lift
#endif
Expand Down
4 changes: 4 additions & 0 deletions Data/ByteString/Lazy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ import Data.Data (Data(..), mkConstr ,mkDataType, Constr, DataTyp

import GHC.Exts (IsList(..))

#if __GLASGOW_HASKELL__ >= 914
import qualified Language.Haskell.TH.Lift as TH
#else
import qualified Language.Haskell.TH.Syntax as TH
#endif

#ifdef HS_BYTESTRING_ASSERTIONS
import Control.Exception (assert)
Expand Down
5 changes: 5 additions & 0 deletions Data/ByteString/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ import qualified Data.ByteString.Lazy.Internal as LBS

import qualified Data.List as List
import qualified GHC.Exts
#if __GLASGOW_HASKELL__ >= 914
import qualified Language.Haskell.TH.Lift as TH
#else
import qualified Language.Haskell.TH.Syntax as TH
#endif


-- | A compact representation of a 'Word8' vector.
--
Expand Down
16 changes: 14 additions & 2 deletions bytestring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,19 @@ common language

library
import: language
build-depends: base >= 4.12 && < 5, ghc-prim, deepseq, template-haskell
build-depends: base >= 4.12 && < 5, ghc-prim, deepseq

if impl(ghc < 9.4)
build-depends: data-array-byte >= 0.1 && < 0.2

-- template-haskell-lift was added as a boot library in GHC-9.14
-- once we no longer wish to backport releases to older major releases,
-- this conditional can be dropped
if impl(ghc < 9.14)
build-depends: template-haskell
else
build-depends: template-haskell-lift >= 0.1 && <0.2

exposed-modules: Data.ByteString
Data.ByteString.Char8
Data.ByteString.Unsafe
Expand Down Expand Up @@ -222,7 +230,6 @@ test-suite bytestring-tests
QuickCheck,
tasty,
tasty-quickcheck >= 0.8.1,
template-haskell,
transformers >= 0.3,
syb

Expand All @@ -235,6 +242,11 @@ test-suite bytestring-tests
if os(openbsd)
build-depends: splitmix < 0.1.3 || > 0.1.3.1

if impl(ghc < 9.14)
build-depends: template-haskell
else
build-depends: template-haskell-lift

benchmark bytestring-bench
import: language
main-is: BenchAll.hs
Expand Down
10 changes: 7 additions & 3 deletions tests/Lift.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import Test.Tasty.QuickCheck (testProperty, (===))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Short as SBS
#if __GLASGOW_HASKELL__ >= 914
import qualified Language.Haskell.TH.Lift as TH
#else
import qualified Language.Haskell.TH.Syntax as TH
#endif

testSuite :: TestTree
#ifdef wasm32_HOST_ARCH
Expand All @@ -26,7 +30,7 @@ testSuite = testGroup "Lift"
let bs = "\0\1\2\3\0\1\2\3" :: BS.ByteString in
bs === $(TH.lift $ BS.pack [0,1,2,3,0,1,2,3])

#if MIN_VERSION_template_haskell(2,16,0)
#if __GLASGOW_HASKELL__ >= 810
, testProperty "typed" $
let bs = "\0\1\2\3\0\1\2\3" :: BS.ByteString in
bs === $$(TH.liftTyped $ BS.pack [0,1,2,3,0,1,2,3])
Expand All @@ -42,7 +46,7 @@ testSuite = testGroup "Lift"
let bs = "\0\1\2\3\0\1\2\3" :: LBS.ByteString in
bs === $(TH.lift $ LBS.pack [0,1,2,3,0,1,2,3])

#if MIN_VERSION_template_haskell(2,16,0)
#if __GLASGOW_HASKELL__ >= 810
, testProperty "typed" $
let bs = "\0\1\2\3\0\1\2\3" :: LBS.ByteString in
bs === $$(TH.liftTyped $ LBS.pack [0,1,2,3,0,1,2,3])
Expand All @@ -58,7 +62,7 @@ testSuite = testGroup "Lift"
let bs = "\0\1\2\3\0\1\2\3" :: SBS.ShortByteString in
bs === $(TH.lift $ SBS.pack [0,1,2,3,0,1,2,3])

#if MIN_VERSION_template_haskell(2,16,0)
#if __GLASGOW_HASKELL__ >= 810
, testProperty "typed" $
let bs = "\0\1\2\3\0\1\2\3" :: SBS.ShortByteString in
bs === $$(TH.liftTyped $ SBS.pack [0,1,2,3,0,1,2,3])
Expand Down