Skip to content
Snippets Groups Projects
Commit d3780ab0 authored by Cheng Shao's avatar Cheng Shao :beach:
Browse files

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.

(cherry picked from commit c331eebf)
parent a0995a9d
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,6 @@ import GHC.Types.Unique.FM ...@@ -43,7 +43,6 @@ import GHC.Types.Unique.FM
import GHC.Utils.Panic import GHC.Utils.Panic
import GHC.Utils.Binary as Binary import GHC.Utils.Binary as Binary
import GHC.Data.FastMutInt import GHC.Data.FastMutInt
import GHC.Data.FastString (FastString)
import GHC.Types.Unique import GHC.Types.Unique
import GHC.Utils.Outputable import GHC.Utils.Outputable
import GHC.Types.Name.Cache import GHC.Types.Name.Cache
...@@ -321,18 +320,21 @@ putWithTables compressionLevel bh' put_payload = do ...@@ -321,18 +320,21 @@ putWithTables compressionLevel bh' put_payload = do
(ifaceType_wt, ifaceTypeWriter) <- initWriteIfaceType compressionLevel (ifaceType_wt, ifaceTypeWriter) <- initWriteIfaceType compressionLevel
-- Initialise the 'WriterUserData'. -- Initialise the 'WriterUserData'.
let writerUserData = mkWriterUserData --
[ mkSomeBinaryWriter @FastString fsWriter -- Similar to how 'getTables' calls 'addReaderToUserData', here we
, mkSomeBinaryWriter @Name nameWriter -- call 'addWriterToUserData' instead of 'setWriterUserData', to
-- We sometimes serialise binding and non-binding names differently, but -- avoid overwriting existing writers of other types in bh'.
-- not during 'ModIface' serialisation. Here, we serialise both to the same let bh =
-- deduplication table. addWriterToUserData fsWriter
-- $ addWriterToUserData nameWriter
-- See Note [Binary UserData] -- We sometimes serialise binding and non-binding names differently, but
, mkSomeBinaryWriter @BindingName $ mkWriter (\bh name -> putEntry nameWriter bh (getBindingName name)) -- not during 'ModIface' serialisation. Here, we serialise both to the same
, mkSomeBinaryWriter @IfaceType ifaceTypeWriter -- deduplication table.
] --
let bh = setWriterUserData bh' writerUserData -- See Note [Binary UserData]
$ addWriterToUserData
(mkWriter $ \bh name -> putEntry nameWriter bh $ getBindingName name)
$ addWriterToUserData ifaceTypeWriter bh'
([fs_count, name_count, ifacetype_count] , r) <- ([fs_count, name_count, ifacetype_count] , r) <-
-- The order of these entries matters! -- The order of these entries matters!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment