@@ -199,12 +199,17 @@ import GHC.Int (Int (..))
199199import GHC.ForeignPtr (unsafeWithForeignPtr )
200200#endif
201201
202- import qualified Language.Haskell.TH.Lib as TH
202+ #if __GLASGOW_HASKELL__ >= 914
203+ import qualified Language.Haskell.TH.Lift as TH
204+ import Language.Haskell.TH.Lift (Code , Quote )
205+ #else
203206import qualified Language.Haskell.TH.Syntax as TH
204- import Language.Haskell.TH.Syntax (Lift , TExp )
207+ import qualified Language.Haskell.TH.Lib as TH
208+ import Language.Haskell.TH.Syntax (TExp )
205209#if __GLASGOW_HASKELL__ >= 900
206210import Language.Haskell.TH.Syntax (Code , Quote )
207211#endif
212+ #endif
208213
209214#if !MIN_VERSION_base(4,13,0)
210215import Control.Monad.Fail (MonadFail )
@@ -371,8 +376,14 @@ byteStringDataType :: DataType
371376byteStringDataType = mkDataType " Data.ByteString.ByteString" [packConstr]
372377
373378-- | @since 0.11.2.0
374- instance Lift ByteString where
375- #if MIN_VERSION_template_haskell(2,16,0)
379+ instance TH. Lift ByteString where
380+ #if __GLASGOW_HASKELL__ >= 914
381+ lift (BS ptr len) =
382+ [| unsafePackLenLiteral
383+ $ (TH. lift len)
384+ $ (TH. liftAddrCompat ptr 0 (fromIntegral len))
385+ | ]
386+ #elif __GLASGOW_HASKELL__ >= 810
376387-- template-haskell-2.16 first ships with ghc-8.10
377388 lift (BS ptr len) = [| unsafePackLenLiteral | ]
378389 `TH.appE` TH. litE (TH. integerL (fromIntegral len))
@@ -383,10 +394,13 @@ instance Lift ByteString where
383394 `TH.appE` TH. litE (TH. StringPrimL $ unpackBytes bs)
384395#endif
385396
386- #if MIN_VERSION_template_haskell(2,17,0)
397+ #if __GLASGOW_HASKELL__ >= 914
398+ -- template-haskell-lift-0.1 first ships with ghc-9.16
399+ liftTyped = TH. defaultLiftTyped
400+ #elif __GLASGOW_HASKELL__ >= 900
387401-- template-haskell-2.17 first ships with ghc-9.0
388402 liftTyped = TH. unsafeCodeCoerce . TH. lift
389- #elif MIN_VERSION_template_haskell(2,16,0)
403+ #elif __GLASGOW_HASKELL__ >= 810
390404-- template-haskell-2.16 first ships with ghc-8.10
391405 liftTyped = TH. unsafeTExpCoerce . TH. lift
392406#endif
@@ -559,17 +573,13 @@ type Quote m = (TH.Q ~ m)
559573type Code m a = m (TExp a )
560574#endif
561575
562- liftTyped :: forall a m . (MonadFail m , Quote m , Lift a ) => a -> Code m a
563- #if MIN_VERSION_template_haskell(2,17,0)
576+ liftTyped :: forall a m . (MonadFail m , Quote m , TH. Lift a ) => a -> Code m a
577+ #if __GLASGOW_HASKELL__ >= 914
578+ liftTyped = TH. defaultLiftTyped
579+ #elif __GLASGOW_HASKELL__ >= 900
564580liftTyped = TH. liftTyped
565-
566- liftCode :: forall a m . (MonadFail m , Quote m ) => m (TExp a ) -> Code m a
567- liftCode = TH. liftCode
568581#else
569582liftTyped = TH. unsafeTExpCoerce . TH. lift
570-
571- liftCode :: forall a m . (MonadFail m , Quote m ) => m TH. Exp -> Code m a
572- liftCode = TH. unsafeTExpCoerce
573583#endif
574584
575585data S2W = Octets {- # UNPACK #-} !Int [Word8 ]
@@ -599,7 +609,7 @@ literalFromOctetString :: (MonadFail m, Quote m) => String -> Code m ByteString
599609literalFromOctetString " " = [|| empty|| ]
600610literalFromOctetString s = case foldr' op (Octets 0 [] ) s of
601611 Octets n ws -> liftTyped (unsafePackLenBytes n ws)
602- Hichar i w -> liftCode $ fail $ " non-octet character '\\ " ++
612+ Hichar i w -> error $ " non-octet character '\\ " ++
603613 show w ++ " ' at offset: " ++ show i
604614 where
605615 op :: Char -> S2W -> S2W
@@ -624,8 +634,8 @@ literalFromHex "" = [||empty||]
624634literalFromHex s =
625635 case foldr' op (Hex 0 [] ) s of
626636 Hex n ws -> liftTyped (unsafePackLenBytes n ws)
627- Odd i _ _ -> liftCode $ fail $ " Odd input length: " ++ show (1 + 2 * i)
628- Bad i w -> liftCode $ fail $ " Non-hexadecimal character '\\ " ++
637+ Odd i _ _ -> error $ " Odd input length: " ++ show (1 + 2 * i)
638+ Bad i w -> error $ " Non-hexadecimal character '\\ " ++
629639 show w ++ " ' at offset: " ++ show i
630640 where
631641 -- Convert char to decimal digit value if result in [0, 9].
0 commit comments