Skip to content

Commit 1b17bf2

Browse files
committed
Switch from template-haskell to template-haskell-lift
1 parent 227bb90 commit 1b17bf2

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

src/Data/Text.hs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,11 @@ import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
274274
import qualified GHC.Exts as Exts
275275
import GHC.Int (Int8)
276276
import 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
279278
import Text.Printf (PrintfArg, formatArg, formatString)
280279
import System.Posix.Types (CSsize(..))
281-
282-
#if MIN_VERSION_template_haskell(2,16,0)
283280
import Data.Text.Foreign (asForeignPtr)
284281
import 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
453449
instance 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)
475462
unpackCStringLen# :: Exts.Addr# -> Int -> Text
476463
unpackCStringLen# 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
486472
instance PrintfArg Text where

src/Data/Text/Lazy.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ import qualified GHC.CString as GHC
255255
import qualified GHC.Exts as Exts
256256
import GHC.Prim (Addr#)
257257
import GHC.Stack (HasCallStack)
258-
import qualified Language.Haskell.TH.Lib as TH
259-
import qualified Language.Haskell.TH.Syntax as TH
258+
import qualified Language.Haskell.TH.Lift as TH
260259
import Text.Printf (PrintfArg, formatArg, formatString)
261260

262261
-- $fusion
@@ -393,12 +392,8 @@ instance Data Text where
393392

394393
-- | @since 1.2.4.0
395394
instance TH.Lift Text where
396-
lift = TH.appE (TH.varE 'fromStrict) . TH.lift . toStrict
397-
#if MIN_VERSION_template_haskell(2,17,0)
398-
liftTyped = TH.unsafeCodeCoerce . TH.lift
399-
#elif MIN_VERSION_template_haskell(2,16,0)
400-
liftTyped = TH.unsafeTExpCoerce . TH.lift
401-
#endif
395+
lift x = [| fromStrict $(TH.lift . toStrict $ x) |]
396+
liftTyped = TH.defaultLiftTyped
402397

403398
-- | @since 1.2.2.0
404399
instance PrintfArg Text where

text.cabal

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ library
226226
bytestring >= 0.10.4 && < 0.13,
227227
deepseq >= 1.1 && < 1.6,
228228
ghc-prim >= 0.2 && < 0.15,
229-
template-haskell >= 2.5 && < 2.25
229+
template-haskell-lift >= 0.1 && <0.2
230230

231231
if impl(ghc < 9.4)
232232
build-depends: data-array-byte >= 0.1 && < 0.2
@@ -303,8 +303,14 @@ test-suite tests
303303
tasty,
304304
tasty-hunit,
305305
tasty-quickcheck,
306+
<<<<<<< HEAD
306307
template-haskell,
307308
temporary,
309+
||||||| parent of 44281e4 (Switch from template-haskell to template-haskell-lift)
310+
template-haskell,
311+
=======
312+
template-haskell-lift,
313+
>>>>>>> 44281e4 (Switch from template-haskell to template-haskell-lift)
308314
transformers,
309315
text
310316
if impl(ghc < 9.4)

0 commit comments

Comments
 (0)