[Git][ghc/ghc][wip/fix-putWithTables] compiler: avoid overwriting existing writers in putWithTables
Cheng Shao (@TerrorJack)
gitlab at gitlab.haskell.org
Tue Feb 25 16:40:27 UTC 2025
Cheng Shao pushed to branch wip/fix-putWithTables at Glasgow Haskell Compiler / GHC
Commits:
918b2c08 by Cheng Shao at 2025-02-25T16:40:05+00:00
compiler: avoid overwriting existing writers in putWithTables
This patch makes `putWithTables` avoid overwriting all existing
UserData writers in the handle. This is crucial for GHC API users that
use putWithUserData/getWithUserData for serialization logic that
involve Names.
- - - - -
1 changed file:
- compiler/GHC/Iface/Binary.hs
Changes:
=====================================
compiler/GHC/Iface/Binary.hs
=====================================
@@ -43,7 +43,6 @@ import GHC.Types.Unique.FM
import GHC.Utils.Panic
import GHC.Utils.Binary as Binary
import GHC.Data.FastMutInt
-import GHC.Data.FastString (FastString)
import GHC.Types.Unique
import GHC.Utils.Outputable
import GHC.Types.Name.Cache
@@ -321,18 +320,21 @@ putWithTables compressionLevel bh' put_payload = do
(ifaceType_wt, ifaceTypeWriter) <- initWriteIfaceType compressionLevel
-- Initialise the 'WriterUserData'.
- let writerUserData = mkWriterUserData
- [ mkSomeBinaryWriter @FastString fsWriter
- , mkSomeBinaryWriter @Name nameWriter
- -- We sometimes serialise binding and non-binding names differently, but
- -- not during 'ModIface' serialisation. Here, we serialise both to the same
- -- deduplication table.
- --
- -- See Note [Binary UserData]
- , mkSomeBinaryWriter @BindingName $ mkWriter (\bh name -> putEntry nameWriter bh (getBindingName name))
- , mkSomeBinaryWriter @IfaceType ifaceTypeWriter
- ]
- let bh = setWriterUserData bh' writerUserData
+ --
+ -- Similar to how 'getTables' calls 'addReaderToUserData', here we
+ -- call 'addWriterToUserData' instead of 'setWriterUserData', to
+ -- avoid overwriting existing writers of other types in bh'.
+ let bh =
+ addWriterToUserData fsWriter
+ $ addWriterToUserData nameWriter
+ -- We sometimes serialise binding and non-binding names differently, but
+ -- not during 'ModIface' serialisation. Here, we serialise both to the same
+ -- deduplication table.
+ --
+ -- See Note [Binary UserData]
+ $ addWriterToUserData
+ (mkWriter $ \bh name -> putEntry nameWriter bh $ getBindingName name)
+ $ addWriterToUserData ifaceTypeWriter bh'
([fs_count, name_count, ifacetype_count] , r) <-
-- The order of these entries matters!
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/918b2c08836d0a9d00d6d186597ecbe9d6671512
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/918b2c08836d0a9d00d6d186597ecbe9d6671512
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/20250225/4918d2b1/attachment-0001.html>
More information about the ghc-commits
mailing list