[Git][ghc/ghc][master] 2 commits: base: Use TemplateHaskellQuotes in instance Lift ByteArray

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Jun 5 02:51:23 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b23746ad by Teo Camarasu at 2024-06-04T22:50:50-04:00
base: Use TemplateHaskellQuotes in instance Lift ByteArray

Resolves #24852

- - - - -
3fd25743 by Teo Camarasu at 2024-06-04T22:50:50-04:00
base: Mark addrToByteArray as NOINLINE

This function should never be inlined in order to keep code size small.

- - - - -


1 changed file:

- libraries/base/src/Data/Array/Byte.hs


Changes:

=====================================
libraries/base/src/Data/Array/Byte.hs
=====================================
@@ -201,10 +201,11 @@ instance Show ByteArray where
                 | otherwise = showString ", "
 
 instance Lift ByteArray where
-  liftTyped x = unsafeCodeCoerce (lift x)
-  lift (ByteArray b) = return
-    (AppE (AppE (VarE addrToByteArrayName) (LitE (IntegerL (fromIntegral len))))
-      (LitE (BytesPrimL (Bytes ptr 0 (fromIntegral len)))))
+  liftTyped = unsafeCodeCoerce . lift
+  lift (ByteArray b) =
+    [| addrToByteArray $(lift len)
+                       $(pure . LitE . BytesPrimL $ Bytes ptr 0 (fromIntegral len))
+    |]
     where
       len# = sizeofByteArray# b
       len = I# len#
@@ -219,9 +220,7 @@ instance Lift ByteArray where
       ptr :: ForeignPtr Word8
       ptr = ForeignPtr (byteArrayContents# pb) (PlainPtr (unsafeCoerce# pb))
 
-addrToByteArrayName :: Name
-addrToByteArrayName = 'addrToByteArray
-
+{-# NOINLINE addrToByteArray #-}
 addrToByteArray :: Int -> Addr# -> ByteArray
 addrToByteArray (I# len) addr = runST $ ST $
   \s -> case newByteArray# len s of



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/077cb2e11fa81076e8c9c5f8dd3bdfa99c8aaf8d...3fd25743ea14c9c99efc9e1da66ee35371d1fc93

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/077cb2e11fa81076e8c9c5f8dd3bdfa99c8aaf8d...3fd25743ea14c9c99efc9e1da66ee35371d1fc93
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240604/bbc433b0/attachment-0001.html>


More information about the ghc-commits mailing list