@@ -274,15 +274,11 @@ import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
274274import qualified GHC.Exts as Exts
275275import GHC.Int (Int8 )
276276import GHC.Stack (HasCallStack )
277- import qualified Language.Haskell.TH.Lib as TH
278- import qualified Language.Haskell.TH.Syntax as TH
277+ import qualified Language.Haskell.TH.Lift as TH
279278import Text.Printf (PrintfArg , formatArg , formatString )
280279import System.Posix.Types (CSsize (.. ))
281-
282- #if MIN_VERSION_template_haskell(2,16,0)
283280import Data.Text.Foreign (asForeignPtr )
284281import System.IO.Unsafe (unsafePerformIO )
285- #endif
286282
287283-- $setup
288284-- >>> :set -package transformers
@@ -451,27 +447,18 @@ instance Data Text where
451447
452448-- | @since 1.2.4.0
453449instance TH. Lift Text where
454- #if MIN_VERSION_template_haskell(2,16,0)
455450 lift txt = do
456451 let (ptr, len) = unsafePerformIO $ asForeignPtr txt
457452 case len of
458- 0 -> TH. varE ' empty
453+ 0 -> [ | empty | ]
459454 _ ->
460455 let
461- bytesQ = TH. litE . TH. bytesPrimL $ TH. mkBytes ptr 0 (P. fromIntegral len)
462- lenQ = liftInt (P. fromIntegral len)
463- liftInt n = (TH. appE (TH. conE 'Exts. I # ) (TH. litE (TH. IntPrimL n)))
464- in TH. varE 'unpackCStringLen# `TH.appE` bytesQ `TH.appE` lenQ
465- #else
466- lift = TH. appE (TH. varE 'pack) . TH. stringE . unpack
467- #endif
468- #if MIN_VERSION_template_haskell(2,17,0)
469- liftTyped = TH. unsafeCodeCoerce . TH. lift
470- #elif MIN_VERSION_template_haskell(2,16,0)
471- liftTyped = TH. unsafeTExpCoerce . TH. lift
472- #endif
456+ bytesQ = TH. liftAddrCompat ptr 0 (P. fromIntegral len)
457+ lenQ = TH. liftIntCompat (P. fromIntegral len)
458+ in [| unpackCStringLen# $ bytesQ $ lenQ | ]
459+
460+ liftTyped = TH. defaultLiftTyped
473461
474- #if MIN_VERSION_template_haskell(2,16,0)
475462unpackCStringLen# :: Exts. Addr# -> Int -> Text
476463unpackCStringLen# addr# l = Text ba 0 l
477464 where
@@ -480,7 +467,6 @@ unpackCStringLen# addr# l = Text ba 0 l
480467 A. copyFromPointer marr 0 (Exts. Ptr addr# ) l
481468 A. unsafeFreeze marr
482469{-# NOINLINE unpackCStringLen# #-} -- set as NOINLINE to avoid generated code bloat
483- #endif
484470
485471-- | @since 1.2.2.0
486472instance PrintfArg Text where
0 commit comments