[Git][ghc/ghc][master] compiler: add Binary Text instance
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 0f5a73bc by Cheng Shao at 2026-02-11T16:07:27-05:00 compiler: add Binary Text instance This patch adds `Binary` instance for strict `Text`, in preparation of making `Text` usable in certain GHC API use cases (e.g. haddock). This also introduces `text` as a direct dependency of the `ghc` package. - - - - - 2 changed files: - compiler/GHC/Utils/Binary.hs - compiler/ghc.cabal.in Changes: ===================================== compiler/GHC/Utils/Binary.hs ===================================== @@ -150,6 +150,7 @@ import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Internal as BS import qualified Data.ByteString.Unsafe as BS import qualified Data.ByteString.Short.Internal as SBS +import qualified Data.Text.Internal as T import Data.IORef import Data.Char ( ord, chr ) import Data.List.NonEmpty ( NonEmpty(..)) @@ -1816,13 +1817,19 @@ putSBS :: WriteBinHandle -> SBS.ShortByteString -> IO () putSBS bh sbs = do let l = SBS.length sbs put_ bh l - putPrim bh l (\p -> SBS.copyToPtr sbs 0 p l) + putSBSOffLen bh sbs 0 l +putSBSOffLen :: WriteBinHandle -> SBS.ShortByteString -> Int -> Int -> IO () +putSBSOffLen bh sbs off len = + putPrim bh len $ \p -> SBS.copyToPtr sbs off p len getSBS :: ReadBinHandle -> IO SBS.ShortByteString getSBS bh = do l <- get bh :: IO Int - getPrim bh l (\src -> SBS.createFromPtr src l) + getSBSLen bh l + +getSBSLen :: ReadBinHandle -> Int -> IO SBS.ShortByteString +getSBSLen bh len = getPrim bh len $ \src -> SBS.createFromPtr src len putBS :: WriteBinHandle -> ByteString -> IO () putBS bh bs = @@ -1856,6 +1863,16 @@ instance Binary LBS.ByteString where get bh = LBS.fromStrict <$> get bh +instance Binary T.Text where + put_ bh (T.Text ba off len) = do + put_ bh len + putSBSOffLen bh (SBS.ShortByteString ba) off len + + get bh = do + len <- get bh + SBS.ShortByteString ba <- getSBSLen bh len + pure $ T.Text ba 0 len + instance Binary FastString where put_ bh f = case findUserDataWriter (Proxy :: Proxy FastString) bh of ===================================== compiler/ghc.cabal.in ===================================== @@ -120,6 +120,7 @@ Library process >= 1 && < 1.7, bytestring >= 0.11 && < 0.13, binary == 0.8.*, + text >= 2.0 && < 2.2, time >= 1.4 && < 1.16, containers >= 0.6.2.1 && < 0.9, array >= 0.1 && < 0.6, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0f5a73bc8d186e53713ba31dfc66a29d... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0f5a73bc8d186e53713ba31dfc66a29d... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)