diff --git a/Data/ByteString/Internal/Type.hs b/Data/ByteString/Internal/Type.hs index 31e449b7..1f279a15 100644 --- a/Data/ByteString/Internal/Type.hs +++ b/Data/ByteString/Internal/Type.hs @@ -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 @@ -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)) @@ -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 diff --git a/Data/ByteString/Lazy/Internal.hs b/Data/ByteString/Lazy/Internal.hs index b8f42551..7e1a798c 100644 --- a/Data/ByteString/Lazy/Internal.hs +++ b/Data/ByteString/Lazy/Internal.hs @@ -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) diff --git a/Data/ByteString/Short/Internal.hs b/Data/ByteString/Short/Internal.hs index 21dc2587..6205385b 100644 --- a/Data/ByteString/Short/Internal.hs +++ b/Data/ByteString/Short/Internal.hs @@ -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. -- diff --git a/bytestring.cabal b/bytestring.cabal index dcdd35a0..df89d24d 100644 --- a/bytestring.cabal +++ b/bytestring.cabal @@ -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 @@ -222,7 +230,6 @@ test-suite bytestring-tests QuickCheck, tasty, tasty-quickcheck >= 0.8.1, - template-haskell, transformers >= 0.3, syb @@ -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 diff --git a/tests/Lift.hs b/tests/Lift.hs index 31d5a786..f8ec0ee1 100644 --- a/tests/Lift.hs +++ b/tests/Lift.hs @@ -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 @@ -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]) @@ -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]) @@ -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])